This commit is contained in:
+4
-4
@@ -29,11 +29,11 @@ const CONFIG = {
|
|||||||
gameOverDelay: 10000,
|
gameOverDelay: 10000,
|
||||||
},
|
},
|
||||||
speed: {
|
speed: {
|
||||||
slowEnemyCrossTimeStart: 120,
|
slowEnemyCrossTimeStart: 240,
|
||||||
slowEnemyCrossTimeCap: 20,
|
slowEnemyCrossTimeCap: 30,
|
||||||
slowEnemyCrossTimeCapWave: 50,
|
slowEnemyCrossTimeCapWave: 50,
|
||||||
fastEnemyCrossTimeStart: 60,
|
fastEnemyCrossTimeStart: 120,
|
||||||
fastEnemyCrossTimeCap: 10,
|
fastEnemyCrossTimeCap: 15,
|
||||||
fastEnemyCrossTimeCapWave: 50,
|
fastEnemyCrossTimeCapWave: 50,
|
||||||
bossCrossTime: 60,
|
bossCrossTime: 60,
|
||||||
projectileCrossTime: 0.43,
|
projectileCrossTime: 0.43,
|
||||||
|
|||||||
+3
-3
@@ -112,9 +112,9 @@ class Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
this.y += this.speed;
|
this.y += this.speed * frameFactor;
|
||||||
this.pulse += 0.05;
|
this.pulse += 0.05 * frameFactor;
|
||||||
if (this.flashTimer > 0) this.flashTimer--;
|
if (this.flashTimer > 0) this.flashTimer -= frameFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
|
|||||||
+6
-5
@@ -230,7 +230,7 @@ function update() {
|
|||||||
if (gameState !== "playing") return;
|
if (gameState !== "playing") return;
|
||||||
|
|
||||||
if (wavePauseActive) {
|
if (wavePauseActive) {
|
||||||
wavePauseTimer--;
|
wavePauseTimer -= frameFactor;
|
||||||
if (wavePauseTimer <= 0) {
|
if (wavePauseTimer <= 0) {
|
||||||
wavePauseActive = false;
|
wavePauseActive = false;
|
||||||
waveEnemiesLeft = getEnemiesPerWave();
|
waveEnemiesLeft = getEnemiesPerWave();
|
||||||
@@ -239,7 +239,7 @@ function update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (waveEnemiesLeft > 0) {
|
} else if (waveEnemiesLeft > 0) {
|
||||||
spawnTimer++;
|
spawnTimer += frameFactor;
|
||||||
const spawnInterval = CONFIG.game.waveInterval / getEnemiesPerWave();
|
const spawnInterval = CONFIG.game.waveInterval / getEnemiesPerWave();
|
||||||
if (spawnTimer >= spawnInterval) {
|
if (spawnTimer >= spawnInterval) {
|
||||||
spawnEnemy();
|
spawnEnemy();
|
||||||
@@ -248,7 +248,7 @@ function update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
waveTimer++;
|
waveTimer += frameFactor;
|
||||||
if (waveTimer >= CONFIG.game.waveInterval && !wavePauseActive && waveEnemiesLeft <= 0) {
|
if (waveTimer >= CONFIG.game.waveInterval && !wavePauseActive && waveEnemiesLeft <= 0) {
|
||||||
wave++;
|
wave++;
|
||||||
waveTimer = 0;
|
waveTimer = 0;
|
||||||
@@ -283,7 +283,7 @@ function update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shakeTimer > 0) {
|
if (shakeTimer > 0) {
|
||||||
shakeTimer--;
|
shakeTimer -= frameFactor;
|
||||||
shakeAmount *= 0.9;
|
shakeAmount *= 0.9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,7 +329,8 @@ function draw() {
|
|||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
function loop() {
|
function loop(timestamp) {
|
||||||
|
calcDt(timestamp);
|
||||||
update();
|
update();
|
||||||
draw();
|
draw();
|
||||||
if (gameLoopStarted) {
|
if (gameLoopStarted) {
|
||||||
|
|||||||
+10
-7
@@ -83,27 +83,30 @@ function runIntro() {
|
|||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
function introLoop() {
|
function introLoop(timestamp) {
|
||||||
frame++;
|
calcDt(timestamp);
|
||||||
|
const prevFrame = Math.floor(frame);
|
||||||
|
frame += frameFactor;
|
||||||
|
const curFrame = Math.floor(frame);
|
||||||
|
|
||||||
if (frame <= I.fadeInFrames) {
|
if (frame <= I.fadeInFrames) {
|
||||||
textAlpha = Math.min(1, frame / I.fadeInFrames);
|
textAlpha = Math.min(1, frame / I.fadeInFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frame === I.shot1Frame) shots.push({ progress: 0, trail: [], done: false });
|
if (prevFrame < I.shot1Frame && curFrame >= I.shot1Frame) shots.push({ progress: 0, trail: [], done: false });
|
||||||
if (frame === I.shot2Frame) shots.push({ progress: 0, trail: [], done: false });
|
if (prevFrame < I.shot2Frame && curFrame >= I.shot2Frame) shots.push({ progress: 0, trail: [], done: false });
|
||||||
if (frame === I.shot3Frame) shots.push({ progress: 0, trail: [], done: false });
|
if (prevFrame < I.shot3Frame && curFrame >= I.shot3Frame) shots.push({ progress: 0, trail: [], done: false });
|
||||||
|
|
||||||
for (let s of shots) {
|
for (let s of shots) {
|
||||||
if (s.done) continue;
|
if (s.done) continue;
|
||||||
s.progress = Math.min(1, s.progress + I.shotSpeed);
|
s.progress = Math.min(1, s.progress + I.shotSpeed * frameFactor);
|
||||||
|
|
||||||
const x = shooterX + (lTargetX - shooterX) * s.progress;
|
const x = shooterX + (lTargetX - shooterX) * s.progress;
|
||||||
const y = shooterY + (lTargetY - shooterY) * s.progress;
|
const y = shooterY + (lTargetY - shooterY) * s.progress;
|
||||||
|
|
||||||
s.trail.push({ x, y, life: 1 });
|
s.trail.push({ x, y, life: 1 });
|
||||||
if (s.trail.length > I.trailMax) s.trail.shift();
|
if (s.trail.length > I.trailMax) s.trail.shift();
|
||||||
for (let t of s.trail) t.life -= I.trailDecay;
|
for (let t of s.trail) t.life -= I.trailDecay * frameFactor;
|
||||||
s.trail = s.trail.filter((t) => t.life > 0);
|
s.trail = s.trail.filter((t) => t.life > 0);
|
||||||
|
|
||||||
if (s.progress >= 1) {
|
if (s.progress >= 1) {
|
||||||
|
|||||||
+3
-3
@@ -10,9 +10,9 @@ class Particle {
|
|||||||
this.size = S.particleSizeMin + Math.random() * (S.particleSizeMax - S.particleSizeMin);
|
this.size = S.particleSizeMin + Math.random() * (S.particleSizeMax - S.particleSizeMin);
|
||||||
}
|
}
|
||||||
update() {
|
update() {
|
||||||
this.x += this.vx;
|
this.x += this.vx * frameFactor;
|
||||||
this.y += this.vy;
|
this.y += this.vy * frameFactor;
|
||||||
this.life -= this.decay;
|
this.life -= this.decay * frameFactor;
|
||||||
this.vx *= S.particleDamping;
|
this.vx *= S.particleDamping;
|
||||||
this.vy *= S.particleDamping;
|
this.vy *= S.particleDamping;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -36,12 +36,12 @@ class Projectile {
|
|||||||
if (this.trail.length > S.projectileTrailLength) this.trail.shift();
|
if (this.trail.length > S.projectileTrailLength) this.trail.shift();
|
||||||
|
|
||||||
for (let t of this.trail) {
|
for (let t of this.trail) {
|
||||||
t.life -= S.projectileTrailDecay;
|
t.life -= S.projectileTrailDecay * frameFactor;
|
||||||
}
|
}
|
||||||
this.trail = this.trail.filter((t) => t.life > 0);
|
this.trail = this.trail.filter((t) => t.life > 0);
|
||||||
|
|
||||||
this.x += this.vx;
|
this.x += this.vx * frameFactor;
|
||||||
this.y += this.vy;
|
this.y += this.vy * frameFactor;
|
||||||
|
|
||||||
if (this.isHit && this.target && !this.hit) {
|
if (this.isHit && this.target && !this.hit) {
|
||||||
const dx = this.target.x - this.x;
|
const dx = this.target.x - this.x;
|
||||||
|
|||||||
+13
-1
@@ -1,3 +1,15 @@
|
|||||||
|
let frameFactor = 1;
|
||||||
|
let _lastTime = 0;
|
||||||
|
|
||||||
|
function calcDt(timestamp) {
|
||||||
|
if (!_lastTime || !timestamp) {
|
||||||
|
frameFactor = 1;
|
||||||
|
} else {
|
||||||
|
frameFactor = Math.min((timestamp - _lastTime) / (1000 / 60), 6);
|
||||||
|
}
|
||||||
|
_lastTime = timestamp || performance.now();
|
||||||
|
}
|
||||||
|
|
||||||
function crossTimeToSpeed(crossTimeSec) {
|
function crossTimeToSpeed(crossTimeSec) {
|
||||||
const playH = H - S.removeZone;
|
const playH = H - S.removeZone;
|
||||||
return playH / (crossTimeSec * 60);
|
return playH / (crossTimeSec * 60);
|
||||||
@@ -191,7 +203,7 @@ function drawGrid() {
|
|||||||
ctx.strokeStyle = CONFIG.colors.primaryGrid;
|
ctx.strokeStyle = CONFIG.colors.primaryGrid;
|
||||||
ctx.lineWidth = 1;
|
ctx.lineWidth = 1;
|
||||||
const gridSize = S.gridSize;
|
const gridSize = S.gridSize;
|
||||||
bgOffset = (bgOffset + S.gridSpeed) % gridSize;
|
bgOffset = (bgOffset + S.gridSpeed * frameFactor) % gridSize;
|
||||||
for (let x = 0; x <= W; x += gridSize) {
|
for (let x = 0; x <= W; x += gridSize) {
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(x, 0);
|
ctx.moveTo(x, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user