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

@title: Sniper Simulator
@author:
@tags: []
@addedOn: 2025-00-00
*/

const player = "p"
const solid = "*"
const target = "x"
const crosshair = "+"
const flash = "F"
const shot = tune`
0,
37.5: C4/37.5 + D4/37.5 + E4/37.5 + F4/37.5 + G4/37.5,
37.5: F4/37.5 + E4/37.5 + D4/37.5 + G4~37.5 + C4~37.5,
0`
const start = performance.now()

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......
................` ],
[ solid, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000` ],
[ crosshair, bitmap`
.......33.......
.....333333.....
....33333333....
...33..33..33...
..33...33...33..
.33....33....33.
.33....33....33.
3333333..3333333
3333333..3333333
.33....33....33.
.33....33....33.
..33...33...33..
...33..33..33...
....33333333....
.....333333.....
.......33.......` ],
[ target, bitmap`
......6LLLL.....
......L6LLL.....
......6L6LL.....
......L6LLL.....
......6LLLL.....
......LLLLL.....
.......111......
.......111......
......LLLLL.....
.....LLLLLLL....
.....LLLLLLL....
.....LLLLLLL....
.....LLLLLLL....
.....LLLLLLL....
.....LLLLLLL....
.....LLLLLLL....` ],
[ flash, bitmap`
................
................
...999999.......
..99999999......
..9999999999....
.996666999999...
.9666666699999..
.96666666699999.
.96666666699999.
.9666666699999..
.996666999999...
..9999999999....
..99999999......
...999999.......
................
................` ]
)

setSolids([])

let level = 0
const levels = [
map`
........................................
........................................
........................................
........................................
........................................
........................................
........................................
........................................
.***....................................
.*****..................................
.***....................................
.***....................................
..*..***................................
************............................
*****.***...............................
****.*..................................
.***....................................
*********...............................
*********...............................
********................................
********................................
******..................................
*****...................................
****....................................
........................................
........................................
........................................
........................................
........................................
........................................`
]
const targets = [
[20, 10], [32, 24], [37, 20], [28, 6], [25, 15], [35, 11], [23, 25]
]

setMap(levels[level])
for (x = 0; x < targets.length; x++) {
addSprite(targets[x][0], targets[x][1], target)
}
addSprite(12, 13, crosshair)
ch = getFirst(crosshair)

onInput("w", () => {
ch.y -= 1
clearTile(12, 13)
})
onInput("a", () => {
ch.x -= 1
clearTile(12, 13)
})
onInput("s", () => {
ch.y += 1
clearTile(12, 13)
})
onInput("d", () => {
ch.x += 1
clearTile(12, 13)
})
onInput("k", () => {
addSprite(12, 13, flash)
playTune(shot)
var x = ch.x
var y = ch.y
clearTile(ch.x, ch.y)
addSprite(x, y, crosshair)
ch = getFirst(crosshair)
})

afterInput(() => {
if (getAll(target).length == 0) {
const timeElapsed = ((performance.now() - start) / 1000)
addText("All targets\n eliminated.\n Time: " + timeElapsed, {x: 0, y: 10})
}
})