Faster levels after reloads fixed (how, idk)
This commit is contained in:
parent
4aa6289f50
commit
61a61db761
@ -9,6 +9,7 @@ import { DirectionEnum } from "../Tanks/directionEnum";
|
|||||||
import { SoundEnum, SoundManager } from "./soundManager";
|
import { SoundEnum, SoundManager } from "./soundManager";
|
||||||
|
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
|
import { isThursday } from "date-fns";
|
||||||
|
|
||||||
export class GameField {
|
export class GameField {
|
||||||
|
|
||||||
@ -33,6 +34,8 @@ export class GameField {
|
|||||||
this.tank = new Tank(Constants.PLAYER_TANK_ID_IMAGE.getValue(), 0, 18 * 16, this.collisionManager);
|
this.tank = new Tank(Constants.PLAYER_TANK_ID_IMAGE.getValue(), 0, 18 * 16, this.collisionManager);
|
||||||
this.aiTanks = new AITankManager(this.collisionManager);
|
this.aiTanks = new AITankManager(this.collisionManager);
|
||||||
this.collisionManager.setMainTank(this.tank);
|
this.collisionManager.setMainTank(this.tank);
|
||||||
|
|
||||||
|
this.lastRequest = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//add all tiles here!
|
//add all tiles here!
|
||||||
@ -86,12 +89,15 @@ export class GameField {
|
|||||||
this.aiTanks.setCount(this.map._enemiesCount);
|
this.aiTanks.setCount(this.map._enemiesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
async play(level) {
|
async play(level, firstTime) {
|
||||||
this.ctx.clearRect(0, 0, this.width, this.height);
|
this.ctx.clearRect(0, 0, this.width, this.height);
|
||||||
|
this.tank.deathCount = 20;
|
||||||
|
this.tank.isDestroyed = false;
|
||||||
this.tank.x = Constants.TANK_DEFAULT_SPAWN_X.getValue();
|
this.tank.x = Constants.TANK_DEFAULT_SPAWN_X.getValue();
|
||||||
this.tank.y = Constants.TANK_DEFAULT_SPAWN_Y.getValue();
|
this.tank.y = Constants.TANK_DEFAULT_SPAWN_Y.getValue();
|
||||||
this.aiTanks = new AITankManager(this.collisionManager);
|
this.aiTanks._activeTanks = [];
|
||||||
if (!this.tileset || !this.map || this.map.mapLevel != level) {
|
this.collisionManager._aiTanks = [];
|
||||||
|
|
||||||
$(".loading").show();
|
$(".loading").show();
|
||||||
$(".text-loading").show();
|
$(".text-loading").show();
|
||||||
$(".start-level-button").hide();
|
$(".start-level-button").hide();
|
||||||
@ -102,21 +108,34 @@ export class GameField {
|
|||||||
$(".text-loading").hide();
|
$(".text-loading").hide();
|
||||||
$(".start-level-button").show();
|
$(".start-level-button").show();
|
||||||
|
|
||||||
|
if (firstTime) {
|
||||||
$(".start-level-button").on("click", () => {
|
$(".start-level-button").on("click", () => {
|
||||||
$(".loading").hide();
|
$(".loading").hide();
|
||||||
this.soundManager.playSound(SoundEnum.GameStart);
|
this.soundManager.playSound(SoundEnum.GameStart);
|
||||||
requestAnimationFrame(() => this.gameLoop());
|
requestAnimationFrame(() => this.gameLoop());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$(".loading").hide();
|
||||||
|
requestAnimationFrame(() => this.gameLoop());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lose() {
|
lose() {
|
||||||
this.soundManager.playSound(SoundEnum.GameOver);
|
this.soundManager.playSound(SoundEnum.GameOver);
|
||||||
requestAnimationFrame(() => this.drawFieldRecursive())
|
requestAnimationFrame(() => this.drawFieldRecursive())
|
||||||
|
setTimeout(() => {
|
||||||
|
cancelAnimationFrame(this.lastRequest);
|
||||||
|
this.lastRequest = undefined;
|
||||||
|
this.play(1, false);
|
||||||
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
win() {
|
win() {
|
||||||
this.play(this.map.mapLevel + 1);
|
cancelAnimationFrame(this.lastRequest);
|
||||||
|
this.lastRequest = undefined;
|
||||||
|
setTimeout(() => { this.play(this.map.mapLevel + 1, false); }, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -138,16 +157,15 @@ export class GameField {
|
|||||||
|
|
||||||
this.drawField();
|
this.drawField();
|
||||||
|
|
||||||
requestAnimationFrame(() => this.gameLoop());
|
this.lastRequest = requestAnimationFrame(() => this.gameLoop());
|
||||||
}
|
}
|
||||||
|
|
||||||
drawFieldRecursive() {
|
drawFieldRecursive() {
|
||||||
this.drawField();
|
this.drawField();
|
||||||
requestAnimationFrame(() => this.drawFieldRecursive());
|
this.lastRequest = requestAnimationFrame(() => this.drawFieldRecursive());
|
||||||
}
|
}
|
||||||
|
|
||||||
drawField() {
|
drawField() {
|
||||||
|
|
||||||
let lateDraw = [];
|
let lateDraw = [];
|
||||||
|
|
||||||
for (let x = 0; x < this.map.width; x += 1) {
|
for (let x = 0; x < this.map.width; x += 1) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user