diff --git a/backend.js b/backend.js index 6c1d6ac..a87421f 100644 --- a/backend.js +++ b/backend.js @@ -718,10 +718,12 @@ io.on('connection', (socket) => { const ENEMYSPAWNRATE = 1000 + function spawnEnemies(){ enemyId++ - const radius = 8 + Math.random() * 8 - const speed = 1 + Math.random() * 2 + const factor = 1 + Math.random() // 1~2 + const radius = Math.round(factor*8) // 8~16 + const speed = 3 - factor // 1~2 let x let y @@ -734,7 +736,8 @@ function spawnEnemies(){ } // back ticks: ~ type this without shift! - const color = `hsl(${Math.random()*360},50%,50%)` // [0~360, saturation %, lightness %] + const colorfactor = 100 + Math.round(factor*60) + const color = `hsl(${colorfactor},50%,50%)` // [0~360, saturation %, lightness %] const angle = Math.atan2(SCREENHEIGHT/2 - y, SCREENWIDTH/2 - x) const velocity = { x: Math.cos(angle)*speed, @@ -743,7 +746,7 @@ function spawnEnemies(){ const damage = 1 const myID = enemyId - const health = 1 // default 1 + const health = factor*2 // (new Enemy({ex, ey, eradius, ecolor, evelocity})) backEndEnemies[enemyId] = { diff --git a/public/js/classes/Items.js b/public/js/classes/Items.js index 0ca93d6..5b0f052 100644 --- a/public/js/classes/Items.js +++ b/public/js/classes/Items.js @@ -69,6 +69,8 @@ class Gun extends Item { } restock(playerId){ + if (!frontEndPlayers[playerId]){return} // safe - player deleted white recharging may inccur an error + const ammoList = frontEndPlayers[playerId].ammoList //console.log(ammoList) const typetemp = this.ammotype diff --git a/public/js/eventListeners.js b/public/js/eventListeners.js index 16a0d7f..9d82911 100644 --- a/public/js/eventListeners.js +++ b/public/js/eventListeners.js @@ -25,6 +25,7 @@ function shootProj(event){ let currentHoldingItemId = frontEndPlayers[socket.id].inventory[inventoryPointer] // if it is 0, it is fist let currentHoldingItem = frontEndItems[currentHoldingItemId] + if (!currentHoldingItem) {return} // undefined case if ((currentHoldingItem.itemtype==='consumable')){ // eat // dont need to check amount since we will delete item if eaten @@ -40,14 +41,14 @@ function shootProj(event){ // decrease amount here (if needed in future) - fireTimeout = window.setTimeout(function(){socket.emit('consume',{ + fireTimeout = window.setTimeout(function(){ if (frontEndPlayers[socket.id]){socket.emit('consume',{ itemName: currentHoldingItem.name, playerId: socket.id, healamount: currentHoldingItem.healamount, deleteflag: true, // current version, delete right away itemid: currentHoldingItemId, currentSlot: frontEndPlayers[socket.id].currentSlot, - }); + }) }; clearTimeout(fireTimeout); listen = true},CONSUMERATE) @@ -192,7 +193,7 @@ function reloadGun(){ reloadTimeout = window.setTimeout(function(){currentHoldingItem.restock(socket.id); //console.log(`${currentGunName} ammo: ${currentHoldingItem.ammo}`); - clearTimeout(reloadTimeout);frontEndPlayers[socket.id].reloading = false; + clearTimeout(reloadTimeout); if (frontEndPlayers[socket.id]) {frontEndPlayers[socket.id].reloading = false}; listen = true}, GUNRELOADRATE) } diff --git a/public/js/frontend.js b/public/js/frontend.js index 46403f9..50bb80d 100644 --- a/public/js/frontend.js +++ b/public/js/frontend.js @@ -690,6 +690,7 @@ document.querySelector('#usernameForm').addEventListener('submit', (event) => { // hide key info //document.querySelector(`div[data-id="keyinfos"]`).style.display = 'none' resetKeys() + socket.emit('initGame', {username: document.querySelector('#usernameInput').value, width: canvas.width, height: canvas.height}) })