Death cone death type
This commit is contained in:
1 parent
6dab8504fe
commit
2928336abf
2 files changed
+59
-5
No files matched your search
@@ -5,7 +5,7 @@ import {clamp, deg2rad, parable, randomInt, vec, wrap} from './math.js';
|
||||
import {createSky} from './sky.js';
|
||||
import {audio, createOsc, playTickSound} from './sound.js';
|
||||
import {collapseTerrain, createTerrain, isTerrain, landHeight, closestLand} from './terrain.js';
|
||||
import {WEAPON_TYPES, EXPLOSION_TYPES} from './weapons.js';
|
||||
import {WEAPON_TYPES, EXPLOSION_TYPES, DEATH_SPECS} from './weapons.js';
|
||||
import {sample} from './utils.js';
|
||||
|
||||
|
||||
@@ -145,8 +145,9 @@ function update() {
|
||||
if (!dyingPlayer) {state = 'end-turn'; return}
|
||||
|
||||
const {x, y} = dyingPlayer;
|
||||
const explosionType = sample(Object.values(EXPLOSION_TYPES));
|
||||
explosion = explosionType.create({r:25}, x, y);
|
||||
const explosionSpec = sample(DEATH_SPECS);
|
||||
const explosionType = EXPLOSION_TYPES[explosionSpec.type];
|
||||
explosion = explosionType.create(explosionSpec, x, y);
|
||||
dyingPlayer.dead = true;
|
||||
state = 'explosion';
|
||||
}
|
||||
|
||||
+55
-2
@@ -1,6 +1,6 @@
|
||||
import {drawCircle} from './gfx.js';
|
||||
import {drawCircle, plot} from './gfx.js';
|
||||
import {clipTerrain} from './terrain.js';
|
||||
import {within, cycle} from './math.js';
|
||||
import {within, cycle, random, randomInt} from './math.js';
|
||||
import {createOsc, audio} from './sound.js';
|
||||
|
||||
export function drawExplosion(ctx, x, y, r) {
|
||||
@@ -17,6 +17,12 @@ export const WEAPON_TYPES = [
|
||||
{id:'large-dirt', name:'Ton of Dirt', explosion:{type:'dirt', r:75}},
|
||||
];
|
||||
|
||||
export const DEATH_SPECS = [
|
||||
{type: 'blast', r: 35},
|
||||
{type: 'dirt', r: 50},
|
||||
{type: 'dirtCone', r: 100},
|
||||
];
|
||||
|
||||
export const EXPLOSION_TYPES = {
|
||||
blast: {
|
||||
create(spec, x, y) {
|
||||
@@ -75,4 +81,51 @@ export const EXPLOSION_TYPES = {
|
||||
},
|
||||
damage(explosion, player) {}
|
||||
},
|
||||
dirtCone: {
|
||||
create(spec, x, y) {
|
||||
const {r} = spec;
|
||||
const pattern = [];
|
||||
const osc = createOsc();
|
||||
osc.start();
|
||||
return {type:'dirtCone', x, y, r, cr:0, osc, pattern};
|
||||
},
|
||||
stop(explosion) {
|
||||
const {osc} = explosion;
|
||||
osc.stop();
|
||||
},
|
||||
update(explosion) {
|
||||
return ++explosion.cr < explosion.r;
|
||||
},
|
||||
draw(explosion, foreground) {
|
||||
const {x, y, cr, osc, pattern} = explosion;
|
||||
|
||||
let row = [];
|
||||
for (let cx=0; cx<=1+cr*2; cx++) {
|
||||
row.push(randomInt(0, 3) === 0);
|
||||
}
|
||||
pattern.push(row);
|
||||
|
||||
for (let cy=0; cy<pattern.length; cy++) {
|
||||
const row = pattern[cy];
|
||||
for (let cx=0; cx<row.length; cx++) {
|
||||
if (row[cx]) plot(foreground, x-cy+cx, y-cy, 'burlywood');
|
||||
}
|
||||
}
|
||||
|
||||
const f = explosion.cr % 2 === 0 ? 220 + explosion.cr : 0;
|
||||
osc.frequency.setValueAtTime(f, audio.currentTime);
|
||||
osc.frequency.setValueAtTime(0, audio.currentTime+0.1);
|
||||
},
|
||||
clip(explosion, terrain) {
|
||||
const {x, y, pattern} = explosion;
|
||||
|
||||
for (let cy=0; cy<pattern.length; cy++) {
|
||||
const row = pattern[cy];
|
||||
for (let cx=0; cx<row.length; cx++) {
|
||||
if (row[cx]) plot(terrain, x-cy+cx, y-cy, 'burlywood');
|
||||
}
|
||||
}
|
||||
},
|
||||
damage(explosion, player) {}
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user