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
135 changes: 135 additions & 0 deletions games/Da-sh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
First time? Check out the tutorial game:
https://sprig.hackclub.com/gallery/getting_started
@title: Dash
@description: Grab the coins, dodge the bad guys!
@author: me
@tags: ['dash', 'arcade']
@addedOn: 2025-01-01
*/

const player = "p"
const coin = "c"
const enemy = "e"
const wall = "w"

setLegend(
[ player, bitmap`
................
................
.......000......
.......0.0......
......0..0......
......0...0.0...
....0003.30.0...
....0.0...000...
....0.05550.....
......0...0.....
.....0....0.....
.....0...0......
......000.......
......0.0.......
.....00.00......
................` ],
[ coin, bitmap`
................
................
......6666......
.....666666.....
....66666666....
....66666666....
....66666666....
....66666666....
.....666666.....
......6666......
................
................
................
................
................
................` ],
[ enemy, bitmap`
................
................
.....22222......
....2222222.....
...222222222....
...22.222.22....
...222222222....
....2..2..2.....
....2..2..2.....
.....2....2.....
................
................
................
................
................
................` ],
[ wall, bitmap`
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL` ]
)

setSolids([ wall ])

let score = 0

const level0 = map`
w w w w w w w w
w p . . c . . w
w . w . . w . w
w . . . e . . w
w c . . . . c w
w . w . . w . w
w . . e . . . w
w w w w w w w w
`

setMap(level0)

setPushables({
[ player ]: []
})

// move the player around
onInput("w", () => { getFirst(player).y -= 1 })
onInput("s", () => { getFirst(player).y += 1 })
onInput("a", () => { getFirst(player).x -= 1 })
onInput("d", () => { getFirst(player).x += 1 })

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

// pick up coins
const coinsHere = tilesWith(coin, p)
if (coinsHere.length > 0) {
coinsHere[0].remove()
score += 1
setText("Score: " + score, { x: 0, y: 0, color: color`3` })
}

// touching an enemy = lose
const enemiesHere = tilesWith(enemy, p)
if (enemiesHere.length > 0) {
addText("You got caught!", { y: 3 })
}

// win when all coins are gone
if (tilesWith(coin).length === 0) {
addText("You win! Score: " + score, { y: 3 })
}
})
Loading