Skip to content

Commit

Permalink
The food types are now recognized and displayed differently - steroid…
Browse files Browse the repository at this point in the history
…s do not work yet
  • Loading branch information
HenJi committed Oct 19, 2011
1 parent 17e0aae commit dba7178
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
11 changes: 10 additions & 1 deletion src/default.opa
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ Default = {{
l, acc),
grid, Set.empty:set(Base.pos))

food = get_grid_nums(1)
walls = get_grid_nums(8)
ghost_prison = get_grid_nums(3)
ghost_start = get_grid_nums(4)

food =
normal = get_grid_nums(1)
steroids = get_grid_nums(2)
aux(set, t, acc) =
Set.fold(
p, acc -> Map.add(p, t, acc),
set, acc)
aux(normal, {normal}, Map.empty:map(Base.pos, Food.t))
|> aux(steroids, {steroids}, _)

teleports =
elts =
get_grid_nums(5)
Expand Down
19 changes: 17 additions & 2 deletions src/food.opa
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
@client Food = {{

check(pos, food) =
match Map.extract(pos, food) with
| (food, {none}) -> (food, 0)
| (food, {some=f}) ->
score = match f with
| {normal} -> 10
| {steroids} -> 100
if food == Map.empty then (Default.food, score+1000)
else (food, score)

draw(g, ctx:Canvas.context) =
food = g.food
w = base_size
do Canvas.save(ctx)
do Canvas.set_fill_style(ctx, {color=Color.red})
do Set.iter(
~{x y} -> Canvas.fill_rect(ctx, w/2+x*w-2, w/2+y*w-2, 6, 6),
do Map.iter(
~{x y}, t ->
match t with
| {normal} ->
Canvas.fill_rect(ctx, w/2+x*w-2, w/2+y*w-2, 6, 6)
| {steroids} ->
Canvas.fill_rect(ctx, w/2+x*w-5, w/2+y*w-5, 11, 11),
food)
do Canvas.restore(ctx)
void
Expand Down
2 changes: 1 addition & 1 deletion src/opacman.opa
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ default_game = {
cont =
<>
Pacman at ({p.base.pos.x},{p.base.pos.y}), moving {"{p.base.dir}"}
- {Set.size(g.food)} food left
- {Map.size(g.food)} food left
- Score: {g.score}
</>
Dom.transform([#info <- cont])
Expand Down
12 changes: 4 additions & 8 deletions src/pacman.opa
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,10 @@
y = mod(grid_heigth + p.base.pos.y + dy, grid_heigth)
}

(food, score) =
if cur_step != p.base.max_steps/2 then (g.food, g.score)
else
if Set.mem(pos, g.food) then
food = Set.remove(pos, g.food)
if food == Set.empty then (Default.food, g.score+1010)
else (food, g.score+10)
else (g.food, g.score)
(food, dscore) =
if cur_step != p.base.max_steps/2 then (g.food, 0)
else Food.check(pos, g.food)
score = g.score + dscore

mouth = p.mouth_step + p.mouth_incr
dmouth =
Expand Down
8 changes: 6 additions & 2 deletions src/types.opa
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ type Ghost.t = {
ai : Ghost.ai
base : Base.t
/* Number of cycles in prison
NOTE: default config is 60 cycles per second */
NOTE: moving takes 10 cycles */
prison : option(int)
color : color
eye_color : color
eye_step : int
eye_steps : int
}

type Food.t =
{normal}
/ {steroids}

type Game.status = {
pacman : Pacman.t
ghosts : list(Ghost.t)
food : set(Base.pos)
food : map(Base.pos, Food.t)
score : int
}

0 comments on commit dba7178

Please sign in to comment.