mirror of
https://github.com/He4eT/DotDashPit.git
synced 2026-05-04 17:37:23 +00:00
game: fx prototype
This commit is contained in:
parent
f46112c2fe
commit
f18b4dff7a
1 changed files with 59 additions and 6 deletions
65
game.js
65
game.js
|
|
@ -47,6 +47,8 @@ let player = {
|
||||||
|
|
||||||
let enemies = []
|
let enemies = []
|
||||||
|
|
||||||
|
let effects = []
|
||||||
|
|
||||||
// Main Menu
|
// Main Menu
|
||||||
|
|
||||||
function mainMenu() {
|
function mainMenu() {
|
||||||
|
|
@ -88,7 +90,7 @@ function gameplay() {
|
||||||
|
|
||||||
drawInterface()
|
drawInterface()
|
||||||
drawArena()
|
drawArena()
|
||||||
// drawFX()
|
drawFX()
|
||||||
drawEnemies()
|
drawEnemies()
|
||||||
drawPlayer()
|
drawPlayer()
|
||||||
}
|
}
|
||||||
|
|
@ -112,6 +114,25 @@ function handleMoves() {
|
||||||
|
|
||||||
function handleMorse() {
|
function handleMorse() {
|
||||||
player.sprite = btn(BTN_B) ? 65 : 64
|
player.sprite = btn(BTN_B) ? 65 : 64
|
||||||
|
|
||||||
|
if (btnp(BTN_B, 100, 100)) {
|
||||||
|
if (enemies.length > 0) {
|
||||||
|
effects.unshift({
|
||||||
|
type: 'laser',
|
||||||
|
from: {
|
||||||
|
x: player.x,
|
||||||
|
y: player.y,
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
x: enemies[0].x[0],
|
||||||
|
y: enemies[0].y[0],
|
||||||
|
},
|
||||||
|
frameColors: [1, 2, 3, 4, 7, 7, 7, 6, 5, 4, 3, 2, 1],
|
||||||
|
})
|
||||||
|
enemies.shift()
|
||||||
|
trace(enemies.length)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enemies
|
// Enemies
|
||||||
|
|
@ -120,8 +141,8 @@ function spawn() {
|
||||||
if (enemies.length === 0) {
|
if (enemies.length === 0) {
|
||||||
enemies = [
|
enemies = [
|
||||||
{
|
{
|
||||||
x: [100],
|
x: [Math.random() * arena.right],
|
||||||
y: [50],
|
y: [Math.random() * arena.bottom],
|
||||||
type: 'zombie',
|
type: 'zombie',
|
||||||
dangerZone: 8,
|
dangerZone: 8,
|
||||||
},
|
},
|
||||||
|
|
@ -144,12 +165,21 @@ function checkColisions() {
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
||||||
|
function arenaToScreen({ x, y }) {
|
||||||
|
return {
|
||||||
|
x: x + arena.x,
|
||||||
|
y: y + arena.y,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function drawSprite(spriteIndex, x, y) {
|
function drawSprite(spriteIndex, x, y) {
|
||||||
const colorkey = 0
|
const colorkey = 0
|
||||||
|
const center = arenaToScreen({ x, y })
|
||||||
|
|
||||||
spr(
|
spr(
|
||||||
spriteIndex,
|
spriteIndex,
|
||||||
arena.x + x - arena.spriteHalfSize,
|
center.x - arena.spriteHalfSize,
|
||||||
arena.y + y - arena.spriteHalfSize,
|
center.y - arena.spriteHalfSize,
|
||||||
colorkey,
|
colorkey,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -162,6 +192,29 @@ function drawArena() {
|
||||||
map(0, 0, 30, 15)
|
map(0, 0, 30, 15)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function drawFX() {
|
||||||
|
const laser = (effect) => {
|
||||||
|
const color = effect.frameColors.shift()
|
||||||
|
const from = arenaToScreen(effect.from)
|
||||||
|
const to = arenaToScreen(effect.to)
|
||||||
|
|
||||||
|
line(from.x, from.y, to.x, to.y, color)
|
||||||
|
|
||||||
|
circ(from.x, from.y, effect.frameColors.length / 2, color)
|
||||||
|
|
||||||
|
circ(to.x, to.y, effect.frameColors.length / 2, color)
|
||||||
|
circb(to.x, to.y, effect.frameColors.length, color + 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
effects.forEach((effect) =>
|
||||||
|
({
|
||||||
|
laser,
|
||||||
|
})[effect.type](effect),
|
||||||
|
)
|
||||||
|
|
||||||
|
effects = effects.filter(({ frameColors }) => frameColors.length > 0)
|
||||||
|
}
|
||||||
|
|
||||||
function drawEnemies() {
|
function drawEnemies() {
|
||||||
enemies
|
enemies
|
||||||
.map((enemy) => [80, enemy.x[0], enemy.y[0]])
|
.map((enemy) => [80, enemy.x[0], enemy.y[0]])
|
||||||
|
|
@ -227,5 +280,5 @@ const [BTN_U, BTN_D, BTN_L, BTN_R, BTN_A, BTN_B, BTN_X, BTN_Y] = [
|
||||||
// </TRACKS>
|
// </TRACKS>
|
||||||
|
|
||||||
// <PALETTE>
|
// <PALETTE>
|
||||||
// 000:000000002b36073642586e75657b8383949693a1a1eee8d5b58900cb4b16dc322fd336826c71c4268bd22aa198859900
|
// 000:000000002b36073642586e75657b8383949693a1a1ffffffb58900cb4b16dc322fd336826c71c4268bd22aa198859900
|
||||||
// </PALETTE>
|
// </PALETTE>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue