Skip to content

Commit

Permalink
Rotate weapon style attack sprites with entity
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Dec 4, 2023
1 parent 9d0d50a commit 462135d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions srcjs/stendhal/entity/RPEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -918,7 +926,7 @@ export class RPEntity extends ActiveEntity {
}
}
};
})(imagePath, ranged, this["dir"]);
})(image, ranged, this["dir"]);
}
}

Expand Down

0 comments on commit 462135d

Please sign in to comment.