mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 03:38:58 +00:00
setup method
This commit is contained in:
parent
851cdb7ead
commit
dedbbf614b
@ -78,12 +78,52 @@ export class Game extends Component {
|
|||||||
Game.instance = this;
|
Game.instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async playGame(
|
public async play(userData: UserData, settings: GameSettings, translationData: TranslationData, testValues?: TestValues): Promise<GameResult> {
|
||||||
userData: UserData,
|
await this.setup(userData, settings, translationData, testValues);
|
||||||
settings: GameSettings,
|
|
||||||
translationData: TranslationData,
|
this.gamePauser.resume();
|
||||||
testValues?: TestValues
|
this.blackScreen.active = false;
|
||||||
): Promise<GameResult> {
|
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();
|
await requireAppRootAsync();
|
||||||
this.gameCanvas.cameraComponent = AppRoot.Instance.MainCamera;
|
this.gameCanvas.cameraComponent = AppRoot.Instance.MainCamera;
|
||||||
|
|
||||||
@ -175,45 +215,6 @@ export class Game extends Component {
|
|||||||
this.diagonalProjectileLauncher,
|
this.diagonalProjectileLauncher,
|
||||||
this.haloProjectileLauncher
|
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 {
|
private createPlayerData(settings: PlayerSettings, metaUpgrades: MetaUpgrades): PlayerData {
|
||||||
|
@ -36,7 +36,7 @@ export class TestGameRunner extends Component {
|
|||||||
testUserData.game.metaUpgrades.goldGathererLevel = this.goldGathererLevel;
|
testUserData.game.metaUpgrades.goldGathererLevel = this.goldGathererLevel;
|
||||||
|
|
||||||
const settings = this.getTimeModifiedSettings(AppRoot.Instance.Settings);
|
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 {
|
private getTimeModifiedSettings(settings: GameSettings): GameSettings {
|
||||||
|
@ -25,7 +25,7 @@ export class GameRunner {
|
|||||||
director.loadScene("Game");
|
director.loadScene("Game");
|
||||||
const userData: UserData = AppRoot.Instance.LiveUserData;
|
const userData: UserData = AppRoot.Instance.LiveUserData;
|
||||||
while (Game.Instance == null) await delay(10);
|
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;
|
userData.game.goldCoins += result.goldCoins;
|
||||||
|
|
||||||
if (userData.game.highscore < result.score) {
|
if (userData.game.highscore < result.score) {
|
||||||
|
Loading…
Reference in New Issue
Block a user