From f4c4ccff488872088ac25a1b7dc9d33aceb1d420 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Wed, 25 Sep 2024 19:05:17 +0100 Subject: [PATCH] Lint --- src/entities/playable/playable.ts | 36 +++++++++++++++++++++++++----- src/entities/playable/testDummy.ts | 12 ++++------ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/entities/playable/playable.ts b/src/entities/playable/playable.ts index d483597..0b17aef 100644 --- a/src/entities/playable/playable.ts +++ b/src/entities/playable/playable.ts @@ -1,8 +1,8 @@ -import { Container, Point, Sprite, UPDATE_PRIORITY, Text, DEG_TO_RAD, Graphics } from "pixi.js"; +import { Point, Sprite, UPDATE_PRIORITY, Text, DEG_TO_RAD, Graphics } from "pixi.js"; import { PhysicsEntity } from "../phys/physicsEntity"; -import { collisionGroupBitmask, CollisionGroups, GameWorld, PIXELS_PER_METER, RapierPhysicsObject } from "../../world"; +import { GameWorld, PIXELS_PER_METER, RapierPhysicsObject } from "../../world"; import { add, Coordinate, magnitude, MetersValue, mult, sub } from "../../utils"; -import { ActiveEvents, ColliderDesc, RigidBodyDesc, Vector2 } from "@dimforge/rapier2d-compat"; +import { Vector2 } from "@dimforge/rapier2d-compat"; import { IPhysicalEntity } from "../entity"; import { Explosion } from "../explosion"; import { teamGroupToColorSet, WormInstance } from "../../logic/teams"; @@ -25,6 +25,9 @@ export abstract class PlayableEntity extends PhysicsEntity { private healthText: Text; protected healthTextBox: Graphics; + private visibleHealth: number; + private healthChangeTensionTimer: number|null = null; + get position() { return this.body.body.translation(); } @@ -35,7 +38,8 @@ export abstract class PlayableEntity extends PhysicsEntity { set health(v: number) { this.wormIdent.health = v; - this.healthText.text = this.health; + // Potentially further delay until the player has stopped moving. + this.healthChangeTensionTimer = 75; } constructor(sprite: Sprite, body: RapierPhysicsObject, position: Coordinate, world: GameWorld, private readonly wormIdent: WormInstance, private readonly opts: Opts) { @@ -62,6 +66,7 @@ export abstract class PlayableEntity extends PhysicsEntity { align: 'center', }, }); + this.visibleHealth = this.health; this.healthTextBox = new Graphics(); this.healthText.position.set((this.nameText.width/2) - this.healthText.width/2, 34); applyGenericBoxStyle(this.healthTextBox).roundRect(-5,0,this.nameText.width+10,30, 4).stroke().fill(); @@ -80,12 +85,33 @@ export abstract class PlayableEntity extends PhysicsEntity { this.healthTextBox.position.set(this.sprite.x - 50, this.sprite.y - 100); } + if (this.healthChangeTensionTimer) { + this.wireframe.setDebugText(`tension: ${this.healthChangeTensionTimer}`); + } + + if (!this.body.body.isMoving() && this.wasMoving) { this.wasMoving = false; this.body.body.setRotation(0, false); this.body.body.setTranslation(add(this.body.body.translation(), new Vector2(0, -0.25)), false); - if (this.health === 0) { + } + + if (!this.body.body.isMoving() && !this.wasMoving && this.healthChangeTensionTimer) { + this.healthChangeTensionTimer -= dt; + } + + if (this.healthChangeTensionTimer && this.healthChangeTensionTimer <= 0) { + this.healthChangeTensionTimer = null; + } + + if (this.healthChangeTensionTimer === null) { + if (this.visibleHealth > this.health) { + this.visibleHealth--; + this.healthText.text = this.visibleHealth; + } + // Delay before this? + if (this.visibleHealth === 0) { this.explode(); } } diff --git a/src/entities/playable/testDummy.ts b/src/entities/playable/testDummy.ts index f9ee09a..398efd5 100644 --- a/src/entities/playable/testDummy.ts +++ b/src/entities/playable/testDummy.ts @@ -1,13 +1,9 @@ -import { Container, Point, Sprite, Texture, UPDATE_PRIORITY, Text, DEG_TO_RAD, Graphics } from "pixi.js"; -import { PhysicsEntity } from "../phys/physicsEntity"; +import { Container, Sprite, Texture, UPDATE_PRIORITY } from "pixi.js"; import { AssetPack } from "../../assets"; import { collisionGroupBitmask, CollisionGroups, GameWorld, PIXELS_PER_METER } from "../../world"; -import { add, Coordinate, magnitude, MetersValue, mult, sub } from "../../utils"; -import { ActiveEvents, ColliderDesc, RigidBodyDesc, Vector2 } from "@dimforge/rapier2d-compat"; -import { IPhysicalEntity } from "../entity"; -import { Explosion } from "../explosion"; -import { teamGroupToColorSet, WormInstance } from "../../logic/teams"; -import { applyGenericBoxStyle } from "../../mixins/styles"; +import { Coordinate, MetersValue } from "../../utils"; +import { ActiveEvents, ColliderDesc, RigidBodyDesc } from "@dimforge/rapier2d-compat"; +import { WormInstance } from "../../logic/teams"; import { PlayableEntity } from "./playable"; /**