Skip to content

Commit 4ff5a90

Browse files
committed
chore: polish hud layout
1 parent e4d7856 commit 4ff5a90

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

‎src/scenes/GameScene.ts‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ const COIN_CHANCE = 0.22;
2828
const COIN_SCALE = 0.55;
2929
const CLOUD_SCROLL_SPEED = 0.006;
3030
const BASE_BG_COLOR = 0x9fd7ff;
31-
const HUD_HEIGHT = 52;
32-
const HUD_PADDING = 16;
31+
const HUD_HEIGHT = 44;
32+
const HUD_PADDING = 12;
3333
const HUD_DEPTH = 10;
3434
const HUD_TEXT_DEPTH = 12;
3535
const HUD_COIN_SCALE = 0.35;
36+
const HUD_COIN_GAP = 6;
3637

3738
export class GameScene extends Phaser.Scene {
3839
private player!: Phaser.Physics.Arcade.Sprite;
@@ -48,6 +49,7 @@ export class GameScene extends Phaser.Scene {
4849
private timeText!: Phaser.GameObjects.Text;
4950
private coinIcon!: Phaser.GameObjects.Image;
5051
private coinText!: Phaser.GameObjects.Text;
52+
private coinGroup!: Phaser.GameObjects.Container;
5153
private hudBackground!: Phaser.GameObjects.Image;
5254
private coinsCollected = 0;
5355
private gameOver = false;
@@ -262,8 +264,8 @@ export class GameScene extends Phaser.Scene {
262264
private updateScore(time: number) {
263265
const elapsedSeconds = Math.max(0, (time - this.startTime) / 1000);
264266
const scoreValue = Math.floor(elapsedSeconds * 10 + this.coinsCollected * 50);
265-
this.scoreText.setText(`Score: ${scoreValue}`);
266-
this.timeText.setText(`Tiempo: ${elapsedSeconds.toFixed(1)}s`);
267+
this.scoreText.setText(`${scoreValue}`);
268+
this.timeText.setText(`${elapsedSeconds.toFixed(1)}s`);
267269
this.coinText.setText(`${this.coinsCollected}`);
268270
this.layoutHud(this.scale.width);
269271
}
@@ -298,10 +300,10 @@ export class GameScene extends Phaser.Scene {
298300
this.hudBackground.setDisplaySize(viewportWidth, HUD_HEIGHT);
299301

300302
const textStyle: Phaser.Types.GameObjects.Text.TextStyle = {
301-
fontSize: '20px',
303+
fontSize: '18px',
302304
color: '#f6f7fb',
303305
stroke: '#1d1e2c',
304-
strokeThickness: 3
306+
strokeThickness: 2
305307
};
306308

307309
this.scoreText = this.add.text(0, 0, '', textStyle).setOrigin(0, 0.5);
@@ -317,6 +319,9 @@ export class GameScene extends Phaser.Scene {
317319
this.coinText = this.add.text(0, 0, '', textStyle).setOrigin(0, 0.5);
318320
this.coinText.setDepth(HUD_TEXT_DEPTH);
319321

322+
this.coinGroup = this.add.container(0, 0, [this.coinIcon, this.coinText]);
323+
this.coinGroup.setDepth(HUD_TEXT_DEPTH);
324+
320325
this.resizeHud(viewportWidth);
321326
}
322327

@@ -333,11 +338,12 @@ export class GameScene extends Phaser.Scene {
333338

334339
const coinTextWidth = this.coinText.width;
335340
const coinIconWidth = this.coinIcon.displayWidth;
336-
const coinTextX = viewportWidth - HUD_PADDING - coinTextWidth;
337-
const coinIconX = coinTextX - 8 - coinIconWidth;
341+
const coinBlockWidth = coinIconWidth + HUD_COIN_GAP + coinTextWidth;
342+
const coinBlockX = viewportWidth - HUD_PADDING - coinBlockWidth;
338343

339-
this.coinIcon.setPosition(coinIconX, centerY);
340-
this.coinText.setPosition(coinTextX, centerY);
344+
this.coinIcon.setPosition(0, 0);
345+
this.coinText.setPosition(coinIconWidth + HUD_COIN_GAP, 0);
346+
this.coinGroup.setPosition(coinBlockX, centerY);
341347
}
342348

343349
private getCloudBandHeight(viewportHeight: number) {

0 commit comments

Comments
 (0)