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

A frogger-ish game #2810

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
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
193 changes: 193 additions & 0 deletions games/frog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
@title: Frog
@author: Felix
@tags: ['endless', 'retro', 'adventure', 'survival']
@addedOn: 2025-01-22
*/

const frog = "f"
const car = "c"
const road = "r"
const sidewalk = "s"
const house = "h"
setLegend(
[ frog, bitmap`
................
........DD..DD..
.......D44DD44D.
......D4404440D.
......D4444DD44D
.....D444444444D
....D444422224D.
...D444422224D..
..D444422222D...
.D44444222DD....
.D4D44D42D4D....
.D44D4D44D44D...
D4444D4444D44D..
................
................
................` ],
[ car, bitmap`
................
................
................
................
.......33333....
......3373733...
.....33773773...
....3377737733..
..3333333333333.
333333333333333.
6330003333300033
3330103333301033
...000.....000..
................
................
................` ],
[ road, bitmap`
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
1111111111111111
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0666006666006660
0666006666006660
0000000000000000
0000000000000000
0000000000000000
0000000000000000
1111111111111111
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL` ],
[ sidewalk, bitmap`
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLL` ],
[ house, bitmap`
................
................
................
................
.....333333.....
....33333333....
...3333333333...
..333333333333..
...CCCCCCCCCC...
...CCCCCCCCCC...
...C777CCCCCC...
...C777CCCCCC...
...C777CC000C...
...CCCCCC000C...
...CCCCCC600C...
...CCCCCC000C...` ],
)

setSolids([frog, house])
setBackground(sidewalk)

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(car).forEach(c=>{
if(c.x == 0) c.remove()
else c.x--
})
if(tilesWith(frog, car).length > 0) {
addText("You died!", {color: color`3`})
dead = true;
moved = true;
}
const newCar = ~~(Math.random() * height())
const tile = getTile(width()-1, newCar);
if(tile.length == 1 && tile[0].type == road) addSprite(width() - 1, newCar, car)
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, house)
}
}
}

onInput("w", () => {
if(moved) return;
if(--getFirst(frog).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(frog).y++
score--
})

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

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

afterInput(() => {
if(dead == true) spawn()
moved = true;
if(tilesWith(frog, car).length > 0) {
addText("You died!", {color: color`3`})
dead = true;
} else {
clearText()
addText(""+score, {x:0, color: color`5`})
}
})
Binary file added games/img/frog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading