Skip to content
Open
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
208 changes: 208 additions & 0 deletions games/Maze-Game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/*
First time? Check out the tutorial game:
https://sprig.hackclub.com/gallery/getting_started

@title: Maze Game
@author:
@tags: []
@addedOn: 2025-00-00
*/

const player = "p"
const wall = "w"
const finish = "f"

setLegend(
[ player, bitmap`
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333` ],
[ wall, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000` ],
[ finish, bitmap`
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666` ]
)

setSolids([ player, wall ])

let level = 0
const levels = [
map`
....p
.wwww
.wwwf
.www.
.....`,

// Level 2
map`
p....
wwww.
.....
.wwww
....f`,

// Level 3
map`
.w.wf..
.....w.
.ww.w..
..w.w.w
w.p.w.w
ww.....
ww...ww`,

// Level 4
map`
fw...www..w...
.www...wwwwww.
....w..w.w....
..w...ww.w...w
.w.ww.w..w.www
.w..w.w..w.w..
ww..w.ww.w.w..
.w.......w.w..
.wwwwwww...www
.w...w...w.wpw
.ww.......ww.w
.....wwww....w`,

// Level 5
map`
p.w...ww.w.....
w.www....w.ww..
w.w.www.ww.w.ww
w.w........w...
w...ww..w.wwww.
ww....w.w....w.
.w.ww.w.w.wwww.
.w..w.w.w....w.
.ww...w.wwww.w.
....w........w.
w...w.w.wwww.w.
w...w.w..wfw.w.
wwwww.ww.w.w...
.........w.www.
..wwwwww.w.....`,

// Level 6
map`
wwwwwwwwwwwwwwwwwwww
w..w.pw.wwwww......w
w..w..w.....w.www..w
w.....wwwww.w.w.w..w
w.w.w.........w.w..w
w.w.wwwwww.ww.w.w..w
w.w......w.ww.www..w
w.w..www.w.ww......w
w.w......w..wwwwww.w
w.www.w..ww........w
w.w...w............w
w.ww..w.wwwwwwwwwwww
w.....w.w........www
w..w..w.wwwwwwwwww.w
wwwww.......w......w
w....wwwwww.wwww.w.w
w.ww..w..........w.w
w...w.wwwwwwwwwwww.w
wf..w..............w
wwwwwwwwwwwwwwwwwwww`
]


setMap(levels[level])

setPushables({
[ player ]: []
})

onInput("s", () => {
const p = getFirst(player)
const oldX = p.x
const oldY = p.y
p.y += 1
addSprite(oldX, oldY, wall)
})

onInput("w", () => {
const p = getFirst(player)
const oldX = p.x
const oldY = p.y
p.y -= 1
addSprite(oldX, oldY, wall)
})

onInput("a", () => {
const p = getFirst(player)
const oldX = p.x
const oldY = p.y
p.x -= 1
addSprite(oldX, oldY, wall)
})

onInput("d", () => {
const p = getFirst(player)
const oldX = p.x
const oldY = p.y
p.x += 1
addSprite(oldX, oldY, wall)
})
Comment on lines +182 to +192
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Player can move through wall sprites and off-map boundaries due to direct coordinate modification without collision or boundary checks.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The Maze-Game.js code directly modifies player coordinates (e.g., p.y += 1, p.x -= 1) without performing collision detection or boundary checks. This allows the player sprite to move into solid wall sprites defined in the game map and also to move off the map boundaries (negative or out-of-bounds coordinates). The setSolids function does not prevent direct coordinate assignment into solid sprites, requiring explicit getTile checks before movement, as demonstrated in BitBoy_Adventure.js. This violates intended game mechanics, making walls passable and potentially leading to undefined behavior off-map.

💡 Suggested Fix

Implement explicit collision detection using getTile checks before modifying player coordinates, similar to BitBoy_Adventure.js, to prevent movement into wall sprites and off-map.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: games/Maze-Game.js#L162-L192

Potential issue: The `Maze-Game.js` code directly modifies player coordinates (e.g.,
`p.y += 1`, `p.x -= 1`) without performing collision detection or boundary checks. This
allows the player sprite to move into solid `wall` sprites defined in the game map and
also to move off the map boundaries (negative or out-of-bounds coordinates). The
`setSolids` function does not prevent direct coordinate assignment into solid sprites,
requiring explicit `getTile` checks before movement, as demonstrated in
`BitBoy_Adventure.js`. This violates intended game mechanics, making walls passable and
potentially leading to undefined behavior off-map.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5709608



afterInput(() => {
const p = getFirst(player)
const f = getFirst(finish)

// Check if player reached finish
if (p && f && p.x === f.x && p.y === f.y) {
level++
if (level < levels.length) {
setMap(levels[level])
} else {
addText("You win!", { x: 5, y: 5, color: color`3` })
}
}
})