Created
October 11, 2023 01:10
-
-
Save JosiasAurel/21dccf7648104aeb985d4af44e6df9a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
First time? Check out the tutorial game: | |
https://sprig.hackclub.com/gallery/getting_started | |
*/ | |
const player = "p" | |
const wall = "w" | |
const goal = "g" | |
setLegend( | |
[ player, bitmap` | |
................ | |
................ | |
................ | |
................ | |
.....33333...... | |
.....33333...... | |
.....33333...... | |
.....33333...... | |
.....33333...... | |
................ | |
................ | |
................ | |
................ | |
................ | |
................ | |
................` ], | |
[ wall, bitmap` | |
................ | |
................ | |
................ | |
.....00000000... | |
.....00000000... | |
.....00000000... | |
.....00000000... | |
.....00000000... | |
.....00000000... | |
.....00000000... | |
.....00000000... | |
................ | |
................ | |
................ | |
................ | |
................`], | |
[ goal, bitmap` | |
................ | |
................ | |
................ | |
..4.4.4.4....... | |
................ | |
..4.4.4.4....... | |
................ | |
..4.4.4.4....... | |
................ | |
..4.4.4.4....... | |
................ | |
................ | |
................ | |
................ | |
................ | |
................`], | |
) | |
setSolids([player, wall]) | |
let level = 0 | |
const levels = [ | |
`........... | |
..wwwwwwww. | |
..w......w. | |
..w......w. | |
..w......w. | |
..wp.....w. | |
..wwww...w. | |
..w......w. | |
..w.....gw. | |
..wwwwwwww. | |
...........` | |
]; | |
function rotate90Clockwise(a) { | |
let N = a.length; | |
// Traverse each cycle | |
for (let i = 0; i < N / 2; i++) { | |
for (let j = i; j < N - i - 1; j++) { | |
// Swap elements of each cycle | |
// in clockwise direction | |
let temp = a[i][j]; | |
a[i][j] = a[N - 1 - j][i]; | |
a[N - 1 - j][i] = a[N - 1 - i][N - 1 - j]; | |
a[N - 1 - i][N - 1 - j] = a[j][N - 1 - i]; | |
a[j][N - 1 - i] = temp; | |
} | |
} | |
} | |
function rotate90CounterClockwise(a) { | |
let N = a.length; | |
// Traverse each cycle | |
for (let i = 0; i < N / 2; i++) { | |
for (let j = i; j < N - i - 1; j++) { | |
// Swap elements of each cycle | |
// in clockwise direction | |
let temp = a[j][N - 1 - i]; | |
a[j][N - 1 - i] = a[N - 1 - i][N - 1 - j]; | |
a[N - 1 - i][N - 1 - j] = a[N - 1 - j][i]; | |
a[N - 1 - j][i] = a[i][j]; | |
a[i][j] = temp; | |
} | |
} | |
} | |
let currentLevel = levels[level]; | |
setMap(map`${currentLevel}`); | |
let playerPosition = { x: 0, y: 0 }; | |
setPushables({ | |
[ player ]: [] | |
}) | |
onInput("s", () => { | |
getFirst(player).y += 1; | |
}) | |
onInput("w", () => { | |
getFirst(player).y -= 1; | |
}) | |
onInput("d", () => { | |
let result = currentLevel.split("\n").map(i => i.split("")); | |
rotate90Clockwise(result); | |
currentLevel = result.map(i => i.join("")).join("\n"); | |
setMap(map`${currentLevel}`); | |
}) | |
onInput("a", () => { | |
let result = currentLevel.split("\n").map(i => i.split("")); | |
rotate90CounterClockwise(result); | |
currentLevel = result.map(i => i.join("")).join("\n"); | |
setMap(map`${currentLevel}`); | |
}) | |
afterInput(() => { | |
// the player coordinates | |
const p = getFirst(player); | |
playerPosition = { x: p.x, y: p.y }; | |
const { x, y } = playerPosition; | |
console.log("doesn't really do anything that cool"); | |
}) | |
// gravity stuff | |
setInterval(() => { | |
const { x, y } = getFirst(player); | |
getFirst(player).y += 1; | |
const pp = getFirst(player); | |
playerPosition = { x: pp.x, y: pp.y }; | |
let levelCopy = currentLevel.split("\n").map(i => i.split("")); | |
levelCopy[playerPosition.x][playerPosition.y] = 'p'; | |
currentLevel = levelCopy.map(i => i.join("")).join("\n"); | |
/* | |
if (pp.y - y != 0) { | |
let levelCopy = currentLevel.split("\n").map(i => i.split("")); | |
levelCopy[x][y] = '.'; | |
levelCopy[pp.x][pp.y] = 'p'; | |
currentLevel = levelCopy.map(i => i.join("")).join("\n"); | |
} | |
*/ | |
addText(`${pp.x},${pp.y}`, { x: 3, y: 2, color: color`3`}) | |
/* | |
const pp = getFirst(player); | |
if (getFirst(player).y != playerPosition.y) { | |
playerPosition = { x: pp.x, y: pp.y }; | |
} else { playerPosition = { x: pp.x, y: pp.y }; } | |
let levelCopy = currentLevel.split("\n").map(i => i.split("")); | |
levelCopy[playerPosition.x][playerPosition.y] = 'p'; | |
currentLevel = levelCopy.map(i => i.join("")).join("\n"); | |
*/ | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment