Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ansh3108 committed Mar 14, 2023
1 parent 7aa0c5f commit 9d47033
Showing 1 changed file with 143 additions and 0 deletions.
143 changes: 143 additions & 0 deletions games/fill_the_map.js
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)
}
})

0 comments on commit 9d47033

Please sign in to comment.