summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-02-26 13:52:29 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-02-26 13:52:29 +0100 |
commit | fd4d031ab5b31763d376c663cc049f62ee389243 (patch) | |
tree | cd09a29bb888acf772fa1aee59fe95e8bd75fe4e /src/struct/character_instance.erl | |
parent | 66ec11ce5d2e227846d6e6b2899cda851a70fc04 (diff) |
Got it to run, at last.
Diffstat (limited to 'src/struct/character_instance.erl')
-rw-r--r-- | src/struct/character_instance.erl | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/src/struct/character_instance.erl b/src/struct/character_instance.erl index c530424..e736a4c 100644 --- a/src/struct/character_instance.erl +++ b/src/struct/character_instance.erl @@ -20,7 +20,8 @@ -export ( [ - new/2 + new/2, + random/4 ] ). @@ -43,6 +44,23 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +find_random_location (BattlemapWidth, BattlemapHeight, ForbiddenLocations) -> + X = roll:between(0, (BattlemapWidth - 1)), + Y = roll:between(0, (BattlemapHeight - 1)), + + IsForbidden = lists:member({X, Y}, ForbiddenLocations), + + case IsForbidden of + true -> + find_random_location + ( + BattlemapWidth, + BattlemapHeight, + ForbiddenLocations + ); + + _ -> {X, Y} + end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -83,12 +101,19 @@ set_is_active (Active, CharInst) -> }. %%%% Utils -new (Char, Location) -> - Stats = character:get_statistics(Char), +new (Character, Location) -> + CharacterStatistics = character:get_statistics(Character), #character_instance { - character = Char, + character = Character, location = Location, - current_health = statistics:get_health(Stats), + current_health = statistics:get_health(CharacterStatistics), active = false }. + +random (Character, BattlemapWidth, BattlemapHeight, ForbiddenLocations) -> + new + ( + Character, + find_random_location(BattlemapWidth, BattlemapHeight, ForbiddenLocations) + ). |