Skip to content

Commit

Permalink
A frogger-ish game (#2810)
Browse files Browse the repository at this point in the history
* Add files via upload

* Add files via upload

* Update frog.js

---------

Co-authored-by: Mare Cosmin <[email protected]>
  • Loading branch information
ItsFelix5 and Cosmin-Mare authored Jan 22, 2025
1 parent d639d59 commit bead8e1
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 0 deletions.
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.

0 comments on commit bead8e1

Please sign in to comment.