diff --git a/src/frontend/src/GameElements/Title.ts b/src/frontend/src/GameElements/Title.ts new file mode 100644 index 0000000..ae69483 --- /dev/null +++ b/src/frontend/src/GameElements/Title.ts @@ -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; + } +} diff --git a/src/frontend/src/Scenes/LobbyScene.ts b/src/frontend/src/Scenes/LobbyScene.ts index e8c0d92..187084d 100644 --- a/src/frontend/src/Scenes/LobbyScene.ts +++ b/src/frontend/src/Scenes/LobbyScene.ts @@ -1,15 +1,14 @@ import * as ex from 'excalibur'; import { spacingL, spacingM } from '../utils/formattingUtils'; -import { subTitleFont, titleFont } from '../utils/fontUtil'; import { Cups } from '../Cups'; import { GameState } from '../GameState'; import { GameStateScene } from './GameStateScene'; import { PlayerListScreenElement } from '../ScreenElements/PlayerListScreenElement'; import { TitledListScreenElement } from '../ScreenElements/TitledListScreenElement'; -import { Text } from '../ScreenElements/Text'; import { Button } from '../ScreenElements/Button'; import { PlayerNameInput } from '../GameElements/PlayerNameInput'; import { Connection, GameMessageEvent } from '../Connection'; +import { Title } from '../GameElements/Title'; const tableWidth = 400; const maxPlayers = 2; @@ -20,13 +19,12 @@ export class LobbyScene extends GameStateScene { private _table: ex.ScreenElement = null!; private _cups: ex.ScreenElement = null!; + private _title: Title = null!; + private _bar1: ex.ScreenElement = null!; private _bar2: ex.ScreenElement = null!; private _bar3: ex.ScreenElement = null!; - private _title: Text = null!; - private _subTitle: Text = null!; - private _playerList: PlayerListScreenElement = null!; private _spectatorsList: TitledListScreenElement = null!; @@ -77,23 +75,9 @@ export class LobbyScene extends GameStateScene { this.add(this._cups); // Title - this._title = new Text({ - text: "Auto Beer Pong", - font: titleFont, - }); - this._title.anchor.setTo(0.5, 0); + this._title = new 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.labels = ["Dubbel"]; 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.anchor = ex.vec(0.5, 0); + engine.screen.events.on("resize", () => this._updatePositions()); + this._updateVisibility(); this._updatePositions(); } @@ -167,11 +153,8 @@ export class LobbyScene extends GameStateScene { this._bar1.pos = ex.vec(halfWidth, y); y += this._bar1.height + spacingM; - this._title.pos = ex.vec(halfWidth, y); - y += this._title.font.size + spacingM; - - this._subTitle.pos = ex.vec(halfWidth, y); - y += this._subTitle.font.size + spacingM; + this._title.pos = ex.vec(halfWidth, y); + y += this._title.height + spacingM; this._bar2.pos = ex.vec(halfWidth, y); y += this._bar2.height + spacingL; diff --git a/src/frontend/src/main.ts b/src/frontend/src/main.ts index 68789f4..ab4ca60 100644 --- a/src/frontend/src/main.ts +++ b/src/frontend/src/main.ts @@ -1,24 +1,23 @@ -import * as ex from 'excalibur'; +import * as ex from "excalibur"; import { LobbyScene } from "./Scenes/LobbyScene"; -import { Connection } from './Connection'; +import { Connection } from "./Connection"; (async () => { const connection = new Connection(); - connection.connect(); + connection.connect(); const lobbyScene = new LobbyScene(connection); - const game = new ex.Engine({ + const game = new ex.Engine({ width: 0, height: 0, displayMode: ex.DisplayMode.FillScreen, - scenes: { lobby: lobbyScene}, + scenes: { lobby: lobbyScene }, backgroundColor: ex.Color.fromHex("23213b"), }); game.toggleDebug(); - game.start().then(async () => { - await game.goToScene('lobby'); + await game.goToScene("lobby"); }); })();