Skip to content
Browse files

The food types are now recognized and displayed differently - steroid…

…s do not work yet
  • Loading branch information...
1 parent 17e0aae commit dba71788c520ec8d11a81152935f77603234881f @HenJi committed Oct 19, 2011
Showing with 38 additions and 14 deletions.
  1. +10 −1 src/default.opa
  2. +17 −2 src/food.opa
  3. +1 −1 src/opacman.opa
  4. +4 −8 src/pacman.opa
  5. +6 −2 src/types.opa
View
11 src/default.opa
@@ -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)
View
19 src/food.opa
@@ -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
View
2 src/opacman.opa
@@ -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])
View
12 src/pacman.opa
@@ -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 =
View
8 src/types.opa
@@ -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.
Something went wrong with that request. Please try again.