Skip to content

Commit

Permalink
Ghosts now start in a prison and are only released after a configurab…
Browse files Browse the repository at this point in the history
…le duration
  • Loading branch information
HenJi committed Oct 19, 2011
1 parent 53b2ac3 commit 17e0aae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
30 changes: 18 additions & 12 deletions src/default.opa
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
*
* 1: Normal food
* 2: Special food (TODO)
* 5: Teleport - Moving the player at one end of the line will teleport it at
* the other end - Ghosts can't teleport. (TODO)
* 3: Ghost prison - There must be at least one
- Best if walled or in a corner
* 4: Ghost start point - There must be at least one
* 5: Teleport - Moving the player at one end of the line will
* teleport it at the other end - Ghosts can't teleport.
* 8: Wall
*/

Expand All @@ -21,10 +24,10 @@ grid = [
[8,8,8,8,8,1,8,8,8,8,8,0,8,8,0,8,8,8,8,8,1,8,8,8,8,8],
[8,8,8,8,8,1,8,8,8,8,8,0,8,8,0,8,8,8,8,8,1,8,8,8,8,8],
[8,8,8,8,8,1,8,8,0,0,0,0,0,0,0,0,0,0,8,8,1,8,8,8,8,8],
[8,8,8,8,8,1,8,8,0,8,8,8,0,0,8,8,8,0,8,8,1,8,8,8,8,8],
[8,8,8,8,8,1,8,8,0,8,8,8,4,4,8,8,8,0,8,8,1,8,8,8,8,8],
[8,8,8,8,8,1,8,8,0,8,0,0,8,8,0,0,8,0,8,8,1,8,8,8,8,8],
[5,0,0,0,0,1,0,0,0,8,0,0,0,0,0,0,8,0,0,0,1,0,0,0,0,5],
[8,8,8,8,8,1,8,8,0,8,0,0,0,0,0,0,8,0,8,8,1,8,8,8,8,8],
[5,0,0,0,0,1,0,0,0,8,3,3,0,0,3,3,8,0,0,0,1,0,0,0,0,5],
[8,8,8,8,8,1,8,8,0,8,3,3,3,3,3,3,8,0,8,8,1,8,8,8,8,8],
[8,8,8,8,8,1,8,8,0,8,8,8,8,8,8,8,8,0,8,8,1,8,8,8,8,8],
[8,8,8,8,8,1,8,8,0,0,0,0,0,0,0,0,0,0,8,8,1,8,8,8,8,8],
[8,8,8,8,8,1,8,8,0,8,8,8,8,8,8,8,8,0,8,8,1,8,8,8,8,8],
Expand Down Expand Up @@ -54,8 +57,9 @@ Default = {{
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)

teleports =
elts =
Expand All @@ -81,18 +85,20 @@ Default = {{
mouth_steps = 10
} : Pacman.t

@private make_ghost(ai, x, y, dir, color, eye_color) = {
~ai ~color ~eye_color
@private make_ghost(ai, prison, dir, color, eye_color) =
~{x y} = Set.random_get(ghost_prison) |> Option.get
{ ~ai ~color ~eye_color
base = Base.make(x, y, dir, 10)
prison = some(prison)
eye_step = 0
eye_steps = 32
} : Ghost.t

ghosts = [
make_ghost({dumb}, 5, 4, {right}, Color.orange, Color.crimson),
make_ghost({guard}, 20, 4, {down}, Color.darkred, Color.gold),
make_ghost({dumb}, 20, 22, {left}, Color.purple, Color.silver),
make_ghost({guard}, 5, 22, {up}, Color.green, Color.navy),
make_ghost({dumb}, 60, {up}, Color.orange, Color.crimson),
make_ghost({guard}, 200, {up}, Color.darkred, Color.gold),
make_ghost({dumb}, 400, {up}, Color.purple, Color.silver),
make_ghost({guard}, 600, {up}, Color.green, Color.navy),
] : list(Ghost.t)

}}
23 changes: 20 additions & 3 deletions src/ghost.opa
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,28 @@
else bias
move_one_generic(ghost, move_fun)

@private move_prison(ghost:Ghost.t) =
match ghost.prison with
| {none} -> ghost
| {some=t} ->
if t < 1 then
~{x y} = Set.random_get(Default.ghost_start) |> Option.get
{ghost with
base = {
pos = ~{x y}
dir = {up}
cur_step = 0
max_steps = ghost.base.max_steps }
prison = none}
else {ghost with prison = some(t-1)}

move(g) =
ghosts = List.map(
ghost -> match ghost.ai with
| {dumb} -> move_one_dumb(ghost)
| {guard} -> move_one_guard(ghost, g.pacman.base),
ghost ->
(match ghost.ai with
| {dumb} -> move_one_dumb(ghost)
| {guard} -> move_one_guard(ghost, g.pacman.base)
) |> move_prison,
g.ghosts)
{g with ~ghosts}

Expand Down
3 changes: 3 additions & 0 deletions src/types.opa
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type Ghost.ai =
type Ghost.t = {
ai : Ghost.ai
base : Base.t
/* Number of cycles in prison
NOTE: default config is 60 cycles per second */
prison : option(int)
color : color
eye_color : color
eye_step : int
Expand Down

0 comments on commit 17e0aae

Please sign in to comment.