mirror of
https://github.com/Sheldan/canvas.git
synced 2026-01-27 20:39:08 +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 {ItemManagement} from "./items.ts";
|
||||||
import {ProjectileStats} from "./stats.ts";
|
import {ProjectileStats} from "./stats.ts";
|
||||||
import {EnemyStatus} from "./status.ts";
|
import {EnemyStatus} from "./status.ts";
|
||||||
|
import {NumberDisplayParticle} from "./particles.ts";
|
||||||
|
|
||||||
export abstract class Enemy implements Placeable, Drawable, Acting, Healthy {
|
export abstract class Enemy implements Placeable, Drawable, Acting, Healthy {
|
||||||
protected _position: Vector;
|
protected _position: Vector;
|
||||||
@@ -40,6 +41,7 @@ export abstract class Enemy implements Placeable, Drawable, Acting, Healthy {
|
|||||||
|
|
||||||
takeDamage(damage: number) {
|
takeDamage(damage: number) {
|
||||||
this.status.health -= damage;
|
this.status.health -= damage;
|
||||||
|
NumberDisplayParticle.spawnNumberParticle(this.world, damage, this._position, 'white')
|
||||||
if(this.status.dead) {
|
if(this.status.dead) {
|
||||||
this.die()
|
this.die()
|
||||||
this.world.removeEnemy(this)
|
this.world.removeEnemy(this)
|
||||||
@@ -65,6 +67,9 @@ export abstract class Enemy implements Placeable, Drawable, Acting, Healthy {
|
|||||||
return this.status.dead
|
return this.status.dead
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tick(seconds: number, tick: number) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BasicEnemy extends Enemy {
|
export class BasicEnemy extends Enemy {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {fillDot, getCoordinatesSplit} from "./utils.ts";
|
|||||||
import {PlayerStats} from "./stats.ts";
|
import {PlayerStats} from "./stats.ts";
|
||||||
import {PlayerStatus} from "./status.ts";
|
import {PlayerStatus} from "./status.ts";
|
||||||
import {World} from "./World.ts";
|
import {World} from "./World.ts";
|
||||||
import {HealingParticle} from "./particles.ts";
|
import { NumberDisplayParticle} from "./particles.ts";
|
||||||
|
|
||||||
export class Player implements Drawable, Acting, Healthy {
|
export class Player implements Drawable, Acting, Healthy {
|
||||||
private _position: Vector;
|
private _position: Vector;
|
||||||
@@ -75,6 +75,7 @@ export class Player implements Drawable, Acting, Healthy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
takeDamage(damage: number) {
|
takeDamage(damage: number) {
|
||||||
|
NumberDisplayParticle.spawnNumberParticle(this._world, damage, this._position, 'red')
|
||||||
this._status.health -= damage;
|
this._status.health -= damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +169,7 @@ export class Player implements Drawable, Acting, Healthy {
|
|||||||
let toHealNow = this._toHeal - (this._toHeal % 1);
|
let toHealNow = this._toHeal - (this._toHeal % 1);
|
||||||
this._toHeal -= toHealNow;
|
this._toHeal -= toHealNow;
|
||||||
this.heal(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) {
|
tick(seconds: number, tick: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HealingParticle extends BaseParticle {
|
export class NumberDisplayParticle extends BaseParticle {
|
||||||
private healthAmount: number;
|
private number: number;
|
||||||
private secondsToDisplay: number = 2;
|
private secondsToDisplay: number = 2;
|
||||||
private alreadyDisplayed: number = 0;
|
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);
|
super(position, world);
|
||||||
this.healthAmount = healthAmount;
|
this.number = healthAmount;
|
||||||
|
this.color = color
|
||||||
}
|
}
|
||||||
|
|
||||||
draw(ctx: CanvasRenderingContext2D) {
|
draw(ctx: CanvasRenderingContext2D) {
|
||||||
ctx.fillStyle = 'green';
|
ctx.fillStyle = this.color;
|
||||||
ctx.fillText(this.healthAmount + '', this._position.x, this._position.y);
|
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) {
|
tick(seconds: number, tick: number) {
|
||||||
this.alreadyDisplayed += seconds;
|
this.alreadyDisplayed += seconds;
|
||||||
if(this.alreadyDisplayed > this.secondsToDisplay) {
|
if(this.alreadyDisplayed > this.secondsToDisplay) {
|
||||||
this.world.removeParticle(this)
|
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