Permalink
Browse files

Steroids now make ghosts change color but still no collision

  • Loading branch information...
1 parent dba7178 commit a84320b52d3e583afe5850760c5387bc46416ae7 @HenJi committed Oct 19, 2011
Showing with 34 additions and 17 deletions.
  1. +8 −7 src/food.opa
  2. +10 −1 src/ghost.opa
  3. +6 −4 src/opacman.opa
  4. +9 −5 src/pacman.opa
  5. +1 −0 src/types.opa
View
@@ -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
View
@@ -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)
}}
View
@@ -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])
View
@@ -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}
}}
View
@@ -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 */
}

0 comments on commit a84320b

Please sign in to comment.