Skip to content

Commit

Permalink
[Sprig App] dot10 (#2647)
Browse files Browse the repository at this point in the history
* Sprig App - dot10

* edit metadata

---------

Co-authored-by: Mare Cosmin <[email protected]>
  • Loading branch information
ashfelloff and Cosmin-Mare authored Nov 26, 2024
1 parent d99acdf commit 28782de
Showing 1 changed file with 273 additions and 0 deletions.
273 changes: 273 additions & 0 deletions games/dot10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
/*
@title: dot10
@author: ashfelloff
@tags: []
@addedOn: 2024-11-26
*/

const player = "p";
const wall = "w";
const goal = "g";

setLegend(
[ player, 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`],
[ goal, bitmap`
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH
HHHHHHHHHHHHHHHH`]
);

const levels = [
`
wwwwwwwwww
p....w...w
w.ww.w.w.w
w....w.w.w
w.ww.w.w.w
w....w.w.w
w.ww.w.w.w
w....w.w.w
w.ww.w.w.w
w.......gw`,

`
wwwwwwwwww
p..w.....w
w.wwwwww.w
w....w...w
www.www.ww
w...w...ww
w.w.w.w..w
w.w...ww.w
w.wwww...w
w.......gw`,

`
wwwwwwwwww
p...w....w
www.w.ww.w
w...w.w..w
w.www.ww.w
w.w...w..w
w.w.www.ww
w...w....w
www.w.ww.w
w.......gw`,

`
wwwwwwwwww
p.w......w
w.w.wwww.w
w.w.w....w
w.w.w.ww.w
w...w..w.w
www.ww.w.w
w.......ww
w.wwwww..w
w.......gw`,

`
wwwwwwwwww
p........w
wwwwwwww.w
w........w
w.wwwwww.w
w.w....w.w
w.w.ww.w.w
w...ww...w
wwwwwwww.w
w.......gw`,

`
wwwwwwwwww
p.......ww
w.w.ww..ww
w.w..w...w
w.ww.w.w.w
w....w.w.w
w.wwww.w.w
w.w....w.w
w.w.wwww.w
w.......gw`,

`
wwwwwwwwww
p..www...w
w.....ww.w
www.w....w
w...wwww.w
w.w......w
w.wwwwww.w
w.......ww
w.wwwww..w
w.......gw`,

`
wwwwwwwwww
p........w
wwwwwwww.w
w........w
w.wwwwwwww
w........w
wwwwwwww.w
w........w
w.wwwwwwww
w.......gw`,

`
wwwwwwwwww
p.......ww
w.wwwww..w
w.....ww.w
www.w....w
w...wwww.w
w.w......w
w.wwwwww.w
w........w
www....wgw`,

`
wwwwwwwwww
p........w
w.wwwwww.w
w.w....w.w
w.w.ww.w.w
w.w.ww.w.w
w.w....w.w
w.wwww.w.w
w......w.w
wwwwww.wgw`
];

let currentLevel = 0;
let timeLeft = 30;
let gameOver = false;

setMap(levels[0]);
setSolids([wall]);

function canMove(x, y) {
return !getTile(x, y).some(t => t.type === wall);
}

function startLevel(levelNum) {
setMap(levels[levelNum]);
timeLeft = 30;
gameOver = false;
clearText();
addText(`Level ${levelNum + 1}`, { y: 1 });
addText(`Time: ${timeLeft}`, { y: 2 });
}

onInput("d", () => {
if (!gameOver) {
const p = getFirst(player);
if (p && p.x < 9 && canMove(p.x + 1, p.y)) {
p.x += 1;
}
}
});

onInput("a", () => {
if (!gameOver) {
const p = getFirst(player);
if (p && p.x > 0 && canMove(p.x - 1, p.y)) {
p.x -= 1;
}
}
});

onInput("w", () => {
if (!gameOver) {
const p = getFirst(player);
if (p && p.y > 0 && canMove(p.x, p.y - 1)) {
p.y -= 1;
}
}
});

onInput("s", () => {
if (!gameOver) {
const p = getFirst(player);
if (p && p.y < 9 && canMove(p.x, p.y + 1)) {
p.y += 1;
}
}
});

afterInput(() => {
const p = getFirst(player);
if (!p) return;

if (getTile(p.x, p.y).some(t => t.type === goal)) {
if (currentLevel < 9) {
currentLevel++;
startLevel(currentLevel);
} else {
gameOver = true;
clearText();
addText("You Beat All Levels!", { y: 5 });
}
}
});

setInterval(() => {
if (!gameOver) {
timeLeft -= 1;
clearText();
addText(`Level ${currentLevel + 1}`, { y: 1 });
addText(`Time: ${timeLeft}`, { y: 2 });

if (timeLeft <= 0) {
gameOver = true;
clearText();
addText("Time's Up!", { y: 5 });
}
}
}, 1000);

0 comments on commit 28782de

Please sign in to comment.