mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 11:48:54 +00:00
Linking highscore to game results
This commit is contained in:
parent
bef7505584
commit
9eab8522a2
@ -7,6 +7,7 @@ export class UserData {
|
|||||||
export class GameData {
|
export class GameData {
|
||||||
public goldCoins = 0;
|
public goldCoins = 0;
|
||||||
public metaUpgrades = new MetaUpgradesData();
|
public metaUpgrades = new MetaUpgradesData();
|
||||||
|
public highscore = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MetaUpgradesData {
|
export class MetaUpgradesData {
|
||||||
|
@ -59,7 +59,7 @@ export class Game extends Component {
|
|||||||
this.gamePauser.pause();
|
this.gamePauser.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async playGame(userData: UserData): Promise<number> {
|
public async playGame(userData: UserData): Promise<GameResult> {
|
||||||
const translationData = <TranslationData>this.translationAsset.json;
|
const translationData = <TranslationData>this.translationAsset.json;
|
||||||
const settings = <GameSettings>this.settingsAsset.json;
|
const settings = <GameSettings>this.settingsAsset.json;
|
||||||
const metaUpgrades = new MetaUpgrades(userData.game.metaUpgrades, settings.metaUpgrades);
|
const metaUpgrades = new MetaUpgrades(userData.game.metaUpgrades, settings.metaUpgrades);
|
||||||
@ -123,7 +123,7 @@ export class Game extends Component {
|
|||||||
await delay(1000000);
|
await delay(1000000);
|
||||||
this.gamePauser.pause();
|
this.gamePauser.pause();
|
||||||
Game.instance = null;
|
Game.instance = null;
|
||||||
return 1;
|
return { goldCoins: 1, score: Math.floor(this.timeAlive) };
|
||||||
}
|
}
|
||||||
|
|
||||||
public update(deltaTime: number): void {
|
public update(deltaTime: number): void {
|
||||||
@ -159,3 +159,8 @@ export class Game extends Component {
|
|||||||
return playerData;
|
return playerData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class GameResult {
|
||||||
|
public goldCoins = 0;
|
||||||
|
public score = 0;
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { director } from "cc";
|
import { director } from "cc";
|
||||||
import { AppRoot } from "../AppRoot/AppRoot";
|
import { AppRoot } from "../AppRoot/AppRoot";
|
||||||
import { UserData } from "../Game/Data/UserData";
|
import { UserData } from "../Game/Data/UserData";
|
||||||
import { Game } from "../Game/Game";
|
import { Game, GameResult } from "../Game/Game";
|
||||||
import { delay } from "../Services/Utils/AsyncUtils";
|
import { delay } from "../Services/Utils/AsyncUtils";
|
||||||
|
|
||||||
export class GameRunner {
|
export class GameRunner {
|
||||||
@ -25,8 +25,12 @@ export class GameRunner {
|
|||||||
director.loadScene("Game");
|
director.loadScene("Game");
|
||||||
const userData: UserData = AppRoot.Instance.SaveSystem.load();
|
const userData: UserData = AppRoot.Instance.SaveSystem.load();
|
||||||
while (Game.Instance == null) await delay(10);
|
while (Game.Instance == null) await delay(10);
|
||||||
const result: number = await Game.Instance.playGame();
|
const result: GameResult = await Game.Instance.playGame(userData);
|
||||||
userData.game.goldCoins += result;
|
userData.game.goldCoins += result.goldCoins;
|
||||||
|
|
||||||
|
if (userData.game.highscore < result.score) {
|
||||||
|
userData.game.highscore = result.score;
|
||||||
|
}
|
||||||
AppRoot.Instance.SaveSystem.save(userData);
|
AppRoot.Instance.SaveSystem.save(userData);
|
||||||
|
|
||||||
console.log("Gold coins: " + result);
|
console.log("Gold coins: " + result);
|
||||||
|
Loading…
Reference in New Issue
Block a user