Skip to content

Commit

Permalink
Add {wait, VarName} and new parts of the scene
Browse files Browse the repository at this point in the history
The diva can come in soon!
  • Loading branch information
Loïc Hoguin committed Jul 10, 2011
1 parent 886671e commit d2d1b0d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
26 changes: 22 additions & 4 deletions priv/spawnfest/scene.hrl
Expand Up @@ -16,10 +16,27 @@
{scene, [
{wait, 10},
{spawn, basic, {480, 270}, [
{var, x, 0},
{var, w, 50},
{var, x, 0.0},

%% Pattern 1 part 1 - fixed.
{repeat, 40, [
{repeat, 18, [
{fire, basic, [
{speed, 2.0},
{dir, x}
]},
{var, x, add, 30}
]},
{wait, w},
{var, w, add, -1}
]},

{var, y, 31.5},
{var, z, -3},
{repeat, 5, [
{var, z, -3.0},

%% Pattern 1 part 2 - variable.
{repeat, 3, [
{repeat, 21, [
{repeat, 18, [
{fire, basic, [
Expand All @@ -32,6 +49,7 @@
{var, y, add, z}
]},
{var, z, mul, -1}
]}
]},
vanish
]}
]}.
11 changes: 9 additions & 2 deletions src/imaku_game.erl
Expand Up @@ -13,7 +13,7 @@
-record(bullet, {
class = generator,
color = {0.0, 0.0, 0.0, 0.0},
pos = {-10000.0, -10000.0},
pos = {1919.0, 1079.0},
dims = {1.0, 1.0},
dir = 0.0,
speed = 0.0,
Expand Down Expand Up @@ -68,7 +68,10 @@ update_scene(Bullets, [Object = #bullet{
NewObjects = update_object(Bullets, Object2),
update_scene(Bullets, Tail, [NewObjects|Acc]).

update_object(_Bullets, Object = #bullet{wait=Wait}) when Wait =/= 0 ->
update_object(_Bullets, #bullet{pos={X, Y}})
when X < -960; X > 1920; Y < -540; Y > 1080 ->
[];
update_object(_Bullets, Object = #bullet{wait=Wait}) when Wait > 0 ->
[Object#bullet{wait=Wait - 1}];
update_object(Bullets, Object = #bullet{actions=Actions}) ->
update_object_actions(Bullets, Object, Actions, []).
Expand Down Expand Up @@ -133,6 +136,10 @@ update_object_actions(Bullets, Object = #bullet{vars=Vars},
Vars3 = [{Name, CurrentValue * MulValue}|Vars2],
update_object_actions(Bullets, Object#bullet{vars=Vars3}, Tail, Acc);
%% Wait.
update_object_actions(_Bullets, Object = #bullet{vars=Vars},
[{wait, Name}|Tail], Acc) when is_atom(Name) ->
{Name, Wait} = lists:keyfind(Name, 1, Vars),
[Object#bullet{actions=Tail, wait=Wait}|Acc];
update_object_actions(_Bullets, Object, [{wait, Wait}|Tail], Acc) ->
[Object#bullet{actions=Tail, wait=Wait}|Acc].

Expand Down

0 comments on commit d2d1b0d

Please sign in to comment.