Skip to content

Commit

Permalink
FOOD-CATCH (#1130)
Browse files Browse the repository at this point in the history
* Add files via upload

* Add files via upload

* Add files via upload

* Delete FOOT CAHTCH.js

* Rename FOOT CATCH.js to FOOT-CATCH.js

* Add files via upload

* Rename FOOT-CATCH.js to FOOD-CATCH.js

* Add files via upload

* Add files via upload

---------

Co-authored-by: Lucas <[email protected]>
  • Loading branch information
jakob07ffm and LucasHT22 authored Sep 2, 2023
1 parent 51ecf9a commit 4ca53bf
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
144 changes: 144 additions & 0 deletions games/FOOD-CATCH.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
const player = "p";
const obstacle = "o";
let score = 0;
let floorfoodhit = 0;

setLegend(
[obstacle, bitmap`
.......C.DDD....
.......CDD4D....
.......CD4D.....
.....333333.....
....33333333....
...3333333333...
...3333333333...
...3333333333...
...3333333333...
...3333333333...
...3333333333...
....33333333....
.....333333.....
................
................
................`],
[player, bitmap`
................
................
................
.....00000......
....0.....0.....
....0.0.0.0.....
....0.....0.....
....0.000.0.....
....0.....0.....
.....00000......
.......0........
.....00000......
.......0........
.......0........
......0.0.......
.....0...0......`]
)

setMap(map`
..........
..........
..........
..........
..........
..........
..........
....p.....`)

var gameRunning = true;

onInput("a", () => {
if (gameRunning) {
getFirst(player).x -= 1;
}
});

onInput("d", () => {
if (gameRunning) {
getFirst(player).x += 1;
}
});

function spawnObstacle() {
let x = Math.floor(Math.random() * 8);
let y = 0;
addSprite(x, y, obstacle);
}

function moveObstacles() {
let obstacles = getAll(obstacle);

for (let i = 0; i < obstacles.length; i++) {
obstacles[i].y += 1;
}
}

function despawnObstacles() {
let obstacles = getAll(obstacle);

for (let i = 0; i < obstacles.length; i++) {
if (obstacles[i].y == 7) {
obstacles[i].remove();
floorfoodhit ++;
}
}
}

function checkHit() {
let obstacles = getAll(obstacle);
let p = getFirst(player);

for (let i = 0; i < obstacles.length; i++) {
if (obstacles[i].x == p.x && obstacles[i].y == p.y) {
obstacles[i].remove();
return true;
}
}

return false;
}

function gameover(){
let obstacles = getAll(obstacle);
for (let i = 0; i < obstacles.length; i++) {
obstacles[i].remove();
}
addText("Game Over!", {
x: 5,
y: 6,
color: color`3`
});
clearInterval(gameLoop);
gameRunning = false;
}

var gameLoop = setInterval(() => {
despawnObstacles();
moveObstacles();
spawnObstacle();
let scortext = addText("Score:" + score, {
x: 1,
y: 1,
color: color`3`
});

let hittext = addText("Misses:" + floorfoodhit, {
x: 11,
y: 1,
color: color`0`
});


if (checkHit()) {
score ++;
}
if (floorfoodhit == 3){
gameover();
}

}, 1000);
Binary file added games/img/FOOD-CATCH.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added games/img/FOOT CATCH.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added games/img/FOOT-CATCH.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 4ca53bf

@vercel
Copy link

@vercel vercel bot commented on 4ca53bf Sep 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sprig – ./

sprig-git-main-gamer.vercel.app
sprig.vercel.app
sprig-gamer.vercel.app

Please sign in to comment.