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] Untitled seagull game #2850

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

@title: Untitled chicken game
@author:
@tags: []
@addedOn: 2024-00-00
*/
const seagull = "f"
const automobile = "c"
const road = "r"
const footpath = "s"
const office= "h"
setLegend(
[ seagull, bitmap`
................
................
................
................
.....00000......
....0222220.....
...022222220....
...020220220....
...022922220....
...022222220....
...0222222220...
...0222222200...
...022222220....
....0000000.....
.....9...9......
................` ],
[ automobile, bitmap`
................
................
................
................
......000000....
.....0072770....
..0000772770000.
.06222222222220.
.02222202202290.
.02LLL2222LLL20.
.00L1L0000L1L00.
...LLL....LLL...
................
................
................
................` ],
[ road, bitmap`
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
1111111111111111
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0666006666006660
0666006666006660
0000000000000000
0000000000000000
0000000000000000
0000000000000000
1111111111111111
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL` ],
[ footpath, bitmap`
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111` ],
[ office, bitmap`
................
...LLLLLLLLL....
...L6L6L6L6L....
...LLLLLLLLL....
...L6L6L6L6L....
...LLLLLLLLL....
...L6L6L6L6L....
...LLLLLLLLL....
...L6L6L6L6L....
...LLLLLLLLL....
...L6L6L6L6L....
...LLLLLLLLL....
...L6L6L6L6L....
...LLLLLLLLL....
...L6L66L6LL....
...LLL66LLLL....` ],

)

setSolids([seagull, office])
setBackground(footpath)

let dead;
let moved = true
let score = 0
function spawn() {
dead = false;
clearText()
addText("0", {x:0, color: color`5`})
setMap(map`
.............
.............
.............
.............
.............
.............
.............
.............
.............
......f......`)
for(let y = 0;y < height() - 1;y++)generateRow(y)
loop()
}
spawn()

function loop() {
if(dead) return;
moved = false;
getAll(automobile).forEach(c=>{
if(c.x == 0) c.remove()
else c.x--
})
if(tilesWith(seagull, automobile).length > 0) {
addText("You died!", {color: color`3`})
dead = true;
moved = true;
}
const newautomobile = ~~(Math.random() * height())
const tile = getTile(width()-1, newautomobile);
if(tile.length == 1 && tile[0].type == road) addSprite(width() - 1, newautomobile, automobile)
setTimeout(loop, 250)
}

function generateRow(y) {
if(Math.random() < 0.5) {
for(let x = 0;x < width();x++) addSprite(x, y, road)
} else if(Math.random() < 0.4) {
for(let x = 0;x < width();x++) {
if(Math.random() < 0.5) addSprite(x, y, office)
}
}
}

onInput("w", () => {
if(moved) return;
if(--getFirst(seagull).y < height() - 2) {
getAll().forEach(s=>{
if(s.y == height() - 1) s.remove()
else s.y++
})
generateRow(0)
score++
}
})

onInput("s", () => {
if(moved) return;
getFirst(seagull).y++
score--
})

onInput("a", () => {
if(moved) return;
getFirst(seagull).x--
})

onInput("d", () => {
if(moved) return;
getFirst(seagull).x++
})

afterInput(() => {
if(dead == true) spawn()
moved = true;
if(tilesWith(seagull, automobile).length > 0) {
addText("You died!", {color: color`3`})
dead = true;
} else {
clearText()
addText(""+score, {x:0, color: color`5`})
}
})