forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
352 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,193 @@ | ||
/* | ||
@title: CatchIt | ||
@author: Shrey Mehra | ||
Creds:- | ||
A_Really_One_Sided_Duel by Saatwik Das (The working was similar so I copied algorithms) | ||
Falling_Blocks by Thanosan Prathifkumar (Again, I copied the algorithm to make my work easy) | ||
*/ | ||
|
||
const player = "p"; | ||
const obstacle = "o"; | ||
|
||
let gameOver = false; | ||
|
||
let score = 0; | ||
let miss = 5; | ||
let timer = 0; | ||
const hit = tune` | ||
500, | ||
500: F5^500 + A4^500, | ||
15000`; | ||
const gameOverTune = tune` | ||
60.120240480961925: C5~60.120240480961925, | ||
60.120240480961925: C5~60.120240480961925 + B4~60.120240480961925 + A4~60.120240480961925, | ||
60.120240480961925: A4~60.120240480961925 + G4~60.120240480961925, | ||
60.120240480961925: F4~60.120240480961925, | ||
60.120240480961925: F4~60.120240480961925 + E4~60.120240480961925, | ||
60.120240480961925: E4~60.120240480961925 + D4~60.120240480961925, | ||
60.120240480961925: D4~60.120240480961925 + C4~60.120240480961925, | ||
60.120240480961925: C4~60.120240480961925, | ||
1442.8857715430863`; | ||
const missed = tune` | ||
86.20689655172414: B4-86.20689655172414, | ||
86.20689655172414: A5-86.20689655172414, | ||
86.20689655172414: B4-86.20689655172414, | ||
2500`; | ||
|
||
setLegend( | ||
[ obstacle, bitmap` | ||
................ | ||
................ | ||
................ | ||
......99999..... | ||
.....9666669.... | ||
....966966669... | ||
...96699666669.. | ||
...96966666669.. | ||
...96966666669.. | ||
...96696666669.. | ||
...96666666669.. | ||
....966666669... | ||
.....9666669.... | ||
......99999..... | ||
................ | ||
................`], | ||
|
||
[ player, bitmap` | ||
4444444444444444 | ||
4444444444444444 | ||
3333333333333333 | ||
3333333333333333 | ||
4444444444444444 | ||
4444444444444444 | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................ | ||
................`] | ||
); | ||
|
||
const level = map` | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
p...........`; | ||
const clear = map` | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............ | ||
............`; | ||
|
||
let obstacles = []; | ||
|
||
setMap(level); | ||
|
||
const obstacleSpawn = setInterval(() => { | ||
// generate obstacles | ||
let x = Math.floor(Math.random() * 12); | ||
let found = false; | ||
for(let i = 0; i < obstacles.length; ++i) { | ||
if(obstacles[i][0] == x && obstacles[i][1] == 0 || obstacles[i][0] == x && obstacles[i][1] == 1) { | ||
found = true; | ||
} | ||
} | ||
if(!found) { | ||
addSprite(x, 0, obstacle); | ||
obstacles.push([x, 0]); | ||
} | ||
}, 1000); | ||
|
||
const obstacleUpdate = setInterval(() => { | ||
for(let i = 0; i < obstacles.length; ++i) { | ||
let pos = obstacles[i]; | ||
let tile = getTile(...pos); | ||
if(tile.length > 0) { | ||
tile[0].y += 1; | ||
obstacles[i][1] += 1; | ||
} | ||
} | ||
|
||
let toRemove = []; | ||
|
||
for(let i = 0; i < obstacles.length; ++i) { | ||
let playerPos = getFirst(player); | ||
let playerX = playerPos.x; | ||
let playerY = playerPos.y; | ||
if(obstacles[i][0] == playerX && obstacles[i][1] >= playerY - 1) { | ||
playTune(hit); | ||
score += 1; | ||
toRemove.push(i); | ||
|
||
} | ||
} | ||
for(let i = 0; i < obstacles.length; ++i) { | ||
if(obstacles[i][1] == getFirst(player).y) { | ||
toRemove.push(i); | ||
miss -= 1; | ||
playTune(missed); | ||
} | ||
} | ||
for(let i = 0; i < toRemove.length; ++i) { | ||
getTile(...obstacles[toRemove[i]]).forEach(item => { | ||
if(item != null && item.type != "p") { | ||
item.y = getFirst(player).y; | ||
setTimeout(() => { | ||
item.remove(); | ||
obstacles.splice(toRemove[i], 1); | ||
}, 100); | ||
} | ||
}); | ||
} | ||
|
||
clearText(); | ||
addText(`Score: ${score}`, { x : 1, y : 0}); | ||
addText(`Misses: ${miss}`, { x : 10, y : 0}); | ||
|
||
// Ending Game | ||
if(miss <= 0) { | ||
clearText(); | ||
setMap(clear); | ||
clearInterval(obstacleUpdate); | ||
clearInterval(obstacleSpawn); | ||
addText("Game Over", { x : 5, y : 5}); | ||
addText(`Score: ${score}`, { x : 5, y : 7}); | ||
playTune(gameOverTune); | ||
gameOver = true; | ||
} | ||
timer++; | ||
}, 1000); | ||
|
||
onInput("a", () => { | ||
if(!gameOver) { | ||
getFirst(player).x -= 1; | ||
} | ||
}); | ||
|
||
onInput("d", () => { | ||
if(!gameOver) { | ||
getFirst(player).x += 1; | ||
} | ||
}); |
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,143 @@ | ||
/* | ||
title: fill the map! | ||
author: Ansh Kumar | ||
Instructions: | ||
Cover all the tiles to move to the next level | ||
You may face the difficulty of a button not working on the edges, don't worry this is some glitch because of the map! | ||
Enjoy! | ||
*/ | ||
|
||
|
||
const player = "p"; | ||
const green = "g"; | ||
const wall = "w"; | ||
|
||
setLegend( | ||
[ player, bitmap` | ||
.....000000..... | ||
....0......0.... | ||
....0.0..0.0.... | ||
....0......0.... | ||
....0..00..0.... | ||
....0......0.... | ||
.....000000..... | ||
.......0........ | ||
.......0........ | ||
.....00000...... | ||
.......0........ | ||
.......0........ | ||
.......0........ | ||
......0.0....... | ||
.....0...0...... | ||
....0.....0.....`], | ||
[ green, bitmap` | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444 | ||
4444444444444444`], | ||
[ wall, bitmap` | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
0000000000000000 | ||
`] | ||
) | ||
|
||
setSolids([player, green, wall]) | ||
|
||
let level = 0; | ||
|
||
const levels = [ | ||
map` | ||
pw.. | ||
.w.. | ||
....`, | ||
map` | ||
pw...... | ||
.w...w.. | ||
.www.... | ||
........ | ||
.......w | ||
..ww.... | ||
...w.... | ||
...w....`, | ||
map` | ||
pw... | ||
.w... | ||
.w... | ||
.w... | ||
.w... | ||
.w... | ||
.....`, | ||
] | ||
|
||
|
||
setMap(levels[level]) | ||
const p = getFirst(player); | ||
addSprite(p.x - p.dx, p.y - p.dy, green) | ||
|
||
onInput("w", _ => { | ||
getFirst(player).y -= 1; | ||
}) | ||
|
||
onInput("s", _ => { | ||
getFirst(player).y += 1; | ||
}) | ||
|
||
onInput("a", _ => { | ||
getFirst(player).x -= 1 | ||
}) | ||
|
||
onInput("d", _ => { | ||
getFirst(player).x += 1; | ||
}) | ||
|
||
onInput("j", _ => { | ||
setMap(levels[level]); | ||
const p = getFirst(player); | ||
addSprite(p.x, p.y, green) | ||
|
||
}) | ||
|
||
afterInput(_ => { | ||
const p = getFirst(player); | ||
if (p.dy !== 0 || p.dx !==0) { | ||
addSprite(p.x, p.y, green) | ||
} | ||
|
||
if (getAll(green).length === width() * height() - getAll(wall).length) { | ||
level++; | ||
if (level in levels) setMap(levels[level]) | ||
else addText("you win", { y: 5, color: color`5`}) | ||
const p = getFirst(player); | ||
addSprite(p.x, p.y, green) | ||
} | ||
}) |
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