feat: added checkpoints generator and timer
This commit is contained in:
parent
a05c0a1721
commit
797d571b76
|
@ -52,7 +52,7 @@
|
|||
"possibility": 1
|
||||
}
|
||||
],
|
||||
"checkPoint": [5, 19, 5, 5]
|
||||
"startCheckPoint": [25, 19, 5, 5]
|
||||
},
|
||||
"exit": {
|
||||
"width": 30,
|
||||
|
@ -76,7 +76,8 @@
|
|||
"width": 3,
|
||||
"alt_tile": [0, 478]
|
||||
}
|
||||
]
|
||||
],
|
||||
"endCheckPoint": [20, 16, 5, 5]
|
||||
},
|
||||
"rooms": [
|
||||
{
|
||||
|
|
|
@ -99,36 +99,44 @@ export default class GameLevel extends Scene {
|
|||
protected gameStateStack: Stack<GameState>;
|
||||
|
||||
// Story
|
||||
private storytextLabel: Label;
|
||||
private storyLayer: Layer;
|
||||
private story: Story;
|
||||
private storyProgress: number;
|
||||
private storySprites: Array<Sprite>;
|
||||
private storyBGMs: Array<string>;
|
||||
private currentSpeaker: string;
|
||||
private currentContent: string;
|
||||
protected storytextLabel: Label;
|
||||
protected storyLayer: Layer;
|
||||
protected story: Story;
|
||||
protected storyProgress: number;
|
||||
protected storySprites: Array<Sprite>;
|
||||
protected storyBGMs: Array<string>;
|
||||
protected currentSpeaker: string;
|
||||
protected currentContent: string;
|
||||
|
||||
//buffs layer
|
||||
buffLayer: Layer;
|
||||
buffButton1 : Button;
|
||||
buffLabel1 : Label;
|
||||
buffButton2 : Button;
|
||||
buffLabel2 : Label;
|
||||
buffButton3 : Button;
|
||||
buffLabel3: Label;
|
||||
buffs: Array<Buff>;
|
||||
protected buffLayer: Layer;
|
||||
protected buffButton1 : Button;
|
||||
protected buffLabel1 : Label;
|
||||
protected buffButton2 : Button;
|
||||
protected buffLabel2 : Label;
|
||||
protected buffButton3 : Button;
|
||||
protected buffLabel3: Label;
|
||||
protected buffs: Array<Buff>;
|
||||
|
||||
//pause layer
|
||||
pauseLayer: Layer;
|
||||
pauseText: Label;
|
||||
pauseInput: TextInput;
|
||||
pauseSubmit: Label;
|
||||
pauseCheatText: Label;
|
||||
protected pauseLayer: Layer;
|
||||
protected pauseText: Label;
|
||||
protected pauseInput: TextInput;
|
||||
protected pauseSubmit: Label;
|
||||
protected pauseCheatText: Label;
|
||||
|
||||
protected randomSeed: number;
|
||||
protected rmg: RandomMapGenerator;
|
||||
protected map: TiledTilemapData;
|
||||
|
||||
protected startCheckPoint: Rect;
|
||||
protected endCheckPoint: Rect;
|
||||
protected touchedStartCheckPoint: boolean = false;
|
||||
protected touchedEndCheckPoint: boolean = false;
|
||||
protected static gameTimer: number = 0;
|
||||
protected gameStarted: boolean = false;
|
||||
protected timerLable: Label;
|
||||
|
||||
startpos: Vec2;
|
||||
loadScene(): void {
|
||||
//can load player sprite here
|
||||
|
@ -198,8 +206,10 @@ export default class GameLevel extends Scene {
|
|||
this.subscribeToEvents();
|
||||
this.addUI();
|
||||
|
||||
const checkPoint = this.rmg.getCheckPoint();
|
||||
this.addLevelEnd(new Vec2(checkPoint[0], checkPoint[1]), new Vec2(checkPoint[2], checkPoint[3]));
|
||||
let startCheckPoint = this.rmg.getStartCheckPoint();
|
||||
this.startCheckPoint = this.addCheckPoint(new Vec2(startCheckPoint[0], startCheckPoint[1]), new Vec2(startCheckPoint[2], startCheckPoint[3]), "startStory", "startTimer");
|
||||
let endCheckPoint = this.rmg.getEndCheckPoint();
|
||||
this.endCheckPoint = this.addCheckPoint(new Vec2(endCheckPoint[0], endCheckPoint[1]), new Vec2(endCheckPoint[2], endCheckPoint[3]), "endStory", "nextLevel");
|
||||
|
||||
// Create an enemies array
|
||||
// Send the player and enemies to the battle manager
|
||||
|
@ -250,7 +260,30 @@ export default class GameLevel extends Scene {
|
|||
|
||||
|
||||
updateScene(deltaT: number){
|
||||
|
||||
if (this.gameStateStack.peek() === GameState.GAMING) {
|
||||
if (this.gameStarted) {
|
||||
GameLevel.gameTimer += deltaT;
|
||||
let minutes = Math.floor(GameLevel.gameTimer / 60);
|
||||
if (minutes >= 10) {
|
||||
this.timerLable.text = minutes.toString();
|
||||
}
|
||||
else {
|
||||
this.timerLable.text = "0" + minutes.toString();
|
||||
}
|
||||
let seconds = Math.floor(GameLevel.gameTimer % 60);
|
||||
if (seconds >= 10) {
|
||||
this.timerLable.text += ":" + seconds.toString();
|
||||
}
|
||||
else {
|
||||
this.timerLable.text += ":0" + seconds.toString();
|
||||
}
|
||||
this.timerLable.textColor = Color.BLACK;
|
||||
}
|
||||
else {
|
||||
this.timerLable.textColor = Color.RED;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle events and update the UI if needed
|
||||
while(this.receiver.hasNextEvent()){
|
||||
let event = this.receiver.getNextEvent();
|
||||
|
@ -326,6 +359,18 @@ export default class GameLevel extends Scene {
|
|||
this.sceneManager.changeToScene(GameOver, {});
|
||||
}
|
||||
break;
|
||||
case "startStory":
|
||||
this.playStartStory();
|
||||
break;
|
||||
case "endStory":
|
||||
this.playEndStory();
|
||||
break;
|
||||
case "startTimer":
|
||||
this.startTimer();
|
||||
break;
|
||||
case "nextLevel":
|
||||
this.goToNextLevel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -435,10 +480,10 @@ export default class GameLevel extends Scene {
|
|||
}
|
||||
*/
|
||||
|
||||
if (InputWrapper.isInventoryJustPressed()) {
|
||||
console.log("LoadingStory");
|
||||
this.storyLoader("shattered_sword_assets/jsons/story.json");
|
||||
}
|
||||
// if (InputWrapper.isInventoryJustPressed()) {
|
||||
// console.log("LoadingStory");
|
||||
// this.storyLoader("shattered_sword_assets/jsons/story.json");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
@ -503,6 +548,10 @@ export default class GameLevel extends Scene {
|
|||
this.receiver.subscribe("buff2");
|
||||
this.receiver.subscribe("buff3");
|
||||
this.receiver.subscribe("cheat");
|
||||
this.receiver.subscribe("startStory");
|
||||
this.receiver.subscribe("startTimer");
|
||||
this.receiver.subscribe("endStory");
|
||||
this.receiver.subscribe("nextLevel");
|
||||
}
|
||||
|
||||
// TODO -
|
||||
|
@ -693,9 +742,12 @@ export default class GameLevel extends Scene {
|
|||
this.pauseSubmit.onClickEventId = "cheat";
|
||||
this.pauseSubmit.borderWidth = 3;
|
||||
|
||||
this.livesCountLabel = <Label>this.add.uiElement(UIElementType.LABEL, "UI", {position: new Vec2(600, 30), text:"Lives: "});
|
||||
this.livesCountLabel = <Label>this.add.uiElement(UIElementType.LABEL, "UI", {position: new Vec2(this.viewport.getHalfSize().x*2 - 100, 30), text:"Lives: "});
|
||||
this.livesCountLabel.textColor = Color.YELLOW;
|
||||
this.livesCountLabel.fontSize = 25;
|
||||
|
||||
this.timerLable = <Label>this.add.uiElement(UIElementType.LABEL, "UI", {position: new Vec2(Math.floor(this.viewport.getHalfSize().x), 30), text: "00:00"});
|
||||
this.timerLable.fontSize = 60;
|
||||
}
|
||||
|
||||
//TODO - determine whether we will have weapon datatype
|
||||
|
@ -738,8 +790,6 @@ export default class GameLevel extends Scene {
|
|||
* Initializes the player
|
||||
*/
|
||||
protected initPlayer(): void {
|
||||
|
||||
|
||||
//create the inventory
|
||||
let inventory = new InventoryManager(this, 1, "inventorySlot", new Vec2(16, 16), 4, "slots1", "items1");
|
||||
|
||||
|
@ -850,8 +900,6 @@ export default class GameLevel extends Scene {
|
|||
|
||||
//TODO - give each enemy unique weapon
|
||||
protected initializeEnemies( enemies: Enemy[]){
|
||||
|
||||
|
||||
let actionsDefault = [new AttackAction(3, [Statuses.IN_RANGE], [Statuses.REACHED_GOAL]),
|
||||
new Move(2, [], [Statuses.IN_RANGE], {inRange: 60}),
|
||||
];
|
||||
|
@ -936,11 +984,12 @@ export default class GameLevel extends Scene {
|
|||
|
||||
}
|
||||
|
||||
protected addLevelEnd(startingTile: Vec2, size: Vec2): void {
|
||||
this.levelEndArea = <Rect>this.add.graphic(GraphicType.RECT, "primary", {position: startingTile.scale(32), size: size.scale(32)});
|
||||
this.levelEndArea.addPhysics(undefined, undefined, false, true);
|
||||
// this.levelEndArea.setTrigger("player", somelevelendevent, null);
|
||||
this.levelEndArea.color = new Color(0, 0, 0, 0);
|
||||
protected addCheckPoint(startingTile: Vec2, size: Vec2, enter: string, exit: string): Rect {
|
||||
let checkPoint = <Rect>this.add.graphic(GraphicType.RECT, "primary", {position: startingTile.scale(32), size: size.scale(32)});
|
||||
checkPoint.addPhysics(undefined, undefined, false, true);
|
||||
checkPoint.setTrigger("player", enter, null);
|
||||
checkPoint.color = new Color(0, 0, 0, 0);
|
||||
return checkPoint;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1005,7 +1054,7 @@ export default class GameLevel extends Scene {
|
|||
* @param viewportCenter The center of the viewport
|
||||
* @param viewportSize The size of the viewport
|
||||
*/
|
||||
playerFalloff(viewportCenter: Vec2, viewportSize: Vec2):void{
|
||||
protected playerFalloff(viewportCenter: Vec2, viewportSize: Vec2):void{
|
||||
if(this.player.position.y >= viewportCenter.y +viewportSize.y/2.0){
|
||||
|
||||
this.player.position.set(this.playerSpawn.x,this.playerSpawn.y);
|
||||
|
@ -1018,7 +1067,36 @@ export default class GameLevel extends Scene {
|
|||
}
|
||||
|
||||
|
||||
async storyLoader(storyPath: string) {
|
||||
protected playStartStory() {
|
||||
if (!this.touchedStartCheckPoint) {
|
||||
this.touchedStartCheckPoint = true;
|
||||
this.storyLoader("shattered_sword_assets/jsons/story.json");
|
||||
this.startTimer();
|
||||
}
|
||||
}
|
||||
|
||||
protected playEndStory() {
|
||||
if (!this.touchedEndCheckPoint) {
|
||||
this.touchedEndCheckPoint = true;
|
||||
this.storyLoader("shattered_sword_assets/jsons/story.json");
|
||||
this.endTimer();
|
||||
}
|
||||
}
|
||||
|
||||
protected startTimer() {
|
||||
this.gameStarted = true;
|
||||
}
|
||||
|
||||
protected endTimer() {
|
||||
this.gameStarted = false;
|
||||
}
|
||||
|
||||
protected goToNextLevel() {
|
||||
console.log("goToNextLevel")
|
||||
}
|
||||
|
||||
|
||||
protected async storyLoader(storyPath: string) {
|
||||
if (this.gameStateStack.peek() === GameState.STORY) {
|
||||
return;
|
||||
}
|
||||
|
@ -1055,11 +1133,11 @@ export default class GameLevel extends Scene {
|
|||
this.updateStory();
|
||||
}
|
||||
|
||||
hasNextStory(): boolean {
|
||||
protected hasNextStory(): boolean {
|
||||
return this.gameStateStack.peek() === GameState.STORY && this.storyProgress + 1 < this.story.texts.length;
|
||||
}
|
||||
|
||||
updateStory() {
|
||||
protected updateStory() {
|
||||
if (this.hasNextStory()) {
|
||||
this.storyProgress++;
|
||||
let tmp = undefined;
|
||||
|
@ -1136,7 +1214,7 @@ export default class GameLevel extends Scene {
|
|||
}
|
||||
|
||||
// Cheat
|
||||
enableCheat() {
|
||||
protected enableCheat() {
|
||||
if (this.pauseInput.text.toUpperCase() === "UUDDLRLRBABA") {
|
||||
(<PlayerController>this.player._ai).godMode = true;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,8 @@ export class RoomTemplate {
|
|||
topLayer: Array<number>;
|
||||
entrances: Array<Entrance>;
|
||||
sprites?: Array<Sprite>;
|
||||
checkPoint?: [number, number, number, number];
|
||||
startCheckPoint?: [number, number, number, number];
|
||||
endCheckPoint?: [number, number, number, number];
|
||||
}
|
||||
|
||||
export class Corner {
|
||||
|
|
|
@ -25,7 +25,8 @@ export default class RandomMapGenerator {
|
|||
private exitFacing: Facing;
|
||||
private enemies: Array<Enemy>;
|
||||
private player: Vec2;
|
||||
private checkPoint: [number, number, number, number];
|
||||
private startCheckPoint: [number, number, number, number];
|
||||
private endCheckPoint: [number, number, number, number];
|
||||
|
||||
constructor(JSONFilePath: string, seed: any) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
@ -45,7 +46,8 @@ export default class RandomMapGenerator {
|
|||
this.rooms = new Array();
|
||||
this.enemies = new Array();
|
||||
this.player = new Vec2();
|
||||
this.checkPoint = [0,0,0,0];
|
||||
this.startCheckPoint = [0,0,0,0];
|
||||
this.endCheckPoint = [0, 0, 0, 0];
|
||||
let gen = require('random-seed');
|
||||
this.gen = new gen(seed);
|
||||
this.hasExit = false;
|
||||
|
@ -117,8 +119,12 @@ export default class RandomMapGenerator {
|
|||
return new Vec2(this.player.x - this.minX, this.player.y - this.minY);
|
||||
}
|
||||
|
||||
getCheckPoint(): [number, number, number, number] {
|
||||
return [this.checkPoint[0] - this.minX, this.checkPoint[1] - this.minY, this.checkPoint[2], this.checkPoint[3]];
|
||||
getStartCheckPoint(): [number, number, number, number] {
|
||||
return [this.startCheckPoint[0] - this.minX, this.startCheckPoint[1] - this.minY, this.startCheckPoint[2], this.startCheckPoint[3]];
|
||||
}
|
||||
|
||||
getEndCheckPoint(): [number, number, number, number] {
|
||||
return [this.endCheckPoint[0] - this.minX, this.endCheckPoint[1] - this.minY, this.endCheckPoint[2], this.endCheckPoint[3]];
|
||||
}
|
||||
|
||||
getEnemies(): Array<Enemy> {
|
||||
|
@ -378,10 +384,15 @@ export default class RandomMapGenerator {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (old.checkPoint) {
|
||||
this.checkPoint = [...old.checkPoint];
|
||||
this.checkPoint[0] += posX;
|
||||
this.checkPoint[1] += posY;
|
||||
if (old.startCheckPoint) {
|
||||
this.startCheckPoint = [...old.startCheckPoint];
|
||||
this.startCheckPoint[0] += posX;
|
||||
this.startCheckPoint[1] += posY;
|
||||
}
|
||||
if (old.endCheckPoint) {
|
||||
this.endCheckPoint = [...old.endCheckPoint];
|
||||
this.endCheckPoint[0] += posX;
|
||||
this.endCheckPoint[1] += posY;
|
||||
}
|
||||
if (posX < this.minX)
|
||||
this.minX = posX;
|
||||
|
|
Loading…
Reference in New Issue
Block a user