Skip to content

Commit

Permalink
Start and resume conditions changed
Browse files Browse the repository at this point in the history
  • Loading branch information
HenJi committed Nov 6, 2011
1 parent 8a2a2a0 commit 2c74fb8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
9 changes: 3 additions & 6 deletions src/info.opa
Original file line number Diff line number Diff line change
Expand Up @@ -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"))


}}
26 changes: 18 additions & 8 deletions src/opacman.opa
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/types.opa
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Food.t =
/ {steroids}

type Game.state =
{initiating:int}
{game_start}
/ {running}
/ {pause}
/ {game_over}
Expand Down

0 comments on commit 2c74fb8

Please sign in to comment.