game: enemy prototype

This commit is contained in:
He4eT 2025-06-05 11:15:25 +02:00
commit d15b43bf9b

114
game.js
View file

@ -16,6 +16,7 @@ function TIC() {
const gameStages = { const gameStages = {
mainMenu, mainMenu,
gameover,
gameplay, gameplay,
} }
@ -38,12 +39,14 @@ let arena = {
} }
let player = { let player = {
sprite: 1, sprite: 64,
speed: 1, speed: 1,
x: 0, x: 0,
y: 0, y: 0,
} }
let enemies = []
// Main Menu // Main Menu
function mainMenu() { function mainMenu() {
@ -60,24 +63,50 @@ function mainMenu() {
print(instruction, 12, 30, 4) print(instruction, 12, 30, 4)
} }
// Gameover
function gameover() {
const title = 'Game Over'
cls(0)
drawEnemies()
drawPlayer()
print(title, 12, 12, 10, false, 2)
}
// Gameplay // Gameplay
function gameplay() { function gameplay() {
// chackColisions() checkColisions()
handleMoves() handleMoves()
handleMorse() handleMorse()
// spawn() spawn()
// moveEnemies() // moveEnemies()
drawInterface() drawInterface()
drawArena() drawArena()
// drawFX() // drawFX()
// drawEnemies() drawEnemies()
drawPlayer() drawPlayer()
} }
function checkColisions() {
if (
enemies
.map((enemy) => [
enemy,
Math.hypot(player.x - enemy.x[0], player.y - enemy.y[0]),
])
.some(([enemy, distance]) => distance < enemy.dangerZone)
) {
cls(10)
currentStage = 'gameover'
}
}
function handleMoves() { function handleMoves() {
player.speed = btn(BTN_A) ? 2 : 1 player.speed = btn(BTN_A) ? 2 : 1
@ -88,7 +117,20 @@ function handleMoves() {
} }
function handleMorse() { function handleMorse() {
player.sprite = btn(BTN_B) ? 17 : 1 player.sprite = btn(BTN_B) ? 65 : 64
}
function spawn() {
if (enemies.length === 0) {
enemies = [
{
x: [100],
y: [50],
type: 'zombie',
dangerZone: 8,
},
]
}
} }
function drawInterface() { function drawInterface() {
@ -99,6 +141,17 @@ function drawArena() {
map(0, 0, 30, 15) map(0, 0, 30, 15)
} }
function drawEnemies() {
enemies.forEach((enemy) => {
spr(
80,
interface.arenaX + enemy.x[0] - interface.spriteHalfSize,
interface.arenaY + enemy.y[0] - interface.spriteHalfSize,
0,
)
})
}
function drawPlayer() { function drawPlayer() {
spr( spr(
player.sprite, player.sprite,
@ -116,33 +169,36 @@ const [BTN_U, BTN_D, BTN_L, BTN_R, BTN_A, BTN_B, BTN_X, BTN_Y] = [
] ]
// <TILES> // <TILES>
// 001:8800088080000080008880000088800000888000800000808800088000000000 // 001:1111110012222100123321001233210012222100111111000000000000000000
// 002:0000000000000000000000000000000000000000000001110000012200000123 // 002:1111111112222221123333211233332112222221111111110000000000000000
// 003:0000000000000000000000000000000000000000111111112222222233333333 // 016:0000000000000000000000000000000000000000000001110000012200000123
// 004:0000000000000000000000000000000000000000111000002210000032100000 // 017:0000000000000000000000000000000000000000111111112222222233333333
// 017:0000000008808800080008000008000008000800088088000000000000000000 // 018:0000000000000000000000000000000000000000111000002210000032100000
// 018:0000012300000123000001230000012300000123000001230000012300000123 // 032:0000012300000123000001230000012300000123000001230000012300000123
// 019:2111111111111111111111111111111111111111111111111111111111111111 // 033:2111111111111111111111111111111111111111111111111111111111111111
// 020:3210000032100000321000003210000032100000321000003210000032100000 // 034:3210000032100000321000003210000032100000321000003210000032100000
// 034:0000012300000122000001110000000000000000000000000000000000000000 // 048:0000012300000122000001110000000000000000000000000000000000000000
// 035:3333333322222222111111110000000000000000000000000000000000000000 // 049:3333333322222222111111110000000000000000000000000000000000000000
// 036:3210000022100000111000000000000000000000000000000000000000000000 // 050:3210000022100000111000000000000000000000000000000000000000000000
// 064:8800088080000080008880000088800000888000800000808800088000000000
// 065:0000000008808800080008000008000008000800088088000000000000000000
// 080:aaaaaaa0aaaaaaa0aa000aa0aa000aa0aa000aa0aaaaaaa0aaaaaaa000000000
// </TILES> // </TILES>
// <MAP> // <MAP>
// 000:203030303030303030303030303030303030303030303030303030303040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 000:011111111111111111111111111111111111111111111111111111111121000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 001:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 001:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 002:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 002:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 003:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 003:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 004:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 004:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 005:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 005:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 006:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 006:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 007:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 007:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 008:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 008:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 009:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 009:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 010:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 010:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 011:213131313131313131313131313131313131313131313131313131313141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 011:021212121212121212121212121212121212121212121212121212121222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// 012:223232323232323232323232323232323232323232323232323232323242000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 012:031313131313131313131313131313131313131313131313131313131323000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
// </MAP> // </MAP>
// <WAVES> // <WAVES>