diff --git a/src/food.opa b/src/food.opa index ec758bb..c5e36af 100644 --- a/src/food.opa +++ b/src/food.opa @@ -1,14 +1,15 @@ @client Food = {{ - check(pos, food) = + check(pos, food, cur_steroids) = match Map.extract(pos, food) with - | (food, {none}) -> (food, 0) + | (food, {none}) -> (food, 0, cur_steroids) | (food, {some=f}) -> - score = match f with - | {normal} -> 10 - | {steroids} -> 100 - if food == Map.empty then (Default.food, score+1000) - else (food, score) + (food, d) = + if food == Map.empty then (Default.food, 1000) + else (food, 0) + match f with + | {normal} -> (food, 10+d, cur_steroids) + | {steroids} -> (food, 100+d, some(300)) draw(g, ctx:Canvas.context) = food = g.food diff --git a/src/ghost.opa b/src/ghost.opa index 03feb26..8329fc8 100644 --- a/src/ghost.opa +++ b/src/ghost.opa @@ -1,5 +1,8 @@ @client Ghost = {{ + @private scared_color = Color.lightsteelblue + @private scared_eye_color = Color.lightslategray + draw_one(ctx:Canvas.context, g:Ghost.t) = w = base_size @@ -118,6 +121,12 @@ {g with ~ghosts} draw(g, ctx:Canvas.context) = - List.iter(draw_one(ctx, _), g.ghosts) + ghosts = match g.on_steroids with + | {none} -> g.ghosts + | {some=_} -> + List.map( + g -> {g with color=scared_color eye_color=scared_eye_color}, + g.ghosts) + List.iter(draw_one(ctx, _), ghosts) }} diff --git a/src/opacman.opa b/src/opacman.opa index abbe79f..404726b 100644 --- a/src/opacman.opa +++ b/src/opacman.opa @@ -8,10 +8,11 @@ grid_heigth = List.length(grid) /* Defaults */ default_game = { - pacman = Default.pacman - ghosts = Default.ghosts - food = Default.food - score = 0 + pacman = Default.pacman + ghosts = Default.ghosts + food = Default.food + score = 0 + on_steroids = none } : Game.status /* Game */ @@ -54,6 +55,7 @@ default_game = { Pacman at ({p.base.pos.x},{p.base.pos.y}), moving {"{p.base.dir}"} - {Map.size(g.food)} food left - Score: {g.score} + - Steroids: {g.on_steroids} Dom.transform([#info <- cont]) diff --git a/src/pacman.opa b/src/pacman.opa index 30d4ce6..4412f16 100644 --- a/src/pacman.opa +++ b/src/pacman.opa @@ -80,11 +80,15 @@ y = mod(grid_heigth + p.base.pos.y + dy, grid_heigth) } - (food, dscore) = - if cur_step != p.base.max_steps/2 then (g.food, 0) - else Food.check(pos, g.food) + (food, dscore, steroids) = + if cur_step != p.base.max_steps/2 then (g.food, 0, g.on_steroids) + else Food.check(pos, g.food, g.on_steroids) score = g.score + dscore - + on_steroids = match steroids with + | {none} -> none + | {some=t} -> + if t < 1 then none + else some(t-1) mouth = p.mouth_step + p.mouth_incr dmouth = if (mouth == p.mouth_steps-1 || mouth == 0) then -p.mouth_incr @@ -94,6 +98,6 @@ mouth_step = mouth mouth_incr = dmouth base = { p.base with ~pos ~dir ~cur_step } } - {g with ~pacman ~food ~score} + {g with ~pacman ~food ~score ~on_steroids} }} diff --git a/src/types.opa b/src/types.opa index 11b5ed4..d3b0425 100644 --- a/src/types.opa +++ b/src/types.opa @@ -52,4 +52,5 @@ type Game.status = { ghosts : list(Ghost.t) food : map(Base.pos, Food.t) score : int + on_steroids : option(int) /* Number of cycles on steroids */ }