diff --git a/src/ghost.opa b/src/ghost.opa index c737db3..762a58f 100644 --- a/src/ghost.opa +++ b/src/ghost.opa @@ -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 @@ -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) @@ -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) @@ -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)) diff --git a/src/opacman.opa b/src/opacman.opa index 93527af..c6a6b89 100644 --- a/src/opacman.opa +++ b/src/opacman.opa @@ -7,7 +7,7 @@ grid_heigth = 29 /* Defaults */ -default_game = { +@client default_game = { pacman = Pacman.default ghosts = Ghost.default food = initial_food diff --git a/src/pacman.opa b/src/pacman.opa index f8ce173..f1a9f92 100644 --- a/src/pacman.opa +++ b/src/pacman.opa @@ -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 @@ -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) @@ -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}) diff --git a/src/types.opa b/src/types.opa index 153d4d8..29b59ba 100644 --- a/src/types.opa +++ b/src/types.opa @@ -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 } @@ -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 = {