Skip to content

Commit

Permalink
Sprig App - Maze Ball
Browse files Browse the repository at this point in the history
  • Loading branch information
doggo742 committed Feb 4, 2025
1 parent 62970b5 commit fad25e7
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 0 deletions.
216 changes: 216 additions & 0 deletions games/Maze-Ball.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/*
First time? Check out the tutorial game:
https://sprig.hackclub.com/gallery/getting_started
@title: Maze Ball
@author: doggo_742
@tags: []
@addedOn: 2024-00-00
Roll through the labyrinth! New levels every day!
*/

const player = "p"
const wall = "w"
const goal = "g"
setLegend(
[player, bitmap`
................
................
.....555555.....
...5555555555...
...5555555555...
..555555555555..
..555555555555..
..555555555555..
..555555555555..
..555555555555..
..555555555555..
...5555555555...
...5555555555...
.....555555.....
................
................`],
[wall, bitmap`
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL`],
[goal, bitmap`
................
................
.....DDDDDD.....
...DDDDDDDDDD...
...DD......DD...
..DD........DD..
..DD........DD..
..DD........DD..
..DD........DD..
..DD........DD..
..DD........DD..
...DD......DD...
...DDDDDDDDDD...
.....DDDDDD.....
................
................`],
)
// Make sure each sprite definition is enclosed in square brackets within the setLegend function call.
setSolids([wall, player])

// Add this code inside the afterInput block to check for reaching the goal
afterInput(() => {
const playerSprite = getFirst(player)
const goalTile = getTile(playerSprite.x, playerSprite.y).find(sprite => sprite.type === goal)

if (goalTile) {
level++
clearTile(playerSprite.x, playerSprite.y)
if (levels[level]) {
setMap(levels[level])
} else {
console.log("You have completed all levels!")
}
}
})
let level = 0
const levels = [
map`
wwwwwwwwwww
w.........w
w.wwwww.w.w
w.w...w.www
w.w.www...w
w...wp..w.w
www.wwwwwww
w......w.gw
w.www.ww.ww
w...w.....w
wwwwwwwwwww`,
map`
wwwwwwwwwww
w...w.....w
w.w.wwwww.w
w.w.......w
w.wwwwwww.w
w.wpwg..w.w
w.w.www.w.w
w.w.w...w.w
w.w.w.www.w
w...w.....w
wwwwwwwwwww`,
map`
wwwwwwwwwww
w........pw
w.wwwwwwwww
w.w...w.w.w
w.www.w.w.w
w...w.w...w
w.w.w.w.www
w.w.......w
www.wwwww.w
w.....wg..w
wwwwwwwwwww`,
map`
wwwwwwwwwww
wp....wgw.w
www.www.w.w
w.w.w.w.w.w
w.w.w.w.w.w
w.w...w...w
w.w.w.www.w
w.w.w.w...w
w.www.w.www
w.........w
wwwwwwwwwww`,
map`
wwwwwwwwwww
wp....w...w
w.wwwwwww.w
w...w.....w
www.w.w.www
w.....w.w.w
w.wwwwwww.w
w.........w
www.wwwww.w
w...wg....w
wwwwwwwwwww`,
map`
wwwwwwwwwww
wp....w...w
w.w.w.w.w.w
w.w.w.w.w.w
www.www.www
w.........w
w.www.w.w.w
w...w.w.w.w
wwwwwww.w.w
wg......w.w
wwwwwwwwwww`,
map`
wwwwwwwwwww
w.....w...w
www.w.www.w
w...wpw.w.w
www.www.w.w
wgw.......w
w.wwwww.w.w
w.w...w.w.w
w.www.www.w
w.........w
wwwwwwwwwww`,
map`
wwwwwwwwwww
w..pw...wgw
w.www.www.w
w.....w...w
w.wwwwwww.w
w...w.w...w
www.w.w.www
w.w.w.w...w
w.w.w.www.w
w.........w
wwwwwwwwwww`,
map`
wwwwwwwwwww
wpwg......w
w.wwwwwww.w
w.w.w...w.w
w.w.www.w.w
w.......w.w
w.w.www.w.w
w.w.w...w.w
w.wwwww.w.w
w...w.....w
wwwwwwwwwww`

]

setMap(levels[level])

setPushables({
[player]: []
})

onInput("s", () => {
getFirst(player).y += 1
})
onInput("w", () => {
getFirst(player).y -= 1
})
onInput("d", () => {
getFirst(player).x += 1
})
onInput("a", () => {
getFirst(player).x -= 1
})
Binary file added games/img/Maze-Ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fad25e7

Please sign in to comment.