Skip to content

Commit

Permalink
Steroids now make ghosts change color but still no collision
Browse files Browse the repository at this point in the history
  • Loading branch information
HenJi committed Oct 19, 2011
1 parent dba7178 commit a84320b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
15 changes: 8 additions & 7 deletions src/food.opa
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/ghost.opa
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)

}}
10 changes: 6 additions & 4 deletions src/opacman.opa
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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])

Expand Down
14 changes: 9 additions & 5 deletions src/pacman.opa
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}

}}
1 change: 1 addition & 0 deletions src/types.opa
Original file line number Diff line number Diff line change
Expand Up @@ -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.