Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added games/img/mazevictory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions games/mazevictory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
@title: Maze Escape
@description: Navigate the maze to reach the goal!
*/

// Define sprite keys
const player = "p";
const wall = "w";
const goal = "g";

// Define graphics (bitmaps) for each sprite
setLegend(
[
player,
bitmap`
................
................
....00000000....
....0......0....
....0.0000.0....
....0.0..0.0....
....0.0..0.0....
....0.0000.0....
....0......0....
....00000000....
................
................
................
................
................
................`
],
[
wall,
bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`
],
[
goal,
bitmap`
................
...3333333333...
...3........3...
...3.333333.3...
...3.3....3.3...
...3.3.33.3.3...
...3.3.33.3.3...
...3.3....3.3...
...3.333333.3...
...3........3...
...3333333333...
................
................
................
................
................`
]
);

// Prevent player and walls from walking into/through each other
setSolids([player, wall]);

// Set up the maze map (w = Wall, p = Player start, g = Goal, . = Empty space)
const level = map`
wwwwwwwwwwwwwwww
wp.......w.....w
w.wwwwww.w.www.w
w.w....w.w...w.w
w.w.ww.w.www.w.w
w...ww.w.....w.w
wwwwww.wwwwwww.w
w..............w
w.wwwww.wwwwww.w
w.w...w.w......w
w.w.w.w.w.wwww.w
w...w.w...w..w.w
wwwww.wwwww.ww.w
w...........w.gw
wwwwwwwwwwwwwwww`;

setMap(level);

// Player Movement Controls
onInput("w", () => { getFirst(player).y -= 1; });
onInput("s", () => { getFirst(player).y += 1; });
onInput("a", () => { getFirst(player).x -= 1; });
onInput("d", () => { getFirst(player).x += 1; });

// Win Condition Logic
afterInput(() => {
const p = getFirst(player);
const g = getFirst(goal);

// Check if player reaches the goal tile
if (p.x === g.x && p.y === g.y) {
addText("YOU WIN!", { x: 4, y: 7, color: color`3` });
}
});


Loading