Skip to content
Browse files

Pacman can now stop facing each direction

  • Loading branch information...
1 parent f60e45f commit e15b5de4a402e2ee84a044482f72cb1aec2a9d7c @HenJi committed
Showing with 27 additions and 11 deletions.
  1. +19 −6 src/base.opa
  2. +1 −1 src/opacman.opa
  3. +3 −3 src/pacman.opa
  4. +4 −1 src/types.opa
View
25 src/base.opa
@@ -4,11 +4,10 @@
facing_angle(dir:Base.direction) =
match dir with
- | {up} -> -Math.PI/2.
- | {down} -> Math.PI/2.
- | {left} -> Math.PI
- | {right} -> 0.
- | {still} -> 0.
+ | {up} | {still_up} -> -Math.PI/2.
+ | {down} | {still_down} -> Math.PI/2.
+ | {left} | {still_left} -> Math.PI
+ | {right} | {still_right} -> 0.
deltas(dir:Base.direction) =
match dir with
@@ -16,7 +15,7 @@
| {down} -> (0, 1)
| {left} -> (-1, 0)
| {right} -> (1, 0)
- | {still} -> (0, 0)
+ | _ -> (0, 0)
back(dir:Base.direction):Base.direction =
match dir with
@@ -26,6 +25,20 @@
| {right} -> {left}
| x -> x
+ is_still(dir:Base.direction) =
+ match dir with
+ | {still_up} | {still_down}
+ | {still_left} | {still_right} -> true
+ | _ -> false
+
+ get_still(dir:Base.direction) =
+ match dir with
+ | {up} -> {still_up}
+ | {down} -> {still_down}
+ | {left} -> {still_left}
+ | {right} -> {still_right}
+ | x -> x
+
}}
@both make(x, y, dir, max_steps) = {
View
2 src/opacman.opa
@@ -100,7 +100,7 @@ default_game = {
| (_, {some=100}) -> {p with next_dir={right}}
// space (pause)
- | (_, {some=32}) -> {p with next_dir={still}}
+ | (_, {some=32}) -> {p with next_dir=Base.Dir.get_still(p.base.dir)}
| _ -> p
game.set({g with pacman=p})
View
6 src/pacman.opa
@@ -38,7 +38,7 @@
ignore_incr = p.base.cur_step < 0
cur_step = p.base.cur_step + 1
cur_step = if cur_step >= p.base.max_steps then 0
- else if p.base.dir == {still} then 0
+ else if Base.Dir.is_still(p.base.dir) then 0
else cur_step
test_wall(on_ok, on_err, x, y) =
if Wall.at(x,y) then on_err
@@ -49,10 +49,10 @@
do print_infos(g)
(dx, dy) = Base.Dir.deltas(p.base.dir)
(ddx, ddy) = Base.Dir.deltas(p.next_dir)
- dir = test_wall(p.next_dir, {still},
+ dir = test_wall(p.next_dir, Base.Dir.get_still(p.next_dir),
p.base.pos.x+dx+ddx, p.base.pos.y+dy+ddy)
(dx, dy, dir) =
- test_wall((dx,dy,dir), (0,0,{still}),
+ test_wall((dx,dy,dir), (0,0,Base.Dir.get_still(dir)),
p.base.pos.x+dx, p.base.pos.y+dy)
if ignore_incr then (dir, 0, 0)
else (dir, dx, dy)
View
5 src/types.opa
@@ -1,4 +1,7 @@
-type Base.direction = {still} / {up} / {down} / {left} / {right}
+type Base.direction =
+ {up} / {down} / {left} / {right}
+ / {still_up} / {still_down}
+ / {still_left} / {still_right}
type Base.pos = {
x : int

0 comments on commit e15b5de

Please sign in to comment.
Something went wrong with that request. Please try again.