Permalink
Browse files

Default values put in one separate file

  • Loading branch information...
1 parent 9b1e15a commit f60e45f35a6013de4b2947ab511617c147eb814a @HenJi committed Oct 19, 2011
Showing with 90 additions and 71 deletions.
  1. +81 −0 src/default.opa
  2. +0 −40 src/food.opa
  3. +0 −14 src/ghost.opa
  4. +6 −6 src/opacman.opa
  5. +1 −9 src/pacman.opa
  6. +2 −2 src/wall.opa
View
@@ -0,0 +1,81 @@
+/**
+ * Game grid
+ *
+ *
+ * 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)
+ * 8: Wall
+ */
+
+grid = [
+ [1,1,1,1,1,1,1,1,1,1,1,1,8,8,1,1,1,1,1,1,1,1,1,1,1,1],
+ [2,8,8,8,8,1,8,8,8,8,8,1,8,8,1,8,8,8,8,8,1,8,8,8,8,2],
+ [1,8,8,8,8,1,8,8,8,8,8,1,8,8,1,8,8,8,8,8,1,8,8,8,8,1],
+ [1,8,8,8,8,1,8,8,8,8,8,1,8,8,1,8,8,8,8,8,1,8,8,8,8,1],
+ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
+ [1,8,8,8,8,1,8,8,1,8,8,8,8,8,8,8,8,1,8,8,1,8,8,8,8,1],
+ [1,8,8,8,8,1,8,8,1,8,8,8,8,8,8,8,8,1,8,8,1,8,8,8,8,1],
+ [1,1,1,1,1,1,8,8,1,1,1,1,8,8,1,1,1,1,8,8,1,1,1,1,1,1],
+ [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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 if v == n then Set.add(~{x y}, acc)
+ else acc,
+ l, acc),
+ grid, Set.empty:set(Base.pos))
+
+ food = get_grid_nums(1)
+ walls = get_grid_nums(8)
+
+ pacman = {
+ base = Base.make(0, 0, {right}, 10)
+ next_dir = {right}
+ mouth_step = 0
+ mouth_incr = 1
+ mouth_steps = 10
+ } : Pacman.t
+
+ @private make_ghost(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
+
+ 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),
+ ] : list(Ghost.t)
+
+}}
View
@@ -1,43 +1,3 @@
-(initial_food, walls) = [
- [1,1,1,1,1,1,1,1,1,1,1,1,8,8,1,1,1,1,1,1,1,1,1,1,1,1],
- [2,8,8,8,8,1,8,8,8,8,8,1,8,8,1,8,8,8,8,8,1,8,8,8,8,2],
- [1,8,8,8,8,1,8,8,8,8,8,1,8,8,1,8,8,8,8,8,1,8,8,8,8,1],
- [1,8,8,8,8,1,8,8,8,8,8,1,8,8,1,8,8,8,8,8,1,8,8,8,8,1],
- [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
- [1,8,8,8,8,1,8,8,1,8,8,8,8,8,8,8,8,1,8,8,1,8,8,8,8,1],
- [1,8,8,8,8,1,8,8,1,8,8,8,8,8,8,8,8,1,8,8,1,8,8,8,8,1],
- [1,1,1,1,1,1,8,8,1,1,1,1,8,8,1,1,1,1,8,8,1,1,1,1,1,1],
- [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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1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
-] |> List.foldi(
- y, l, (food, walls) ->
- List.foldi(
- x, v, (food, walls) ->
- if v == 1 then (Set.add(~{x y}, food), walls)
- else if v == 8 then (food, Set.add(~{x y}, walls))
- else (food, walls),
- l, (food, walls)),
- _, (Set.empty:set(Base.pos), Set.empty:set(Base.pos)))
-
@client Food = {{
draw(ctx:Canvas.context) =
View
@@ -1,19 +1,5 @@
@client Ghost = {{
- 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
-
- 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
View
@@ -2,15 +2,15 @@
fps = 60
base_size = 32
-grid_width = 26
-grid_heigth = 29
+grid_width = List.length(List.head(grid))
+grid_heigth = List.length(grid)
/* Defaults */
-@client default_game = {
- pacman = Pacman.default
- ghosts = Ghost.default
- food = initial_food
+default_game = {
+ pacman = Default.pacman
+ ghosts = Default.ghosts
+ food = Default.food
score = 0
} : Game.status
View
@@ -1,13 +1,5 @@
@client Pacman = {{
- default = {
- base = Base.make(0, 0, {right}, 10)
- next_dir = {right}
- mouth_step = 0
- mouth_incr = 1
- mouth_steps = 10
- } : Pacman.t
-
draw(ctx:Canvas.context) =
g = game.get()
p = g.pacman
@@ -74,7 +66,7 @@
else
if Set.mem(pos, g.food) then
food = Set.remove(pos, g.food)
- if food == Set.empty then (initial_food, g.score+1010)
+ if food == Set.empty then (Default.food, g.score+1010)
else (food, g.score+10)
else (g.food, g.score)
View
@@ -6,13 +6,13 @@
do Canvas.set_fill_style(ctx, {color=Color.darkblue})
do Set.iter(
~{x y} -> Canvas.fill_rect(ctx, 1+x*w, 1+y*w, w, w),
- walls)
+ Default.walls)
do Canvas.restore(ctx)
void
at(x, y) =
x >= grid_width || y >= grid_heigth
|| x < 0 || y < 0
- || Set.mem(~{x y}, walls)
+ || Set.mem(~{x y}, Default.walls)
}}

0 comments on commit f60e45f

Please sign in to comment.