setup method

This commit is contained in:
Martin 2023-01-05 09:53:16 +01:00
parent 851cdb7ead
commit dedbbf614b
3 changed files with 48 additions and 47 deletions

View File

@ -78,12 +78,52 @@ export class Game extends Component {
Game.instance = this;
}
public async playGame(
userData: UserData,
settings: GameSettings,
translationData: TranslationData,
testValues?: TestValues
): Promise<GameResult> {
public async play(userData: UserData, settings: GameSettings, translationData: TranslationData, testValues?: TestValues): Promise<GameResult> {
await this.setup(userData, settings, translationData, testValues);
this.gamePauser.resume();
this.blackScreen.active = false;
AppRoot.Instance.ScreenFader.playClose();
while (!this.gameResult.hasExitManually && this.player.Health.IsAlive) await delay(100);
this.gamePauser.pause();
Game.instance = null;
this.gameResult.score = this.timeAlive;
if (!this.gameResult.hasExitManually) {
await delay(2000);
}
return this.gameResult;
}
public exitGame(): void {
this.gameResult.hasExitManually = true;
}
public update(deltaTime: number): void {
if (this.gamePauser.IsPaused) return;
this.player.gameTick(deltaTime);
this.playerCollisionSystem.gameTick(deltaTime);
this.enemyManager.gameTick(deltaTime);
this.haloProjectileLauncher.gameTick(deltaTime);
this.horizontalProjectileLauncher.gameTick(deltaTime);
this.diagonalProjectileLauncher.gameTick(deltaTime);
this.enemyAxeProjectileLauncher.gameTick(deltaTime);
this.enemyMagicOrbProjectileLauncher.gameTick(deltaTime);
this.itemAttractor.gameTick(deltaTime);
this.background.gameTick();
this.timeAlive += deltaTime;
this.gameUI.updateTimeAlive(this.timeAlive);
AppRoot.Instance.MainCamera.node.setWorldPosition(this.player.node.worldPosition);
this.gameUI.node.setWorldPosition(this.player.node.worldPosition);
}
private async setup(userData: UserData, settings: GameSettings, translationData: TranslationData, testValues: TestValues): Promise<void> {
await requireAppRootAsync();
this.gameCanvas.cameraComponent = AppRoot.Instance.MainCamera;
@ -175,45 +215,6 @@ export class Game extends Component {
this.diagonalProjectileLauncher,
this.haloProjectileLauncher
);
this.gamePauser.resume();
this.blackScreen.active = false;
AppRoot.Instance.ScreenFader.playClose();
while (!this.gameResult.hasExitManually && this.player.Health.IsAlive) await delay(100);
this.gamePauser.pause();
Game.instance = null;
this.gameResult.score = this.timeAlive;
if (!this.gameResult.hasExitManually) {
await delay(2000);
}
return this.gameResult;
}
public exitGame(): void {
this.gameResult.hasExitManually = true;
}
public update(deltaTime: number): void {
if (this.gamePauser.IsPaused) return;
this.player.gameTick(deltaTime);
this.playerCollisionSystem.gameTick(deltaTime);
this.enemyManager.gameTick(deltaTime);
this.haloProjectileLauncher.gameTick(deltaTime);
this.horizontalProjectileLauncher.gameTick(deltaTime);
this.diagonalProjectileLauncher.gameTick(deltaTime);
this.enemyAxeProjectileLauncher.gameTick(deltaTime);
this.enemyMagicOrbProjectileLauncher.gameTick(deltaTime);
this.itemAttractor.gameTick(deltaTime);
this.background.gameTick();
this.timeAlive += deltaTime;
this.gameUI.updateTimeAlive(this.timeAlive);
AppRoot.Instance.MainCamera.node.setWorldPosition(this.player.node.worldPosition);
this.gameUI.node.setWorldPosition(this.player.node.worldPosition);
}
private createPlayerData(settings: PlayerSettings, metaUpgrades: MetaUpgrades): PlayerData {

View File

@ -36,7 +36,7 @@ export class TestGameRunner extends Component {
testUserData.game.metaUpgrades.goldGathererLevel = this.goldGathererLevel;
const settings = this.getTimeModifiedSettings(AppRoot.Instance.Settings);
Game.Instance.playGame(testUserData, settings, AppRoot.Instance.TranslationData, { startTime: this.startTime, startXP: this.startXP });
Game.Instance.play(testUserData, settings, AppRoot.Instance.TranslationData, { startTime: this.startTime, startXP: this.startXP });
}
private getTimeModifiedSettings(settings: GameSettings): GameSettings {

View File

@ -25,7 +25,7 @@ export class GameRunner {
director.loadScene("Game");
const userData: UserData = AppRoot.Instance.LiveUserData;
while (Game.Instance == null) await delay(10);
const result: GameResult = await Game.Instance.playGame(userData, AppRoot.Instance.Settings, AppRoot.Instance.TranslationData);
const result: GameResult = await Game.Instance.play(userData, AppRoot.Instance.Settings, AppRoot.Instance.TranslationData);
userData.game.goldCoins += result.goldCoins;
if (userData.game.highscore < result.score) {