Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Time at end + game over message

  • Loading branch information...
commit 597e3577179464c21b3907961c03e181a4601861 1 parent edfa87b
@HenJi authored
Showing with 50 additions and 11 deletions.
  1. +20 −1 src/info.opa
  2. +24 −10 src/opacman.opa
  3. +6 −0 src/types.opa
View
21 src/info.opa
@@ -26,7 +26,7 @@
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)
@@ -34,4 +34,23 @@
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")
+
}}
View
34 src/opacman.opa
@@ -10,7 +10,7 @@ info_width = 200
food_points = 10
steroid_points = 100
-steroid_len = 300 /* frames */
+steroid_len = 5*fps /* frames */
clear_bonus = 500
life_points = 2500
@@ -18,6 +18,7 @@ life_points = 2500
/* Defaults */
default_game = {
+ state = {initiating=2*fps}
pacman = Default.pacman
ghosts = Default.ghosts
food = Default.food
@@ -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) =
@@ -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()
View
6 src/types.opa
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.