Skip to content

Commit

Permalink
server directives removed (full client) + ghost eye movement isolated
Browse files Browse the repository at this point in the history
  • Loading branch information
HenJi committed Oct 19, 2011
1 parent ba649fe commit 4ffbd62
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
41 changes: 18 additions & 23 deletions src/ghost.opa
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
@client Ghost = {{

@server default = [
{ ai = {dumb}
base = Base.make(5, 4, {right}, 10)
color = Color.orange },
{ ai = {guard}
base = Base.make(20, 4, {down}, 10)
color = Color.darkred },
{ ai = {dumb}
base = Base.make(20, 22, {left}, 10)
color = Color.gold },
{ ai = {guard}
base = Base.make(5, 22, {up}, 10)
color = Color.green }
] : list(Ghost.t)
make(ai, x, y, dir, color, eye_color) = {
~ai ~color ~eye_color
base = Base.make(x, y, dir, 10)
eye_step = 0
eye_steps = 32
} : Ghost.t

invert_color(c:color) =
Color.set_r(c, 255-Color.r(c))
|> Color.set_g(_, 255-Color.g(c))
|> Color.set_b(_, 255-Color.b(c))
default = [
make({dumb}, 5, 4, {right}, Color.orange, Color.crimson),
make({guard}, 20, 4, {down}, Color.darkred, Color.gold),
make({dumb}, 20, 22, {left}, Color.purple, Color.silver),
make({guard}, 5, 22, {up}, Color.green, Color.navy),
] : list(Ghost.t)

draw_one(ctx:Canvas.context, g:Ghost.t) =
w = base_size
Expand All @@ -40,12 +34,12 @@
do Canvas.fill(ctx)

do Canvas.clear_rect(ctx, -w/4, -w/4, w/2, w/4)
do Canvas.set_fill_style(ctx, {color=invert_color(g.color)})
do Canvas.set_fill_style(ctx, {color=(g.eye_color)})
dx =
base = g.base.max_steps
base = g.eye_steps
step =
if g.base.cur_step > base/2 then base - g.base.cur_step
else g.base.cur_step
if g.eye_step > base/2 then base - g.eye_step
else g.eye_step
(w*step)/(2*base)
do Canvas.fill_rect(ctx, dx-w/4, -w/4, w/4, w/4)

Expand Down Expand Up @@ -73,6 +67,7 @@
cur_step =
if cur_step >= g.base.max_steps then 0
else cur_step
g = {g with eye_step = mod(g.eye_step+1, g.eye_steps)}
if cur_step != 0 then {g with base = {g.base with ~cur_step}}
else
(dx, dy) = Base.Dir.deltas(g.base.dir)
Expand All @@ -83,7 +78,7 @@
g = {g with base = {g.base with ~pos}}
dirs = move_fun(g.base)
dir = List.get(Random.int(List.length(dirs)), dirs) ? {down}
{g with base = {g.base with ~dir ~cur_step}}
{g with base = {g.base with ~dir ~cur_step} }

@private move_one_dumb(ghost:Ghost.t) =
move_one_generic(ghost, build_move_options(_, true))
Expand Down
2 changes: 1 addition & 1 deletion src/opacman.opa
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ grid_heigth = 29

/* Defaults */

default_game = {
@client default_game = {
pacman = Pacman.default
ghosts = Ghost.default
food = initial_food
Expand Down
12 changes: 6 additions & 6 deletions src/pacman.opa
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@client Pacman = {{

@server default = {
default = {
base = Base.make(0, 0, {right}, 10)
next_dir = {right}
mouth_state = 0
mouth_incr = 1
mouth_step = 0
mouth_incr = 1
mouth_steps = 10
} : Pacman.t

Expand All @@ -13,7 +13,7 @@
p = g.pacman
w = base_size

mouth = p.mouth_state
mouth = p.mouth_step
steps = p.mouth_steps

do Canvas.save(ctx)
Expand Down Expand Up @@ -78,13 +78,13 @@
else (food, g.score+10)
else (g.food, g.score)

mouth = p.mouth_state + p.mouth_incr
mouth = p.mouth_step + p.mouth_incr
dmouth =
if (mouth == p.mouth_steps-1 || mouth == 0) then -p.mouth_incr
else p.mouth_incr
pacman =
{ p with
mouth_state = mouth
mouth_step = mouth
mouth_incr = dmouth
base = { p.base with ~pos ~dir ~cur_step } }
game.set({g with ~pacman ~food ~score})
Expand Down
11 changes: 7 additions & 4 deletions src/types.opa
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Base.t = {
type Pacman.t = {
base : Base.t
next_dir : Base.direction
mouth_state : int
mouth_step : int
mouth_incr : int
mouth_steps : int
}
Expand All @@ -25,9 +25,12 @@ type Ghost.ai =
/ {guard}

type Ghost.t = {
ai : Ghost.ai
base : Base.t
color : color
ai : Ghost.ai
base : Base.t
color : color
eye_color : color
eye_step : int
eye_steps : int
}

type Game.status = {
Expand Down

0 comments on commit 4ffbd62

Please sign in to comment.