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

Space jam sprig game #2313

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
154 changes: 154 additions & 0 deletions games/Space jam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
First time? Check out the tutorial game:
https://sprig.hackclub.com/gallery/getting_started

@title: Space jam
@author: Praveenkushinpi
@tags: []
@addedOn: 2024-09-17
*/
const rocket = "r";
const space = "s";
const meteor = "m";
let gameOver = false;

setLegend(
[ rocket, bitmap`
................
.......0........
......010.......
.....01710......
....0177710.....
...017727710....
..01772227710...
...222222222....
...222222222....
...222202222....
...202020202....
...222020222....
...202002202....
...202020202....
...222022222....
...222222222....`] ,
[ space, bitmap`
0000000000000000
0020000000000020
0000000000000000
0000002000020000
0000000000000000
0000000000000000
0002000000000200
0000000020000000
0200000000000000
0000000000000000
0000000000000000
0000000000000000
0020000002000200
0000000000000000
0000000000000000
0000000000000000`],
[ meteor, bitmap`
................
......000000....
....001110110...
...01111111110..
...01101111110..
...01111011110..
..011011111110..
..011111111010..
.0111111011110..
.0111111111110..
..011101111110..
.011111111010...
..01101111110...
..0111111110....
...00111010.....
.....00000......`]
);

setSolids([]);

let score = 0;
let level = 0;

const levels = [
map`
...........
...........
...........
...........
...........
...........
...........
...........
.....r.....`
];
setMap(levels[level]);

setSolids([meteor]);

let gameRunning = true;

function spawnMeteor() {
let x = Math.floor(Math.random() * 10);
let y = 0;
addSprite(x, y, "m");
}

function moveMeteor() {
let meteors = getAll("m");

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

function despawnMeteor() {
let meteors = getAll("m");

for (let i = 0; i < meteors.length; i++) {
if (meteors[i].y == 8) {
meteors[i].remove();
}
}
}

function checkHit() {
let meteors = getAll("m");
let r = getFirst("r");

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

return false;
}

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

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

setBackground(space);

var gameLoop = setInterval(() => {
if (checkHit()) {
gameOver = true;
clearInterval(gameLoop);
addText(`Game Over! Final Score: ${score}`, { x: 4, y: 4, color: color`3` });
return;
}

score += 1;
addText(`Score: ${score}`, { x: 8, y: 1, color: color`2` });

despawnMeteor();
moveMeteor();
spawnMeteor();

}, 300);
Binary file added games/img/Space jam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading