Skip to content

CoinCollector #3109

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
337 changes: 337 additions & 0 deletions games/CoinCollector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@

/*
@title: CoinCollector
@description: A simple maze game where you play as a coin that has to get to a piggy bank.
@author: Alfonso Espino
@tags: [maze, puzzle, coin]
@addedOn: 5/10/2025
*/

const player = "p"
const goal = "g"
const wall = "w"
const trap = "t"

const nextLevelTune = tune`
500: C5-500,
15500`

const BGMusic = tune`
500: C4-500 + G5^500,
500: B5-500 + F4^500,
500: D4-500 + F5^500,
500: A5-500 + G4^500,
500: E4-500 + E5^500,
500: G5-500 + A4^500,
500: F4-500 + D5^500,
500: F5-500 + B4^500,
500: G4-500 + C5^500,
500: E5-500,
500: A4-500,
500: D5-500,
500: B4-500,
500: C5-500,
500: C5/500,
500: D5/500,
500: B4/500,
500: E5/500,
500: A4/500,
500: F5/500 + D5~500 + C5~500,
500: G4/500,
500: G5/500 + E5~500 + B4~500,
500: F4/500,
500: A5/500 + F5~500 + A4~500,
500: E4/500,
500: B5/500 + G5~500 + G4~500,
500: D4/500,
500: A5~500 + F4~500,
500: C4/500,
500: B5~500 + E4~500,
500: C4/500,
500: D4~500 + B5/500`

const playback = playTune(BGMusic, Infinity)

