mirror of
https://github.com/He4eT/DotDashPit.git
synced 2026-05-05 01:47:22 +00:00
game: naming
This commit is contained in:
parent
43e6198e6e
commit
3dbf1cc498
1 changed files with 22 additions and 22 deletions
44
game.js
44
game.js
|
|
@ -116,7 +116,7 @@ const playerStates = {
|
||||||
/** @type {Enemy[]} */
|
/** @type {Enemy[]} */
|
||||||
let enemies = []
|
let enemies = []
|
||||||
|
|
||||||
const enemyTypes = {
|
const enemyBlueprints = {
|
||||||
point: {
|
point: {
|
||||||
sprite: 272,
|
sprite: 272,
|
||||||
spawnDistance: 20,
|
spawnDistance: 20,
|
||||||
|
|
@ -232,7 +232,7 @@ const enemyTypes = {
|
||||||
/** @type {Effect[]} */
|
/** @type {Effect[]} */
|
||||||
let effects = []
|
let effects = []
|
||||||
|
|
||||||
const effectHandlers = {
|
const effectRenderers = {
|
||||||
flash: ({ frames }) => {
|
flash: ({ frames }) => {
|
||||||
const color = frames.shift()
|
const color = frames.shift()
|
||||||
cls(color)
|
cls(color)
|
||||||
|
|
@ -336,7 +336,7 @@ function gameScreen() {
|
||||||
drawFX()
|
drawFX()
|
||||||
drawEnemies()
|
drawEnemies()
|
||||||
drawPlayer()
|
drawPlayer()
|
||||||
drawLetters()
|
drawEnemyLetters()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Arena */
|
/* Arena */
|
||||||
|
|
@ -484,12 +484,12 @@ function spawnEnemies() {
|
||||||
const getType = (wave) => {
|
const getType = (wave) => {
|
||||||
if (wave <= 2) return 'point'
|
if (wave <= 2) return 'point'
|
||||||
|
|
||||||
const availableTypes = Object.keys(enemyTypes)
|
const availableTypes = Object.keys(enemyBlueprints)
|
||||||
return availableTypes[rnd(0, availableTypes.length - 1)]
|
return availableTypes[rnd(0, availableTypes.length - 1)]
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSpawnPosition = (type) => {
|
const getSpawnPosition = (type) => {
|
||||||
const minDistance = enemyTypes[type].spawnDistance
|
const minDistance = enemyBlueprints[type].spawnDistance
|
||||||
const b = 4 * arena.spriteHalfSize
|
const b = 4 * arena.spriteHalfSize
|
||||||
let x, y, distance
|
let x, y, distance
|
||||||
|
|
||||||
|
|
@ -506,11 +506,11 @@ function spawnEnemies() {
|
||||||
const type = getType(arena.wave)
|
const type = getType(arena.wave)
|
||||||
return {
|
return {
|
||||||
type,
|
type,
|
||||||
speed: enemyTypes[type].maxSpeed * Math.random(),
|
speed: enemyBlueprints[type].maxSpeed * Math.random(),
|
||||||
value: enemyTypes[type].value,
|
value: enemyBlueprints[type].value,
|
||||||
letter: alphabet[rnd(0, alphabet.length - 1)],
|
letter: alphabet[rnd(0, alphabet.length - 1)],
|
||||||
positions: [getSpawnPosition(type), getSpawnPosition(type)],
|
positions: [getSpawnPosition(type), getSpawnPosition(type)],
|
||||||
dangerZone: enemyTypes[type].dangerZone,
|
dangerZone: enemyBlueprints[type].dangerZone,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -525,7 +525,7 @@ function spawnEnemies() {
|
||||||
|
|
||||||
function moveEnemies() {
|
function moveEnemies() {
|
||||||
enemies.forEach((enemy) => {
|
enemies.forEach((enemy) => {
|
||||||
enemyTypes[enemy.type].behaviour(enemy)
|
enemyBlueprints[enemy.type].behaviour(enemy)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -569,24 +569,24 @@ function checkCollisions() {
|
||||||
function drawEnemies() {
|
function drawEnemies() {
|
||||||
enemies
|
enemies
|
||||||
.map((enemy) => [
|
.map((enemy) => [
|
||||||
enemyTypes[enemy.type].sprite,
|
enemyBlueprints[enemy.type].sprite,
|
||||||
enemy.positions[0].x,
|
enemy.positions[0].x,
|
||||||
enemy.positions[0].y,
|
enemy.positions[0].y,
|
||||||
])
|
])
|
||||||
.forEach(([sprite, x, y]) => drawSprite(sprite, x, y))
|
.forEach(([sprite, x, y]) => drawSprite(sprite, x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawLetters() {
|
function drawEnemyLetters() {
|
||||||
enemies.forEach((enemy) => {
|
enemies.forEach((enemy) => {
|
||||||
const enemyPosition = enemy.positions[0]
|
const enemyPosition = enemy.positions[0]
|
||||||
const d = getDirection(enemyPosition, player.position)
|
const d = getDirection(player.position, enemyPosition)
|
||||||
|
|
||||||
const letterPos = {
|
const letterPos = {
|
||||||
x: enemyPosition.x - d.x * 18,
|
x: enemyPosition.x + d.x * 18,
|
||||||
y: enemyPosition.y - d.y * 18,
|
y: enemyPosition.y + d.y * 18,
|
||||||
}
|
}
|
||||||
|
|
||||||
const screenPos = arenaToScreen(letterPos)
|
const screenPos = worldToScreen(letterPos)
|
||||||
|
|
||||||
rect(screenPos.x - 7, screenPos.y - 7, 16, 16, 4)
|
rect(screenPos.x - 7, screenPos.y - 7, 16, 16, 4)
|
||||||
rectb(screenPos.x - 7, screenPos.y - 7, 16, 16, 3)
|
rectb(screenPos.x - 7, screenPos.y - 7, 16, 16, 3)
|
||||||
|
|
@ -614,10 +614,10 @@ function drawFX() {
|
||||||
effects
|
effects
|
||||||
.map((effect) => ({
|
.map((effect) => ({
|
||||||
...effect,
|
...effect,
|
||||||
from: arenaToScreen(effect.from ?? {}),
|
from: worldToScreen(effect.from ?? {}),
|
||||||
to: arenaToScreen(effect.to ?? {}),
|
to: worldToScreen(effect.to ?? {}),
|
||||||
}))
|
}))
|
||||||
.forEach((effect) => effectHandlers[effect.type](effect))
|
.forEach((effect) => effectRenderers[effect.type](effect))
|
||||||
|
|
||||||
effects = effects.filter(({ frames }) => frames.length > 0)
|
effects = effects.filter(({ frames }) => frames.length > 0)
|
||||||
}
|
}
|
||||||
|
|
@ -651,7 +651,7 @@ function getDirection(from, to) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function arenaToScreen({ x, y }) {
|
function worldToScreen({ x, y }) {
|
||||||
return {
|
return {
|
||||||
x: Math.floor(x + arena.screenPosition.x),
|
x: Math.floor(x + arena.screenPosition.x),
|
||||||
y: Math.floor(y + arena.screenPosition.y),
|
y: Math.floor(y + arena.screenPosition.y),
|
||||||
|
|
@ -660,7 +660,7 @@ function arenaToScreen({ x, y }) {
|
||||||
|
|
||||||
function drawSprite(spriteIndex, x, y) {
|
function drawSprite(spriteIndex, x, y) {
|
||||||
const colorkey = 0
|
const colorkey = 0
|
||||||
const center = arenaToScreen({ x, y })
|
const center = worldToScreen({ x, y })
|
||||||
|
|
||||||
spr(
|
spr(
|
||||||
spriteIndex,
|
spriteIndex,
|
||||||
|
|
@ -727,7 +727,7 @@ const BTN_Y = 7
|
||||||
* }} Player
|
* }} Player
|
||||||
*
|
*
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* type: keyof typeof enemyTypes,
|
* type: keyof typeof enemyBlueprints,
|
||||||
* speed: number,
|
* speed: number,
|
||||||
* positions: Point[],
|
* positions: Point[],
|
||||||
* letter: string,
|
* letter: string,
|
||||||
|
|
@ -736,7 +736,7 @@ const BTN_Y = 7
|
||||||
* }} Enemy
|
* }} Enemy
|
||||||
*
|
*
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* type: keyof typeof effectHandlers
|
* type: keyof typeof effectRenderers
|
||||||
* from: Point,
|
* from: Point,
|
||||||
* to: Point,
|
* to: Point,
|
||||||
* frames: number[],
|
* frames: number[],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue