This commit is contained in:
Daniel Maixner 2023-09-02 12:07:05 +02:00
parent 2c02de8af1
commit c5918e851b
4 changed files with 22 additions and 29 deletions

View File

@ -1,6 +1,6 @@
import {EventProcessor} from "./EventProcessor.js";
import {Player} from "./Player.js";
import {InventorySlot, ItemId, SoundType} from "./Enums.js";
import {InventorySlot, SoundType} from "./Enums.js";
import {SoundRepository} from "./SoundRepository.js";
export class Game {
@ -21,9 +21,15 @@ export class Game {
#hudDebounceTicks = 1
#bombTimerId = null;
#eventProcessor
#dropItems = [];
#throwables = [];
#dropItems = {};
#throwables = {};
#roundIntervalIds = [];
#playerSlotsVisibleModels = [
InventorySlot.SLOT_KNIFE, InventorySlot.SLOT_PRIMARY, InventorySlot.SLOT_SECONDARY,
InventorySlot.SLOT_BOMB, InventorySlot.SLOT_GRENADE_DECOY, InventorySlot.SLOT_GRENADE_MOLOTOV,
InventorySlot.SLOT_GRENADE_SMOKE, InventorySlot.SLOT_GRENADE_FLASH, InventorySlot.SLOT_GRENADE_HE,
InventorySlot.SLOT_TASER, InventorySlot.SLOT_KIT,
]
score = null
bombDropPosition = null
alivePlayers = [0, 0]
@ -31,19 +37,6 @@ export class Game {
players = []
playerMe = null
playerSpectate = null
#playerSlotsVisibleModels = [
InventorySlot.SLOT_KNIFE,
InventorySlot.SLOT_PRIMARY,
InventorySlot.SLOT_SECONDARY,
InventorySlot.SLOT_BOMB,
InventorySlot.SLOT_GRENADE_DECOY,
InventorySlot.SLOT_GRENADE_MOLOTOV,
InventorySlot.SLOT_GRENADE_SMOKE,
InventorySlot.SLOT_GRENADE_FLASH,
InventorySlot.SLOT_GRENADE_HE,
InventorySlot.SLOT_TASER,
InventorySlot.SLOT_KIT,
]
constructor(world, hud, stats) {
this.#world = world
@ -53,17 +46,19 @@ export class Game {
this.#soundRepository = new SoundRepository((...args) => world.playSound(...args))
}
pause(msg, score, timeMs) {
this.#paused = true
console.log("Pause: " + msg + " for " + timeMs + "ms")
#roundReset() {
clearInterval(this.#bombTimerId)
this.#roundIntervalIds.forEach((id) => clearInterval(id))
this.#roundIntervalIds = []
Object.keys(this.#dropItems).forEach((id) => this.itemPickUp(id))
this.#dropItems = []
Object.keys(this.#throwables).forEach((id) => this.removeGrenade(id))
this.#throwables = []
this.#world.reset()
}
pause(msg, score, timeMs) {
this.#paused = true
console.log("Pause: " + msg + " for " + timeMs + "ms")
this.#roundReset()
const game = this
this.players.forEach(function (player) {
@ -175,9 +170,6 @@ export class Game {
this.playerHit(data, true)
}
if (data.type === SoundType.ITEM_PICKUP) {
if (data.item.id === ItemId.Bomb && spectatorId === data.player) {
this.#dropItems[data.extra.id].visible = false
}
this.itemPickUp(data.extra.id)
}
if (data.type === SoundType.ITEM_DROP_AIR) {

View File

@ -225,7 +225,7 @@ export class HUD {
if (player.ammo === null) {
this.#elements.ammo.innerText = Enum.ItemIdToName[player.item.id]
} else {
this.#elements.ammo.innerText = `${Enum.ItemIdToName[player.item.id]} \u00a0 ${player.ammo} / ${player.ammoReserve}`
this.#elements.ammo.innerText = `${Enum.ItemIdToName[player.item.id]} \u00a0 ${player.ammo} / ${player.ammoReserve}`
}
let myTeamIndex = this.#game.playerMe.getTeamIndex()

View File

@ -2,7 +2,6 @@ import {ItemId} from "./Enums.js";
export class ModelRepository {
#gltfLoader
#objectLoader
#textureLoader
#models = {}
#meshes = {}
@ -18,9 +17,7 @@ export class ModelRepository {
constructor() {
this.#gltfLoader = new THREE.GLTFLoader()
this.#objectLoader = new THREE.ObjectLoader()
this.#textureLoader = new THREE.TextureLoader()
}
#loadModel(url) {

View File

@ -21,6 +21,7 @@ export class World {
init(mapName, setting) {
const scene = new THREE.Scene()
scene.name = 'MainScene'
scene.background = new THREE.Color(0xdadada)
const promises = []
@ -204,13 +205,16 @@ export class World {
reset() {
this.clearDecals()
const bomb = this.#modelRepository.getBomb()
if (bomb.parent && bomb.parent.type === 'Scene') {
if (bomb.parent && bomb.parent.name === 'MainScene') {
bomb.visible = false
}
}
destroyObject(object) {
if (object.name === `item-${Enum.ItemId.Bomb}`) {
if (object.parent && object.parent.name === 'MainScene') {
object.visible = false
}
return
}