diff --git a/src/default.opa b/src/default.opa index 381ba52..9dfb6a0 100644 --- a/src/default.opa +++ b/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) diff --git a/src/food.opa b/src/food.opa index b7578bc..ec758bb 100644 --- a/src/food.opa +++ b/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 diff --git a/src/opacman.opa b/src/opacman.opa index 6af3177..abbe79f 100644 --- a/src/opacman.opa +++ b/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]) diff --git a/src/pacman.opa b/src/pacman.opa index 155b4c0..30d4ce6 100644 --- a/src/pacman.opa +++ b/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 = diff --git a/src/types.opa b/src/types.opa index 6c399af..11b5ed4 100644 --- a/src/types.opa +++ b/src/types.opa @@ -35,7 +35,7 @@ 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 @@ -43,9 +43,13 @@ type Ghost.t = { 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 }