Skip to content

Commit

Permalink
remove unused level data files from initial work on rul
Browse files Browse the repository at this point in the history
  • Loading branch information
sofuture committed Jan 5, 2011
1 parent 397e599 commit 1d0a618
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
13 changes: 0 additions & 13 deletions priv/level.dat

This file was deleted.

13 changes: 0 additions & 13 deletions priv/level2.dat

This file was deleted.

12 changes: 11 additions & 1 deletion src/ru_brains.erl
Expand Up @@ -22,7 +22,17 @@
%% ============================================================================

dog_brain(Event, Me) ->
case Event of
case Event of
attack ->
{MyLoc, _} = ru_world:mob_location(Me#mob.ref),
HeroLoc = ru_world:hero_location(),
{CX,CY} = MyLoc#world.loc,
Dir = random_direction(),
case ru_state:move(Me#mob.ref, Dir) of
error ->
ru_state:move(Me#mob.ref, random_direction());
ok -> ok
end;
tick ->
{MyLoc, _} = ru_world:mob_location(Me#mob.ref),
HeroLoc = ru_world:hero_location(),
Expand Down
22 changes: 21 additions & 1 deletion src/ru_mobs.erl
Expand Up @@ -21,7 +21,7 @@
code_change/3]).

-export([start_link/0]).
-export([tick/0, add/1, update/1]).
-export([tick/0, add/1, update/1, attack/1]).

%% ============================================================================
%% Module API
Expand All @@ -39,6 +39,9 @@ add(Mob) when is_record(Mob, mob) ->
update(#mob{} = Mob) ->
?CALL({update, Mob}).

attack(#mob{} = Mob) ->
?CAST({attack, Mob}).

%% ============================================================================
%% gen_server Behaviour
%% ============================================================================
Expand All @@ -53,6 +56,9 @@ handle_call({add, Mob}, _From, State) ->
handle_call({update, Mob}, _From, State) ->
{reply, ok, update_mob(Mob, State)}.

handle_cast({attack, Mob}, State) ->
attack_mob(Mob, State),
{noreply, State};
handle_cast(_Msg, State) ->
{noreply, State}.

Expand Down Expand Up @@ -84,3 +90,17 @@ update_mob(Mob, State) ->
OtherFilter = fun(Elem) -> Elem#mob.ref =/= MobRef end,
Others = lists:filter(OtherFilter, State),
[Mob | Others].

attack_mob(Mob, []) ->
ok;
attack_mob(Mob, [Head | Tail]) ->
Ref = Mob#mob.ref,
case Head#mob.ref of
Ref ->
case Head#mob.func of
nil -> ok;
F -> F(attack, Head)
end;
_ ->
attack_mob(Mob, Tail)
end.
1 change: 1 addition & 0 deletions src/ru_state.erl
Expand Up @@ -205,6 +205,7 @@ do_rest_of_attack(Who, Current, Direction) ->
[Mob] ->
Next = Mob#mob { attackedby = Who },
ru_mobs:update(Next),
ru_mobs:attack(Next),
?MSG("MOB THERE"),
ok;
[] ->
Expand Down

0 comments on commit 1d0a618

Please sign in to comment.