Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sprig App] Maze Ball #2848

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
159 changes: 159 additions & 0 deletions games/Maze-Ball.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
First time? Check out the tutorial game:
https://sprig.hackclub.com/gallery/getting_started

@title: Maze Ball
@author:
@tags: []
@addedOn: 2024-00-00
*/

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)

// 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......w.w
wwwww.www.w
w.........w
w.www.....w
w.w.......w
wwwww.....w
w.........w
wwwwww....w
w........gw
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.