mirror of
https://github.com/Sheldan/canvas.git
synced 2026-01-08 01:03:42 +00:00
survivors: also showing taken damage
This commit is contained in:
@@ -8,6 +8,7 @@ import {HealthPack, ItemDrop, LevelDrop, MoneyDrop} from "./drop.ts";
|
||||
import {ItemManagement} from "./items.ts";
|
||||
import {ProjectileStats} from "./stats.ts";
|
||||
import {EnemyStatus} from "./status.ts";
|
||||
import {NumberDisplayParticle} from "./particles.ts";
|
||||
|
||||
export abstract class Enemy implements Placeable, Drawable, Acting, Healthy {
|
||||
protected _position: Vector;
|
||||
@@ -40,6 +41,7 @@ export abstract class Enemy implements Placeable, Drawable, Acting, Healthy {
|
||||
|
||||
takeDamage(damage: number) {
|
||||
this.status.health -= damage;
|
||||
NumberDisplayParticle.spawnNumberParticle(this.world, damage, this._position, 'white')
|
||||
if(this.status.dead) {
|
||||
this.die()
|
||||
this.world.removeEnemy(this)
|
||||
@@ -65,6 +67,9 @@ export abstract class Enemy implements Placeable, Drawable, Acting, Healthy {
|
||||
return this.status.dead
|
||||
}
|
||||
|
||||
tick(seconds: number, tick: number) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class BasicEnemy extends Enemy {
|
||||
|
||||
@@ -4,7 +4,7 @@ import {fillDot, getCoordinatesSplit} from "./utils.ts";
|
||||
import {PlayerStats} from "./stats.ts";
|
||||
import {PlayerStatus} from "./status.ts";
|
||||
import {World} from "./World.ts";
|
||||
import {HealingParticle} from "./particles.ts";
|
||||
import { NumberDisplayParticle} from "./particles.ts";
|
||||
|
||||
export class Player implements Drawable, Acting, Healthy {
|
||||
private _position: Vector;
|
||||
@@ -75,6 +75,7 @@ export class Player implements Drawable, Acting, Healthy {
|
||||
}
|
||||
|
||||
takeDamage(damage: number) {
|
||||
NumberDisplayParticle.spawnNumberParticle(this._world, damage, this._position, 'red')
|
||||
this._status.health -= damage;
|
||||
}
|
||||
|
||||
@@ -168,7 +169,7 @@ export class Player implements Drawable, Acting, Healthy {
|
||||
let toHealNow = this._toHeal - (this._toHeal % 1);
|
||||
this._toHeal -= toHealNow;
|
||||
this.heal(toHealNow);
|
||||
HealingParticle.spawnHealingParticle(this._world, toHealNow, this.position)
|
||||
NumberDisplayParticle.spawnNumberParticle(this._world, toHealNow, this.position, 'green')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,38 +32,44 @@ abstract class BaseParticle implements Particle {
|
||||
|
||||
tick(seconds: number, tick: number) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class HealingParticle extends BaseParticle {
|
||||
private healthAmount: number;
|
||||
export class NumberDisplayParticle extends BaseParticle {
|
||||
private number: number;
|
||||
private secondsToDisplay: number = 2;
|
||||
private alreadyDisplayed: number = 0;
|
||||
private color: string;
|
||||
|
||||
constructor(position: Vector, world: World, healthAmount: number) {
|
||||
constructor(position: Vector, world: World, healthAmount: number, color: string) {
|
||||
super(position, world);
|
||||
this.healthAmount = healthAmount;
|
||||
this.number = healthAmount;
|
||||
this.color = color
|
||||
}
|
||||
|
||||
draw(ctx: CanvasRenderingContext2D) {
|
||||
ctx.fillStyle = 'green';
|
||||
ctx.fillText(this.healthAmount + '', this._position.x, this._position.y);
|
||||
ctx.fillStyle = this.color;
|
||||
ctx.fillText(this.number + '', this._position.x, this._position.y);
|
||||
}
|
||||
|
||||
static spawnHealingParticle(world: World, health: number, position: Vector) {
|
||||
world.addParticle(this.createHealingParticle(world, health, position))
|
||||
}
|
||||
|
||||
static createHealingParticle(world: World, health: number, position: Vector) {
|
||||
let healingParticle = new HealingParticle(position, world, health)
|
||||
return healingParticle
|
||||
}
|
||||
|
||||
|
||||
tick(seconds: number, tick: number) {
|
||||
this.alreadyDisplayed += seconds;
|
||||
if(this.alreadyDisplayed > this.secondsToDisplay) {
|
||||
this.world.removeParticle(this)
|
||||
}
|
||||
}
|
||||
|
||||
static spawnNumberParticle(world: World, health: number, position: Vector, color?: string) {
|
||||
if(!color) {
|
||||
color = 'red'
|
||||
}
|
||||
world.addParticle(this.createNumberParticle(world, health, position, color))
|
||||
}
|
||||
|
||||
static createNumberParticle(world: World, health: number, position: Vector, color?: string) {
|
||||
if(!color) {
|
||||
color = 'red'
|
||||
}
|
||||
let particle = new NumberDisplayParticle(position, world, health, color)
|
||||
return particle
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user