Permalink
Browse files

Border effects moved in main function

  • Loading branch information...
1 parent e15b5de commit 31c4b5e7acb66e5dde9adde26fac0400f2ecfd1c @HenJi committed Oct 19, 2011
Showing with 15 additions and 18 deletions.
  1. +2 −2 src/food.opa
  2. +3 −5 src/ghost.opa
  3. +7 −6 src/opacman.opa
  4. +3 −5 src/pacman.opa
View
@@ -1,7 +1,7 @@
@client Food = {{
- draw(ctx:Canvas.context) =
- food = game.get().food
+ draw(g, ctx:Canvas.context) =
+ food = g.food
w = base_size
do Canvas.save(ctx)
do Canvas.set_fill_style(ctx, {color=Color.red})
View
@@ -92,17 +92,15 @@
else bias
move_one_generic(ghost, move_fun)
- move() =
- g = game.get()
+ move(g) =
ghosts = List.map(
ghost -> match ghost.ai with
| {dumb} -> move_one_dumb(ghost)
| {guard} -> move_one_guard(ghost, g.pacman.base),
g.ghosts)
- game.set({g with ~ghosts})
+ {g with ~ghosts}
- draw(ctx:Canvas.context) =
- g = game.get()
+ draw(g, ctx:Canvas.context) =
List.iter(draw_one(ctx, _), g.ghosts)
}}
View
@@ -58,14 +58,15 @@ default_game = {
Dom.transform([#info <- cont])
@client next_frame(ctx:Canvas.context)() =
+ g = game.get()
+ |> Pacman.move
+ |> Ghost.move
do clean_frame(ctx)
- do Pacman.move()
- do Ghost.move()
do Wall.draw(ctx)
- do Food.draw(ctx)
- do Pacman.draw(ctx)
- do Ghost.draw(ctx)
- void
+ do Food.draw(g, ctx)
+ do Pacman.draw(g, ctx)
+ do Ghost.draw(g, ctx)
+ game.set(g)
@client keyfun(e) =
g = game.get()
View
@@ -1,7 +1,6 @@
@client Pacman = {{
- draw(ctx:Canvas.context) =
- g = game.get()
+ draw(g, ctx:Canvas.context) =
p = g.pacman
w = base_size
@@ -32,8 +31,7 @@
do Canvas.restore(ctx)
void
- move() =
- g = game.get()
+ move(g) =
p = g.pacman
ignore_incr = p.base.cur_step < 0
cur_step = p.base.cur_step + 1
@@ -79,6 +77,6 @@
mouth_step = mouth
mouth_incr = dmouth
base = { p.base with ~pos ~dir ~cur_step } }
- game.set({g with ~pacman ~food ~score})
+ {g with ~pacman ~food ~score}
}}

0 comments on commit 31c4b5e

Please sign in to comment.