Merge branch 'v26'

This commit is contained in:
evanpelle
2025-11-04 16:08:15 -08:00
37 changed files with 206 additions and 263 deletions
+40 -81
View File
@@ -1,21 +1,15 @@
import miniBigSmoke from "../../../resources/sprites/bigsmoke.png";
import buildingExplosion from "../../../resources/sprites/buildingExplosion.png";
import conquestSword from "../../../resources/sprites/conquestSword.png";
import dust from "../../../resources/sprites/dust.png";
import miniExplosion from "../../../resources/sprites/miniExplosion.png";
import miniFire from "../../../resources/sprites/minifire.png";
import nuke from "../../../resources/sprites/nukeExplosion.png";
import SAMExplosion from "../../../resources/sprites/samExplosion.png";
import sinkingShip from "../../../resources/sprites/sinkingShip.png";
import miniSmoke from "../../../resources/sprites/smoke.png";
import miniSmokeAndFire from "../../../resources/sprites/smokeAndFire.png";
import unitExplosion from "../../../resources/sprites/unitExplosion.png";
import bats from "../../../resources/sprites/halloween/bats.png";
import bubble from "../../../resources/sprites/halloween/bubble.png";
import ghost from "../../../resources/sprites/halloween/ghost.png";
import minifireGreen from "../../../resources/sprites/halloween/minifireGreen.png";
import shark from "../../../resources/sprites/halloween/shark.png";
import skull from "../../../resources/sprites/halloween/skull.png";
import skullNuke from "../../../resources/sprites/halloween/skullNuke.png";
import miniSmokeAndFireGreen from "../../../resources/sprites/halloween/smokeAndFireGreen.png";
import tentacle from "../../../resources/sprites/halloween/tentacle.png";
import tornado from "../../../resources/sprites/halloween/tornado.png";
import { Theme } from "../../core/configuration/Config";
import { PlayerView } from "../../core/game/GameView";
import { AnimatedSprite } from "./AnimatedSprite";
@@ -34,7 +28,7 @@ type AnimatedSpriteConfig = {
const ANIMATED_SPRITE_CONFIG: Partial<Record<FxType, AnimatedSpriteConfig>> = {
[FxType.MiniFire]: {
url: minifireGreen,
url: miniFire,
frameWidth: 7,
frameCount: 6,
frameDuration: 100,
@@ -43,28 +37,28 @@ const ANIMATED_SPRITE_CONFIG: Partial<Record<FxType, AnimatedSpriteConfig>> = {
originY: 11,
},
[FxType.MiniSmoke]: {
url: ghost,
frameWidth: 10,
frameCount: 5,
frameDuration: 100,
url: miniSmoke,
frameWidth: 11,
frameCount: 4,
frameDuration: 120,
looping: true,
originX: 4,
originX: 2,
originY: 10,
},
[FxType.MiniBigSmoke]: {
url: bats,
frameWidth: 21,
frameCount: 6,
url: miniBigSmoke,
frameWidth: 24,
frameCount: 5,
frameDuration: 120,
looping: true,
originX: 9,
originY: 14,
},
[FxType.MiniSmokeAndFire]: {
url: miniSmokeAndFireGreen,
url: miniSmokeAndFire,
frameWidth: 24,
frameCount: 5,
frameDuration: 90,
frameDuration: 120,
looping: true,
originX: 9,
originY: 14,
@@ -96,15 +90,6 @@ const ANIMATED_SPRITE_CONFIG: Partial<Record<FxType, AnimatedSpriteConfig>> = {
originX: 9,
originY: 9,
},
[FxType.SinkingShip]: {
url: sinkingShip,
frameWidth: 16,
frameCount: 14,
frameDuration: 90,
looping: false,
originX: 7,
originY: 7,
},
[FxType.BuildingExplosion]: {
url: buildingExplosion,
frameWidth: 17,
@@ -114,14 +99,23 @@ const ANIMATED_SPRITE_CONFIG: Partial<Record<FxType, AnimatedSpriteConfig>> = {
originX: 8,
originY: 8,
},
[FxType.Nuke]: {
url: skullNuke,
frameWidth: 42,
frameCount: 19,
frameDuration: 50,
[FxType.SinkingShip]: {
url: sinkingShip,
frameWidth: 16,
frameCount: 14,
frameDuration: 90,
looping: false,
originX: 20,
originY: 21,
originX: 7,
originY: 7,
},
[FxType.Nuke]: {
url: nuke,
frameWidth: 60,
frameCount: 9,
frameDuration: 70,
looping: false,
originX: 30,
originY: 30,
},
[FxType.SAMExplosion]: {
url: SAMExplosion,
@@ -133,51 +127,16 @@ const ANIMATED_SPRITE_CONFIG: Partial<Record<FxType, AnimatedSpriteConfig>> = {
originY: 19,
},
[FxType.Conquest]: {
url: skull,
frameWidth: 14,
frameCount: 14,
frameDuration: 90,
looping: false,
originX: 7,
originY: 23,
},
[FxType.Tentacle]: {
url: tentacle,
frameWidth: 22,
frameCount: 26,
frameDuration: 90,
looping: false,
originX: 13,
originY: 28,
},
[FxType.Shark]: {
url: shark,
frameWidth: 25,
frameCount: 14,
frameDuration: 90,
looping: false,
originX: 13,
originY: 8,
},
[FxType.Bubble]: {
url: bubble,
frameWidth: 22,
frameCount: 13,
frameDuration: 80,
looping: false,
originX: 13,
originY: 8,
},
[FxType.Tornado]: {
url: tornado,
frameWidth: 30,
url: conquestSword,
frameWidth: 21,
frameCount: 10,
frameDuration: 80,
looping: true,
originX: 11,
originY: 22,
frameDuration: 90,
looping: false,
originX: 10,
originY: 16,
},
};
export class AnimatedSpriteLoader {
private animatedSpriteImageMap: Map<FxType, HTMLCanvasElement> = new Map();
// Do not color the same sprite twice
+4 -4
View File
@@ -1,6 +1,6 @@
import { Colord } from "colord";
import miniPumpkin from "../../../resources/sprites/halloween/miniPumpkin.png";
import pumpkin from "../../../resources/sprites/halloween/pumpkin.png";
import atomBombSprite from "../../../resources/sprites/atombomb.png";
import hydrogenBombSprite from "../../../resources/sprites/hydrogenbomb.png";
import mirvSprite from "../../../resources/sprites/mirv2.png";
import samMissileSprite from "../../../resources/sprites/samMissile.png";
import tradeShipSprite from "../../../resources/sprites/tradeship.png";
@@ -26,8 +26,8 @@ const SPRITE_CONFIG: Partial<Record<UnitType | TrainTypeSprite, string>> = {
[UnitType.TransportShip]: transportShipSprite,
[UnitType.Warship]: warshipSprite,
[UnitType.SAMMissile]: samMissileSprite,
[UnitType.AtomBomb]: miniPumpkin,
[UnitType.HydrogenBomb]: pumpkin,
[UnitType.AtomBomb]: atomBombSprite,
[UnitType.HydrogenBomb]: hydrogenBombSprite,
[UnitType.TradeShip]: tradeShipSprite,
[UnitType.MIRV]: mirvSprite,
[TrainTypeSprite.Engine]: trainEngineSprite,
+1
View File
@@ -26,6 +26,7 @@ export function conquestFxFactory(
x,
y,
FxType.Conquest,
2500,
);
const fadeAnimation = new FadeFx(swordAnimation, 0.1, 0.6);
conquestFx.push(fadeAnimation);
-4
View File
@@ -16,8 +16,4 @@ export enum FxType {
UnderConstruction = "UnderConstruction",
Dust = "Dust",
Conquest = "Conquest",
Tentacle = "Tentacle",
Shark = "Shark",
Bubble = "Bubble",
Tornado = "Tornado",
}
+2 -31
View File
@@ -19,35 +19,6 @@ function fadeInOut(
return 1 - f * f;
}
}
/**
* Move a sprite around
*/
export class MoveSpriteFx implements Fx {
private originX: number;
private originY: number;
constructor(
private fxToMove: SpriteFx,
private toX: number,
private toY: number,
private fadeIn: number = 0.1,
private fadeOut: number = 0.9,
) {
this.originX = fxToMove.x;
this.originY = fxToMove.y;
}
renderTick(duration: number, ctx: CanvasRenderingContext2D): boolean {
const t = this.fxToMove.getElapsedTime() / this.fxToMove.getDuration();
this.fxToMove.x = Math.floor(this.originX * (1 - t) + this.toX * t);
this.fxToMove.y = Math.floor(this.originY * (1 - t) + this.toY * t);
ctx.save();
ctx.globalAlpha = fadeInOut(t, this.fadeIn, this.fadeOut);
const result = this.fxToMove.renderTick(duration, ctx);
ctx.restore();
return result;
}
}
/**
* Fade in/out another FX
*/
@@ -78,8 +49,8 @@ export class SpriteFx implements Fx {
protected waitToTheEnd = false;
constructor(
animatedSpriteLoader: AnimatedSpriteLoader,
public x: number,
public y: number,
protected x: number,
protected y: number,
fxType: FxType,
duration?: number,
owner?: PlayerView,
+1 -77
View File
@@ -14,7 +14,7 @@ import { conquestFxFactory } from "../fx/ConquestFx";
import { Fx, FxType } from "../fx/Fx";
import { NukeAreaFx } from "../fx/NukeAreaFx";
import { nukeFxFactory, ShockwaveFx } from "../fx/NukeFx";
import { FadeFx, MoveSpriteFx, SpriteFx } from "../fx/SpriteFx";
import { SpriteFx } from "../fx/SpriteFx";
import { TargetFx } from "../fx/TargetFx";
import { TextFx } from "../fx/TextFx";
import { UnitExplosionFx } from "../fx/UnitExplosionFx";
@@ -22,8 +22,6 @@ import { Layer } from "./Layer";
export class FxLayer implements Layer {
private canvas: HTMLCanvasElement;
private context: CanvasRenderingContext2D;
private lastRandomEvent: number = 0;
private randomEventRate: number = 8;
private lastRefresh: number = 0;
private refreshRate: number = 10;
@@ -44,14 +42,6 @@ export class FxLayer implements Layer {
}
tick() {
if (!this.game.config().userSettings()?.fxLayer()) {
return;
}
this.lastRandomEvent += 1;
if (this.lastRandomEvent > this.randomEventRate) {
this.lastRandomEvent = 0;
this.randomEvent();
}
this.manageBoatTargetFx();
this.game
.updatesSinceLastTick()
@@ -154,72 +144,6 @@ export class FxLayer implements Layer {
this.allFx.push(textFx);
}
randomEvent() {
const randX = Math.floor(Math.random() * this.game.width());
const randY = Math.floor(Math.random() * this.game.height());
const ref = this.game.ref(randX, randY);
if (this.game.isOcean(ref) && !this.game.isShoreline(ref)) {
const animation = Math.floor(Math.random() * 4);
if (animation === 0) {
const fx = new SpriteFx(
this.animatedSpriteLoader,
randX,
randY,
FxType.Shark,
);
this.allFx.push(fx);
} else if (animation === 1) {
const fx = new SpriteFx(
this.animatedSpriteLoader,
randX,
randY,
FxType.Bubble,
);
this.allFx.push(fx);
} else if (animation === 2) {
const fx = new MoveSpriteFx(
new SpriteFx(
this.animatedSpriteLoader,
randX,
randY,
FxType.Tornado,
6000,
),
randX - 40,
randY,
0.1,
0.8,
);
this.allFx.push(fx);
} else if (animation === 3) {
const fx = new FadeFx(
new SpriteFx(
this.animatedSpriteLoader,
randX,
randY,
FxType.Tentacle,
),
0.1,
0.8,
);
this.allFx.push(fx);
}
} else {
const ghost = new FadeFx(
new SpriteFx(
this.animatedSpriteLoader,
randX,
randY,
FxType.MiniSmoke,
4000,
),
0.1,
0.8,
);
this.allFx.push(ghost);
}
}
onUnitEvent(unit: UnitView) {
switch (unit.type()) {
case UnitType.TransportShip: {