basic railgun

This commit is contained in:
koneko 2025-02-18 21:42:40 +01:00
parent abde1a6519
commit a33912d59d
2 changed files with 78 additions and 14 deletions

View File

@ -64,7 +64,7 @@ export default class Projectile extends GameObject {
public update(elapsedMS) { public update(elapsedMS) {
if (this.deleteMe) return; if (this.deleteMe) return;
if (this.x > 2000 || this.x < 0 || this.y > 2000 || this.y < 0 || this.pierce <= 0 || this.timeToLive <= 0) if (this.x > 1720 || this.x < 0 || this.y > 2000 || this.y < 0 || this.pierce <= 0 || this.timeToLive <= 0)
return this.destroy(); return this.destroy();
this.timeToLive -= Engine.GameScene.gameSpeedMultiplier; this.timeToLive -= Engine.GameScene.gameSpeedMultiplier;
Engine.Grid.creeps.forEach((creep) => { Engine.Grid.creeps.forEach((creep) => {
@ -105,6 +105,54 @@ export default class Projectile extends GameObject {
} }
} }
export class RailProjectile extends Projectile {
public visuals: PIXI.Sprite[] = [];
public counter: number = 0;
constructor(
x,
y,
textures,
angle,
damage,
tint,
timeToLive,
pierce,
gemResistanceModifications: CreepResistancesDefinition
) {
super(x, y, textures, angle, damage, tint, timeToLive, pierce, gemResistanceModifications);
this.pierce = 1000;
this.timeToLive = 2000;
}
public destroy(): void {
super.destroy();
this.visuals.forEach((visual) => visual.destroy());
this.visuals = [];
}
public update(elapsedMS) {
super.update(elapsedMS);
if (this.counter == 2) {
this.counter = 0;
let newVisual = new PIXI.Sprite({
x: this.x,
y: this.y,
rotation: this.angle,
texture: this.sprite.texture,
scale: 0.25,
});
newVisual.anchor.set(0.5, 0.5);
this.visuals.push(newVisual);
this.visuals.forEach((visual) => {
visual.width -= 4;
visual.height -= 4;
visual.alpha -= 0.05;
if (visual.width <= 0 && visual.height <= 0) visual.destroy();
});
Engine.GameScene.stage.addChild(newVisual);
} else this.counter++;
}
}
export class VisualLightning extends GameObject { export class VisualLightning extends GameObject {
public deleteMe: boolean = false; public deleteMe: boolean = false;
private c: Creep; private c: Creep;

View File

@ -4,7 +4,7 @@ import GameObject from '../GameObject';
import { CreepResistancesDefinition, TowerDefinition } from '../Definitions'; import { CreepResistancesDefinition, TowerDefinition } from '../Definitions';
import { Cell } from './Grid'; import { Cell } from './Grid';
import { TowerBehaviours } from './TowerManager'; import { TowerBehaviours } from './TowerManager';
import Projectile from './Projectile'; import Projectile, { RailProjectile } from './Projectile';
import Gem from './Gem'; import Gem from './Gem';
import { import {
DebuffTowerBehaviour, DebuffTowerBehaviour,
@ -132,7 +132,10 @@ export class Tower extends GameObject {
} }
combinedTint = color; combinedTint = color;
} }
let proj = new Projectile(
let proj;
if (this.behaviour == TowerBehaviours.RailTowerBehaviour) {
proj = new RailProjectile(
x, x,
y, y,
this.definition.projectileTextures, this.definition.projectileTextures,
@ -143,7 +146,20 @@ export class Tower extends GameObject {
this.computedPierce, this.computedPierce,
this.totalGemResistanceModifications this.totalGemResistanceModifications
); );
const time = new Date().toISOString(); } else {
proj = new Projectile(
x,
y,
this.definition.projectileTextures,
angle,
this.computedDamageToDeal,
combinedTint,
this.computedTimeToLive,
this.computedPierce,
this.totalGemResistanceModifications
);
}
// const time = new Date().toISOString();
// console.log(`${time} ${this.definition.name} shot at ${angle} degrees`); // console.log(`${time} ${this.definition.name} shot at ${angle} degrees`);
this.projectiles.push(proj); this.projectiles.push(proj);
return proj; return proj;