Skip to content

Commit

Permalink
Merge branch 'main' into TICTACGPT
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasHT22 authored Sep 8, 2023
2 parents c6f62c5 + 2d22f3c commit 8619914
Show file tree
Hide file tree
Showing 31 changed files with 7,253 additions and 1 deletion.
182 changes: 182 additions & 0 deletions games/Eat_&_Don't_Be_Eaten.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
First time? Check out the tutorial game:
https://sprig.hackclub.com/gallery/getting_started
*/

const player = "p"
const enemy = "e"
const food = 'f'

setLegend(
[ player, bitmap`
................
................
.......000......
.......0.0......
......0..0......
......0...0.0...
....0003.30.0...
....0.0...000...
....0.05550.....
......0...0.....
.....0....0.....
.....0...0......
......000.......
......0.0.......
.....00.00......
................` ],
[ enemy, bitmap`
................
................
................
....33333333....
....30033003....
....30033003....
....33333333....
....33300333....
....33000033....
....30000003....
....33333333....
................
................
................
................
................`],
[food, bitmap`
................
................
................
.....606606.....
....66666666....
...6333333336...
...DDDDDDDDDD...
...CCCCCCCCCC...
...6CCCCCCCC6...
....66666666....
.....666666.....
................
................
................
................
................`]
)

setSolids([])

let level = 0
const levels = [
map`
e.....
......
....f.
......
......
...p..`
]

setMap(levels[level])

setPushables({
[ player ]: []
})

onInput("s", () => {
if (gameRunning) {
getFirst(player).y += 1
}

})
onInput("w", () => {
if (gameRunning) {
getFirst(player).y -= 1
}
})
onInput("a", () => {
if (gameRunning) {
getFirst(player).x -= 1
}
})
onInput("d", () => {
if (gameRunning) {
getFirst(player).x += 1
}
})

onInput("i", () => {
clearText()
setMap(levels[level])
startGame()
score = 0
})
function checkDie() {
let e = getFirst(enemy);
let p = getFirst(player);

if (e.x == p.x && e.y == p.y) {
return true;
}

return false;
}
function moveEnemy() {
let theEnemy = getFirst(enemy);
let dirX = (theEnemy.x - getFirst(player).x) / Math.abs(theEnemy.x - getFirst(player).x);
let dirY = (theEnemy.y - getFirst(player).y) / Math.abs(theEnemy.y - getFirst(player).y);

theEnemy.x -= dirX
theEnemy.y -= dirY
}

function spawnFood() {
let f = getFirst(food)
f.x = Math.floor(Math.random() * 8);
f.y = Math.floor(Math.random() * 8);
}

function checkEat() {
let f = getFirst(food);
let p = getFirst(player);

if (f.x == p.x && f.y == p.y) {
return true;
}

return false;
}
let score = 0;

afterInput(() => {
if (checkEat()) {
score += 1;
spawnFood();
}
})


var gameLoop;
let gameRunning = true;

function startGame() {
gameRunning = true;
gameLoop = setInterval(() => {
moveEnemy()
if (checkDie()) {
clearInterval(gameLoop);
gameRunning = false;
addText("Score: " + score, {
x: 5,
y: 6,
color: color`3`
});
addText("Press I to reset", {
x: 2,
y: 8,
color: color`3`
});
}

}, 500);

}

startGame();
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);
Loading

0 comments on commit 8619914

Please sign in to comment.