Skip to content

Commit

Permalink
Time at end + game over message
Browse files Browse the repository at this point in the history
  • Loading branch information
HenJi committed Nov 6, 2011
1 parent edfa87b commit 597e357
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
21 changes: 20 additions & 1 deletion src/info.opa
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,31 @@

do match g.on_steroids with
| {none} -> void
| {some=d} -> cft("Bonus: {1+d/60}", 10, 190)
| {some=d} -> cft("Bonus: {1+d/fps}s", 10, 190)

p = g.pacman.base.pos
do cft("Player at ({p.x},{p.y})", 10, info_height-10)

do Canvas.restore(ctx)
void

draw_in_center(ctx, text) =
f = 70
w=2+base_size*grid_width
h=2+base_size*grid_heigth
do Canvas.save(ctx)
do Canvas.set_text_align(ctx, {align_center})
do Canvas.set_font(ctx, "bold {f}px Arial")
do Canvas.fill_text(ctx, text, w/2, (h-f)/2)
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)

draw_game_over(ctx) = draw_in_center(ctx, "GAME OVER")

}}
34 changes: 24 additions & 10 deletions src/opacman.opa
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ info_width = 200

food_points = 10
steroid_points = 100
steroid_len = 300 /* frames */
steroid_len = 5*fps /* frames */
clear_bonus = 500
life_points = 2500


/* Defaults */

default_game = {
state = {initiating=2*fps}
pacman = Default.pacman
ghosts = Default.ghosts
food = Default.food
Expand Down Expand Up @@ -65,7 +66,10 @@ check_collision(g) =
d = Math.sqrt_i(x*x+y*y)
d < base_size,
g.ghosts, false)
if has_collision then {g with lives=0}
if has_collision then
{g with
state = {game_over}
lives = 0}
else g

@client clean_frame(ctx:Canvas.context) =
Expand All @@ -75,20 +79,30 @@ check_collision(g) =
2+base_size*grid_heigth)

@client next_frame(ctx:Canvas.context)() =
g = game.get()
if g.lives == 0 then
void
else
g = Pacman.move(g)
|> Ghost.move
|> check_collision
draw_board(g) =
do clean_frame(ctx)
do Wall.draw(ctx)
do Food.draw(g, ctx)
do Pacman.draw(g, ctx)
do Ghost.draw(g, ctx)
do Info.draw(g, ctx)
game.set(g)
void
g = game.get()
do draw_board(g)
g = match g.state with
| {game_over} ->
do Info.draw_game_over(ctx)
g
| {initiating=t} ->
if t < -fps/2 then {g with state={running}}
else
do Info.draw_init(t, ctx)
{g with state={initiating=(t-1)}}
| {running} ->
Pacman.move(g)
|> Ghost.move
|> check_collision
game.set(g)

@client keyfun(e) =
g = game.get()
Expand Down
6 changes: 6 additions & 0 deletions src/types.opa
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ type Food.t =
{normal}
/ {steroids}

type Game.state =
{initiating:int}
/ {running}
/ {game_over}

type Game.status = {
state : Game.state
pacman : Pacman.t
ghosts : list(Ghost.t)
food : map(Base.pos, Food.t)
Expand Down

0 comments on commit 597e357

Please sign in to comment.