From 462135dc5561918daca09b48f5cf7471e2b11325 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Sun, 3 Dec 2023 20:03:40 -0800 Subject: [PATCH] Rotate weapon style attack sprites with entity --- srcjs/stendhal/entity/RPEntity.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/srcjs/stendhal/entity/RPEntity.ts b/srcjs/stendhal/entity/RPEntity.ts index fb5ed983a85..6c9da825fbb 100644 --- a/srcjs/stendhal/entity/RPEntity.ts +++ b/srcjs/stendhal/entity/RPEntity.ts @@ -836,19 +836,27 @@ export class RPEntity extends ActiveEntity { if (weapon === "blade_strike" && nature == 0) { weapon += "_cut"; } + let image: HTMLImageElement; const imagePath = Nature.VALUES[nature].getWeaponPath(weapon); + if (weapon.startsWith("blade_strike")) { + image = stendhal.data.sprites.get(imagePath); + } else { + const entity_rot = 90 * (this["dir"] - 1); + // TODO: rotate left & right 45 degrees & offset to center on entity + image = stendhal.data.sprites.getRotated(imagePath, entity_rot); + } - this.attackSprite = (function(imagePath, _ranged, dir) { + this.attackSprite = (function(image, _ranged, dir) { return { initTime: Date.now(), - image: stendhal.data.sprites.get(imagePath), + image: image, frame: 0, barehand: weapon.startsWith("blade_strike"), expired: function() { return Date.now() - this.initTime > 180; }, draw: function(ctx: CanvasRenderingContext2D, x: number, y: number, entityWidth: number, entityHeight: number) { - if (!this.image.height) { + if (!this.image || !this.image.height) { return; } @@ -918,7 +926,7 @@ export class RPEntity extends ActiveEntity { } } }; - })(imagePath, ranged, this["dir"]); + })(image, ranged, this["dir"]); } }