setLegend(
[ player, bitmap`
....00000000....
...0066666600...
..006666666600..
.00666600066600.
0066660060006600
0666600666666660
0666606666666660
0666006666666660
0666066666666660
0666006666606660
0666606666006660
0066600660066600
.00666000066600.
..006666666600..
...0066666600...
....00000000....` ],
[ goal, bitmap`
................
...88..8888.....
...8888888888...
...88888008888..
..888880880888..
..8808888888888.
8888888888888888
8888888888888888
8888888888888888
888888888888888.
.88888888888888.
..888888888888..
...8888888888...
...8888888888...
...888....888...
................` ],
[ wall, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000` ],
[ trap, bitmap`
....33333333....
...3333333333...
..333......333..
.3333......3333.
333333....333333
33..333..333..33
33...333333...33
33....3333....33
33....3333....33
33...333333...33
33..333..333..33
333333....333333
.3333......3333.
..333......333..
...3333333333...
....33333333....`]
)

setSolids([wall, player])

let level = 0
const levels = [
map`
p...
.ww.
.ww.
...g`,
map`
..pwww
.wwwww
.ww...
....w.
wwwww.
wwwwwg`,
map`
pw...ww.g
......w..
wwww..ww.
.......w.
.wwwwwww.
.........`,
map`
t.t...t.t
....t....
pt.....tg
.....t...
t..t....t`,
map`
tw.tw..wt.t.
..t..wt.ww.g
p.w.t...w...
w......t.t.w
t.t.w.w.tw..
.w.wt.......`,
map`
p..twww
tt.twww
wt.tttt
.......
ttttt.t
t......
t.wwwww
t.wwttt
t.ttwww
t.....g`,
map`
tttttttttttttt
pttttttttttttt
.tttttttttt.tt
..tttt.ttt...t
t.ttt...tt.t.g
t..t..t.t..ttt
tt...tt...tttt`,
map`
tptg........ttt......tt
t.t.tt.....tt.........t
t.t..tt..ttt....tttt...
t.t...ttt.....ttt..tt..
t.t.........ttt....t...
t.tttt.....tt......t..t
t.t..ttttttt......t..tt
t.t...tt...tt....tt.tt.
t.t..tt.....t....t..t..
t.t.tt..ttt.tt...t..t..
t.ttt..tt.t..tt..t.tt..
t.tt..tt...t..tttt.t...
t....tt....tt......t...`,
map`
t...t...t...t...t...t...
..t...t...t...t...t...t.
pttttttttttttttttttttttg
....ttt.....ttt.....ttt.
ttt.....ttt.....ttt.....`,
map`
tt.t...t......t..
.....t....t.t...t
gtt....tttttt.t..
ttttt.t......t.t.
ttttt.t.tttt.tt..
tttt..t.tttt.tt.t
tt...tt.tttt.tt..
.t.tttt.tttt.t..t
.t......tttt.tt..
.t.tttt.tttt.ttt.
................p`,
map`
tt...p.t.tt
........t..
t.t.t..t...
t....tttt..
.t...ttt.tt
.t.t..t....
tt..t....t.
....t..t..t
tttt..t..tt
.tttttt...t
tt......t..
t..t..ttt..
ttt....tt.t
.ttt.t..ttt
...tttt.t..
ttt.t...tt.
.tt....t.t.
.tt...tt.t.
tt...g.tt..`,
map`
....t...t.....t....
..t...t.t.ttt...tt.
.tttttt...ttttttt..
.tttp.tttttt.t.tt.t
.tttt..tt.tt.t.tt..
.tt.tt....ttt..ttt.
.tttttttt.t..ttttt.
.ttttt..t.....ttt..
.t...ttt.tttt.ttt.t
.t.t...tt.ttt.t.t..
...ttt....t...tttt.
tttt.tttt...t.tg...`,
map`
wwwwwww
wwwwwww
wwwpwww
wwwwwww
wwwwwww`
]

setMap(levels[level])

setPushables({
[ player ]: []
})

onInput("s", () => {
getFirst(player).y += 1
})

onInput("a", () => {
getFirst(player).x -= 1
})

onInput("w", () => {
getFirst(player).y -= 1
})

onInput("d", () => {
getFirst(player).x += 1
})

afterInput(() => {
const goalsCovered = tilesWith(player, goal)
if (goalsCovered.length >= 1) {
level += 1;
if (level < levels.length) {
setMap(levels[level]);
if (level == 12) {
addText("You Win! \nPress j to\nplay again!", { x: 3, y: 1, color: color`6` });
const winTune = tune`
44.642857142857146: C4~44.642857142857146,
44.642857142857146: D4~44.642857142857146,
44.642857142857146: D4~44.642857142857146 + E4~44.642857142857146,
44.642857142857146: E4~44.642857142857146,
44.642857142857146: E4~44.642857142857146 + F4~44.642857142857146,
44.642857142857146: F4~44.642857142857146,
44.642857142857146: F4~44.642857142857146,
44.642857142857146: F4~44.642857142857146 + G4~44.642857142857146,
44.642857142857146: G4~44.642857142857146,
44.642857142857146: G4~44.642857142857146,
44.642857142857146: A4~44.642857142857146,
44.642857142857146: A4~44.642857142857146,
44.642857142857146: B4~44.642857142857146,
44.642857142857146: C5~44.642857142857146,
44.642857142857146: C5~44.642857142857146,
44.642857142857146: C5~44.642857142857146,
44.642857142857146: C5~44.642857142857146 + D5~44.642857142857146,
44.642857142857146: D5~44.642857142857146,
44.642857142857146: D5~44.642857142857146,
44.642857142857146: E5~44.642857142857146,
44.642857142857146: E5~44.642857142857146,
44.642857142857146: E5~44.642857142857146 + F5~44.642857142857146,
44.642857142857146: F5~44.642857142857146,
44.642857142857146: F5~44.642857142857146,
44.642857142857146: F5~44.642857142857146,
44.642857142857146: F5~44.642857142857146 + G5~44.642857142857146,
44.642857142857146: G5~44.642857142857146,
44.642857142857146: G5~44.642857142857146,
44.642857142857146: G5~44.642857142857146 + A5~44.642857142857146,
44.642857142857146: A5~44.642857142857146,
44.642857142857146: A5~44.642857142857146,
44.642857142857146: B5~44.642857142857146`;
playTune(winTune);
} else {
playTune(nextLevelTune)
}
}
}
})

onInput("j", () => {
level = 0
setMap(levels[level])
clearText()
})

afterInput(() => {
const trapsCovered = tilesWith(player, trap)
if (trapsCovered.length >= 1) {
level = 0
setMap(levels[level])
}
})