Cosmetic tweaks
This commit is contained in:
1 parent
81e7848c14
commit
bc38fee8a1
1 file changed
+13
-12
@@ -5,7 +5,7 @@ import {wrap, clamp, parable, deg2rad, vec} from './math.js';
|
|||||||
import {drawExplosion, WEAPONS} from './weapons.js';
|
import {drawExplosion, WEAPONS} from './weapons.js';
|
||||||
import {createOsc, audio} from './sound.js';
|
import {createOsc, audio} from './sound.js';
|
||||||
|
|
||||||
const W = 384; const H = 240; const Z = 3;
|
const W = 640; const H = 400; const Z = 2;
|
||||||
|
|
||||||
let state = 'aim';
|
let state = 'aim';
|
||||||
const players = [];
|
const players = [];
|
||||||
@@ -26,12 +26,13 @@ const terrain = createTerrain(W, H);
|
|||||||
const projectiles = createCanvas(W, H);
|
const projectiles = createCanvas(W, H);
|
||||||
|
|
||||||
// Init players
|
// Init players
|
||||||
players.push({x:50, y:landHeight(terrain, 50), a:180-45, p:300, c:'tomato', weapon:WEAPONS[0]});
|
let i=0;
|
||||||
players.push({x:100, y:landHeight(terrain, 100), a:45, p:300, c:'royalblue', weapon:WEAPONS[1]});
|
for (let color of ['tomato', 'royalblue', 'greenyellow', 'gold', 'hotpink', 'orchid']) {
|
||||||
players.push({x:180, y:landHeight(terrain, 180), a:45, p:300, c:'greenyellow', weapon:WEAPONS[0]});
|
const x = Math.round(50 + (W-100) / 5 * i);
|
||||||
players.push({x:260, y:landHeight(terrain, 260), a:45, p:300, c:'gold', weapon:WEAPONS[1]});
|
const a = x > W/2 ? 45 : 180-45;
|
||||||
players.push({x:290, y:landHeight(terrain, 290), a:45, p:300, c:'hotpink', weapon:WEAPONS[0]});
|
players.push({x, y:landHeight(terrain, x), a, p:300, c:color, weapon:WEAPONS[i%2]});
|
||||||
players.push({x:340, y:landHeight(terrain, 340), a:45, p:300, c:'orchid', weapon:WEAPONS[1]});
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
if (state === 'aim') {
|
if (state === 'aim') {
|
||||||
@@ -48,8 +49,7 @@ function update() {
|
|||||||
player.p = clamp(100, p -5, 1000);
|
player.p = clamp(100, p -5, 1000);
|
||||||
} else if (key(' ')) {
|
} else if (key(' ')) {
|
||||||
state = 'fire';
|
state = 'fire';
|
||||||
fadeProjectiles();
|
const [px, py] = vec(x, y-3, a+180, 5);
|
||||||
const [px, py] = vec(x, y-3, a+180, 3);
|
|
||||||
projectile = prevProjectile = {
|
projectile = prevProjectile = {
|
||||||
osc: createOsc(),
|
osc: createOsc(),
|
||||||
player: player,
|
player: player,
|
||||||
@@ -63,7 +63,8 @@ function update() {
|
|||||||
|
|
||||||
else if (state === 'fire') {
|
else if (state === 'fire') {
|
||||||
prevProjectile = {...projectile};
|
prevProjectile = {...projectile};
|
||||||
for (let i=0; i<20; i++) {
|
fadeProjectiles(1);
|
||||||
|
for (let i=0; i<30; i++) {
|
||||||
const {weapon, ox, oy, a, p, t} = projectile;
|
const {weapon, ox, oy, a, p, t} = projectile;
|
||||||
const [x, y] = parable(t, ox, oy, deg2rad(180+a), p/10, 9.8);
|
const [x, y] = parable(t, ox, oy, deg2rad(180+a), p/10, 9.8);
|
||||||
const f = 200 + 10 * (H-y);
|
const f = 200 + 10 * (H-y);
|
||||||
@@ -117,9 +118,9 @@ function drawProjectile() {
|
|||||||
drawLine(projectiles, prevProjectile.x, prevProjectile.y, x, y, player.c);
|
drawLine(projectiles, prevProjectile.x, prevProjectile.y, x, y, player.c);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fadeProjectiles() {
|
function fadeProjectiles(amount) {
|
||||||
const imageData = projectiles.getImageData(0, 0, W, H);
|
const imageData = projectiles.getImageData(0, 0, W, H);
|
||||||
for (let i=0; i<imageData.data.length; i+=4) imageData.data[i+3] -= 30;
|
for (let i=0; i<imageData.data.length; i+=4) imageData.data[i+3] -= amount;
|
||||||
projectiles.clearRect(0, 0, W, H);
|
projectiles.clearRect(0, 0, W, H);
|
||||||
projectiles.putImageData(imageData, 0, 0);
|
projectiles.putImageData(imageData, 0, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user