-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
51ecf9a
commit 4ca53bf
Showing
4 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4ca53bf
There was a problem hiding this comment.
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