Replace unit sprites with tactical RPG sheets
This commit is contained in:
@@ -28,6 +28,13 @@ const unitTexture: Record<string, string> = {
|
||||
'rebel-leader': 'unit-rebel-leader'
|
||||
};
|
||||
|
||||
const unitFrameRows: Record<UnitDirection, number> = {
|
||||
south: 0,
|
||||
east: 1,
|
||||
north: 2,
|
||||
west: 3
|
||||
};
|
||||
|
||||
type BattleLayout = {
|
||||
mapX: number;
|
||||
mapY: number;
|
||||
@@ -248,16 +255,16 @@ export class BattleScene extends Phaser.Scene {
|
||||
|
||||
private drawUnits() {
|
||||
firstBattleUnits.forEach((unit) => {
|
||||
const sizeRatio = unit.faction === 'ally' ? 1.08 : 1.02;
|
||||
const sizeRatio = unit.faction === 'ally' ? 1.16 : 1.1;
|
||||
const textureBase = unitTexture[unit.id] ?? 'unit-rebel';
|
||||
const sprite = this.add.sprite(this.tileCenterX(unit.x), this.tileCenterY(unit.y), `${textureBase}-south-0`);
|
||||
const sprite = this.add.sprite(this.tileCenterX(unit.x), this.tileCenterY(unit.y), textureBase, this.unitFrameIndex('south'));
|
||||
sprite.setName(`unit-${unit.id}`);
|
||||
sprite.setDisplaySize(this.layout.tileSize * sizeRatio, this.layout.tileSize * sizeRatio);
|
||||
sprite.setDepth(6);
|
||||
sprite.setInteractive({ useHandCursor: unit.faction === 'ally' });
|
||||
sprite.on('pointerdown', () => this.selectUnit(unit));
|
||||
|
||||
const label = this.add.text(sprite.x, sprite.y + this.layout.tileSize * 0.47, unit.name, {
|
||||
const label = this.add.text(sprite.x, sprite.y + this.layout.tileSize * 0.52, unit.name, {
|
||||
fontFamily: '"Malgun Gothic", "Noto Sans KR", sans-serif',
|
||||
fontSize: '11px',
|
||||
color: unit.faction === 'ally' ? '#e7edf7' : '#ffebe7',
|
||||
@@ -960,7 +967,7 @@ export class BattleScene extends Phaser.Scene {
|
||||
this.tweens.add({
|
||||
targets: view.label,
|
||||
x: targetX,
|
||||
y: targetY + this.layout.tileSize * 0.47,
|
||||
y: targetY + this.layout.tileSize * 0.52,
|
||||
duration,
|
||||
ease: 'Sine.easeInOut'
|
||||
});
|
||||
@@ -975,7 +982,7 @@ export class BattleScene extends Phaser.Scene {
|
||||
|
||||
private playUnitWalk(view: UnitView, direction: UnitDirection) {
|
||||
view.direction = direction;
|
||||
view.sprite.setFlipX(direction === 'west');
|
||||
view.sprite.setFlipX(false);
|
||||
view.sprite.play(`${view.textureBase}-walk-${direction}`, true);
|
||||
}
|
||||
|
||||
@@ -986,9 +993,12 @@ export class BattleScene extends Phaser.Scene {
|
||||
}
|
||||
|
||||
private setUnitDirectionFrame(view: UnitView, direction: UnitDirection) {
|
||||
const sourceDirection = direction === 'west' ? 'east' : direction;
|
||||
view.sprite.setTexture(`${view.textureBase}-${sourceDirection}-0`);
|
||||
view.sprite.setFlipX(direction === 'west');
|
||||
view.sprite.setTexture(view.textureBase, this.unitFrameIndex(direction));
|
||||
view.sprite.setFlipX(false);
|
||||
}
|
||||
|
||||
private unitFrameIndex(direction: UnitDirection, frame = 0) {
|
||||
return unitFrameRows[direction] * 4 + frame;
|
||||
}
|
||||
|
||||
private applyActedStyle(unit: UnitData) {
|
||||
|
||||
Reference in New Issue
Block a user