Permalink
Browse files

Blinking effect added on some texts + r to restart on game over

  • Loading branch information...
1 parent 31374de commit 185cdca51953e197931073fa67faf89007f43b36 @HenJi committed Nov 6, 2011
Showing with 35 additions and 15 deletions.
  1. +17 −8 src/info.opa
  2. +18 −7 src/opacman.opa
View
@@ -14,22 +14,30 @@
do Canvas.set_text_align(ctx, {align_center})
do Canvas.set_font(ctx, "bold 40px Arial")
- cft(t,x,y) = Canvas.fill_text(ctx, t, x, y)
- do cft("OPAcman", info_width/2, 50)
+ do Canvas.fill_text(ctx, "OPAcman", info_width/2, 50)
do Canvas.set_text_align(ctx, {align_start})
do Canvas.set_font(ctx, "bold 20px Arial")
+ do Canvas.translate(ctx, 10, 70)
- do cft("Lives: {g.lives}", 10, 100)
- do cft("Score: {g.score}", 10, 130)
- do cft("Food left: {Map.size(g.food)}", 10, 160)
+ cft(t,dy) =
+ do Canvas.translate(ctx, 0, dy)
+ Canvas.fill_text(ctx, t, 0, 0)
+
+ do cft("Lives: {g.lives}", 30)
+ do cft("Score: {g.score}", 30)
+ do cft("Food left: {Map.size(g.food)}", 30)
+
+ do if g.state == {game_over} then
+ cft("'r': restart", 30)
do match g.on_steroids with
| {none} -> void
- | {some=d} -> cft("Bonus: {1+d/fps}s", 10, 190)
+ | {some=d} -> cft("Bonus: {1+d/fps}s", 30)
p = g.pacman.base.pos
- do cft("Player at ({p.x},{p.y})", 10, info_height-10)
+ do Canvas.fill_text(ctx,
+ "Player at ({p.x},{p.y})", 10, info_height-10)
do Canvas.restore(ctx)
void
@@ -51,6 +59,7 @@
else "Starts in {1+t/fps}s"
draw_in_center(ctx, text)
- draw_game_over(ctx) = draw_in_center(ctx, "GAME OVER")
+ draw_game_over(ctx) =
+ draw_in_center(ctx, "GAME OVER")
}}
View
@@ -78,6 +78,12 @@ check_collision(g) =
2+base_size*grid_width,
2+base_size*grid_heigth)
+@client blink(f) =
+ t = Date.now() |> Date.in_milliseconds
+ t = t / 100
+ t = t - (t/10)*10
+ if t > 5 then f()
+
@client next_frame(ctx:Canvas.context)() =
draw_board(g) =
do clean_frame(ctx)
@@ -91,12 +97,12 @@ check_collision(g) =
do draw_board(g)
g = match g.state with
| {game_over} ->
- do Info.draw_game_over(ctx)
+ do blink(->Info.draw_game_over(ctx))
g
| {initiating=t} ->
if t < -fps/2 then {g with state={running}}
else
- do Info.draw_init(t, ctx)
+ do blink(->Info.draw_init(t, ctx))
{g with state={initiating=(t-1)}}
| {running} ->
Pacman.move(g)
@@ -107,16 +113,17 @@ check_collision(g) =
@client keyfun(e) =
g = game.get()
p = g.pacman
+ do Dom.transform([#debug <- "{e.key_code}"])
p = match (p.base.dir, e.key_code) with
- // z
- | ({down}, {some=122}) ->
+ // z + w
+ | ({down}, {some=122}) | ({down}, {some=119}) ->
{p with next_dir={up}
base={p.base with dir={up}
cur_step=-p.base.cur_step}}
| (_, {some=122}) -> {p with next_dir={up}}
- // q
- | ({right}, {some=113}) ->
+ // q + a
+ | ({right}, {some=113}) | ({right}, {some=97}) ->
{p with next_dir={left}
base={p.base with dir={left}
cur_step=-p.base.cur_step}}
@@ -139,7 +146,11 @@ check_collision(g) =
// space (pause)
| (_, {some=32}) -> {p with next_dir=Base.Dir.get_still(p.base.dir)}
| _ -> p
- game.set({g with pacman=p})
+ g = match (g.state, e.key_code) with
+ // r (reset if game over)
+ | ({game_over}, {some=114}) -> default_game
+ | _ -> {g with pacman=p}
+ game.set(g)
@client init() =
match Canvas.get(#game_holder) with

0 comments on commit 185cdca

Please sign in to comment.