Browse files

Start and resume conditions changed

  • Loading branch information...
1 parent 8a2a2a0 commit 2c74fb850f1e2bcf8f7a0d514241ec8b7aec553f @HenJi committed Nov 6, 2011
Showing with 22 additions and 15 deletions.
  1. +3 −6 src/info.opa
  2. +18 −8 src/opacman.opa
  3. +1 −1 src/types.opa
View
9 src/info.opa
@@ -73,17 +73,14 @@
do Canvas.restore(ctx)
void
- draw_init(t, ctx) =
- text =
- if t < 0 then "Go!"
- else "Starts in {1+t/fps}s"
- draw_in_center(ctx, text, none)
+ draw_init(ctx) =
+ draw_in_center(ctx, "OPAcman", some("Move in any direction to start"))
draw_game_over(ctx) =
draw_in_center(ctx, "GAME OVER", some("'r' to restart"))
draw_pause(ctx) =
- draw_in_center(ctx, "PAUSE", some("'space' to resume"))
+ draw_in_center(ctx, "PAUSE", some("'space' or any direction to resume"))
}}
View
26 src/opacman.opa
@@ -18,7 +18,7 @@ life_points = 2500
/* Defaults */
default_game = {
- state = {initiating=2*fps}
+ state = {game_start}
pacman = Default.pacman
ghosts = Default.ghosts
food = Default.food
@@ -107,11 +107,9 @@ check_collision(g) =
| {pause} ->
do blink(->Info.draw_pause(ctx))
g
- | {initiating=t} ->
- if t < -fps/2 then {g with state={running}}
- else
- do blink(->Info.draw_init(t, ctx))
- {g with state={initiating=(t-1)}}
+ | {game_start} ->
+ do blink(->Info.draw_init(ctx))
+ {g with state={game_start}}
| {running} ->
Pacman.move(g)
|> Ghost.move
@@ -152,13 +150,25 @@ check_collision(g) =
| (_, {some=100}) -> {p with next_dir={right}}
| _ -> p
+ directions = [122, 119, 113, 97, 115, 100]
g = match (g.state, e.key_code) with
// r (reset if game over)
| ({game_over}, {some=114}) -> default_game
- // space (pause toggle)
+ // space (pause start)
| ({running}, {some=32}) -> {g with state={pause}}
- | ({pause}, {some=32}) -> {g with state={running}}
+
+ // any direction or space to resume
+ | ({pause}, {some=k}) ->
+ if k == 32 || List.mem(k, directions) then
+ {g with state={running} pacman=p}
+ else g
+
+ // any direction to start game
+ | ({game_start}, {some=k}) ->
+ if List.mem(k, directions) then
+ {g with state={running} pacman=p}
+ else g
| _ -> {g with pacman=p}
game.set(g)
View
2 src/types.opa
@@ -48,7 +48,7 @@ type Food.t =
/ {steroids}
type Game.state =
- {initiating:int}
+ {game_start}
/ {running}
/ {pause}
/ {game_over}

0 comments on commit 2c74fb8

Please sign in to comment.