Reposition on resize and add title screen element (#9)

This commit is contained in:
lucas authored and GitHub committed 2025-10-06 19:05:05 +02:00
1 parent 93ce8285d4
commit d5035a9a87
3 files changed
+48 -29

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import { Engine, ScreenElement, vec } from "excalibur";
import { Text } from "../ScreenElements/Text";
import { subTitleFont, titleFont } from "../utils/fontUtil";
import { spacingM } from "../utils/formattingUtils";
export class Title extends ScreenElement {
private _title: Text = null!;
private _subTitle: Text = null!;
onInitialize(_engine: Engine): void {
// Title
this._title = new Text({
text: "Auto Beer Pong",
font: titleFont,
});
this._title.anchor = vec(0.5, 0);
this.addChild(this._title);
// Sub title
this._subTitle = new Text({
text: "An auto battler with stupid people.",
font: subTitleFont,
});
this._subTitle.anchor = vec(0.5, 0);
this._subTitle.pos = vec(0, this._titleHeight + spacingM);
this.addChild(this._subTitle);
}
get height(): number {
return this._titleHeight + subTitleFont.size + spacingM;
}
private get _titleHeight(): number {
return titleFont.size;
}
}
+7 -24
View File
@@ -1,15 +1,14 @@
import * as ex from 'excalibur'; import * as ex from 'excalibur';
import { spacingL, spacingM } from '../utils/formattingUtils'; import { spacingL, spacingM } from '../utils/formattingUtils';
import { subTitleFont, titleFont } from '../utils/fontUtil';
import { Cups } from '../Cups'; import { Cups } from '../Cups';
import { GameState } from '../GameState'; import { GameState } from '../GameState';
import { GameStateScene } from './GameStateScene'; import { GameStateScene } from './GameStateScene';
import { PlayerListScreenElement } from '../ScreenElements/PlayerListScreenElement'; import { PlayerListScreenElement } from '../ScreenElements/PlayerListScreenElement';
import { TitledListScreenElement } from '../ScreenElements/TitledListScreenElement'; import { TitledListScreenElement } from '../ScreenElements/TitledListScreenElement';
import { Text } from '../ScreenElements/Text';
import { Button } from '../ScreenElements/Button'; import { Button } from '../ScreenElements/Button';
import { PlayerNameInput } from '../GameElements/PlayerNameInput'; import { PlayerNameInput } from '../GameElements/PlayerNameInput';
import { Connection, GameMessageEvent } from '../Connection'; import { Connection, GameMessageEvent } from '../Connection';
import { Title } from '../GameElements/Title';
const tableWidth = 400; const tableWidth = 400;
const maxPlayers = 2; const maxPlayers = 2;
@@ -20,13 +19,12 @@ export class LobbyScene extends GameStateScene {
private _table: ex.ScreenElement = null!; private _table: ex.ScreenElement = null!;
private _cups: ex.ScreenElement = null!; private _cups: ex.ScreenElement = null!;
private _title: Title = null!;
private _bar1: ex.ScreenElement = null!; private _bar1: ex.ScreenElement = null!;
private _bar2: ex.ScreenElement = null!; private _bar2: ex.ScreenElement = null!;
private _bar3: ex.ScreenElement = null!; private _bar3: ex.ScreenElement = null!;
private _title: Text = null!;
private _subTitle: Text = null!;
private _playerList: PlayerListScreenElement = null!; private _playerList: PlayerListScreenElement = null!;
private _spectatorsList: TitledListScreenElement = null!; private _spectatorsList: TitledListScreenElement = null!;
@@ -77,23 +75,9 @@ export class LobbyScene extends GameStateScene {
this.add(this._cups); this.add(this._cups);
// Title // Title
this._title = new Text({ this._title = new Title();
text: "Auto Beer Pong",
font: titleFont,
});
this._title.anchor.setTo(0.5, 0);
this.add(this._title); this.add(this._title);
// Sub title
this._subTitle = new Text({
text: "An auto battler with stupid people.",
font: subTitleFont,
});
this._subTitle.anchor.setTo(0.5, 0);
this.add(this._subTitle);
this._playerList = new PlayerListScreenElement("Players", maxPlayers); this._playerList = new PlayerListScreenElement("Players", maxPlayers);
this._playerList.labels = ["Dubbel"]; this._playerList.labels = ["Dubbel"];
this._playerList.anchor.setTo(0.5, 0); this._playerList.anchor.setTo(0.5, 0);
@@ -118,6 +102,8 @@ export class LobbyScene extends GameStateScene {
this._playerNameInput = new PlayerNameInput((_name: string) => this._join()); this._playerNameInput = new PlayerNameInput((_name: string) => this._join());
this._playerNameInput.anchor = ex.vec(0.5, 0); this._playerNameInput.anchor = ex.vec(0.5, 0);
engine.screen.events.on("resize", () => this._updatePositions());
this._updateVisibility(); this._updateVisibility();
this._updatePositions(); this._updatePositions();
} }
@@ -168,10 +154,7 @@ export class LobbyScene extends GameStateScene {
y += this._bar1.height + spacingM; y += this._bar1.height + spacingM;
this._title.pos = ex.vec(halfWidth, y); this._title.pos = ex.vec(halfWidth, y);
y += this._title.font.size + spacingM; y += this._title.height + spacingM;
this._subTitle.pos = ex.vec(halfWidth, y);
y += this._subTitle.font.size + spacingM;
this._bar2.pos = ex.vec(halfWidth, y); this._bar2.pos = ex.vec(halfWidth, y);
y += this._bar2.height + spacingL; y += this._bar2.height + spacingL;
+4 -5
View File
@@ -1,6 +1,6 @@
import * as ex from 'excalibur'; import * as ex from "excalibur";
import { LobbyScene } from "./Scenes/LobbyScene"; import { LobbyScene } from "./Scenes/LobbyScene";
import { Connection } from './Connection'; import { Connection } from "./Connection";
(async () => { (async () => {
const connection = new Connection(); const connection = new Connection();
@@ -12,13 +12,12 @@ import { Connection } from './Connection';
width: 0, width: 0,
height: 0, height: 0,
displayMode: ex.DisplayMode.FillScreen, displayMode: ex.DisplayMode.FillScreen,
scenes: { lobby: lobbyScene}, scenes: { lobby: lobbyScene },
backgroundColor: ex.Color.fromHex("23213b"), backgroundColor: ex.Color.fromHex("23213b"),
}); });
game.toggleDebug(); game.toggleDebug();
game.start().then(async () => { game.start().then(async () => {
await game.goToScene('lobby'); await game.goToScene("lobby");
}); });
})(); })();