diff --git a/gun infos.xlsx b/gun infos.xlsx index 00c78bf..b488f0c 100644 Binary files a/gun infos.xlsx and b/gun infos.xlsx differ diff --git a/public/frontend.js b/public/frontend.js index fe24068..61c62f0 100644 --- a/public/frontend.js +++ b/public/frontend.js @@ -447,20 +447,13 @@ function shootCheck(event){ //console.log("ready to fire") } -function CheckOnBoard(){ - return (frontEndPlayer && frontEndPlayer.onBoard) -} addEventListener('click', (event) => { - if (CheckOnBoard()){ - return - } shootCheck(event) }) - // periodically request backend server setInterval(()=>{ if (keys.f.pressed){ @@ -472,10 +465,6 @@ setInterval(()=>{ //socket.emit('keydown',{keycode:'KeyG'}) } - if (CheckOnBoard()){// player cannot do anything below - return - } - if (keys.digit1.pressed){ socket.emit('keydown',{keycode:'Digit1'}) } @@ -509,6 +498,8 @@ setInterval(()=>{ } else{ // builtin socket.emit('playermousechange', {x:cursorX,y:cursorY}) // report mouseposition every TICK, not immediately } + + },TICKRATE) @@ -536,7 +527,7 @@ function reloadGun(){ const GUNRELOADRATE = gunInfoFrontEnd[currentGunName].reloadTime if (currentGunName==='flareGun'){ // not reloadable - console.log("flaregun cannot be reloaded") + //console.log("flaregun cannot be reloaded") return } @@ -699,10 +690,7 @@ socket.on('interact',({backEndItems,backEndVehicles})=>{ // manual takeoff if (frontEndPlayer.onBoard){ // take off! - playerdeathsound.play() // sounds like this! - socket.emit('takeOff') - frontEndPlayer.onBoard = false return } @@ -1274,7 +1262,7 @@ function loop(){ ///////////////////////////////// PLAYERS ///////////////////////////////// canvas.fillStyle = 'white' // canvas.strokeStyle = 'black' // same stroke style with projectiles - if (frontEndPlayer && !frontEndPlayer.onBoard){ // draw myself in the center + if (!frontEndPlayer.onBoard){ // draw myself in the center const currentHoldingItem = getCurItem(frontEndPlayer) frontEndPlayer.displayAttribute(canvas, camX, camY, currentHoldingItem) if (gunInfoFrontEnd){ @@ -1305,7 +1293,7 @@ function loop(){ // This loop is for displaying health & name canvas.lineWidth = 8 - if (frontEndPlayer && !frontEndPlayer.onBoard){ // draw myself in the center + if (!frontEndPlayer.onBoard){ // draw myself in the center frontEndPlayer.displayHealth(canvas, camX, camY, centerX , centerY - PLAYERRADIUS*2) } @@ -1338,40 +1326,7 @@ function loop(){ - // ADVANCED PLANTS (OPAQUE) - canvas.save(); - canvas.globalAlpha = 0.8; - for (let row = chunkInfo.rowNum-sightChunk;row < chunkInfo.rowNum + sightChunk+1;row++){ - for (let col = chunkInfo.colNum-sightChunk;col < chunkInfo.colNum + sightChunk+1 ;col++){ - if (row < 0 || col < 0 || row >= groundMap.length || col >= groundMap[0].length){ - continue - } - const { id } = decalMap[row][col] ?? {id:undefined}; - const imageRow = parseInt(id / TILES_IN_ROW); - const imageCol = id % TILES_IN_ROW; - if (130 <= id && id <= 134){ // grass - opacity - canvas.drawImage(mapImage, - imageCol * TILE_SIZE, - imageRow * TILE_SIZE, - TILE_SIZE,TILE_SIZE, - col*TILE_SIZE - camX, - row*TILE_SIZE - camY, - TILE_SIZE,TILE_SIZE - ); - } else if (id===107){ // overhanges (roofs) - opacity but not clear as house - canvas.drawImage(mapImage, - imageCol * TILE_SIZE, - imageRow * TILE_SIZE, - TILE_SIZE,TILE_SIZE, - col*TILE_SIZE - camX, - row*TILE_SIZE - camY, - TILE_SIZE,TILE_SIZE - ); - } - } - } - canvas.restore(); - // ADVANCED PLANTS + // ADVANCED NON OPAC for (let row = chunkInfo.rowNum-sightChunk;row < chunkInfo.rowNum + sightChunk+1;row++){ @@ -1411,16 +1366,58 @@ function loop(){ // ADVANCED NON OPAC + // GLOBAL ALPHA CHANGES + canvas.save(); + // ADVANCED PLANTS (OPAQUE) + canvas.globalAlpha = 0.8; + + for (let row = chunkInfo.rowNum-sightChunk;row < chunkInfo.rowNum + sightChunk+1;row++){ + for (let col = chunkInfo.colNum-sightChunk;col < chunkInfo.colNum + sightChunk+1 ;col++){ + if (row < 0 || col < 0 || row >= groundMap.length || col >= groundMap[0].length){ + continue + } + const { id } = decalMap[row][col] ?? {id:undefined}; + const imageRow = parseInt(id / TILES_IN_ROW); + const imageCol = id % TILES_IN_ROW; + if (130 <= id && id <= 134){ // grass - opacity + canvas.drawImage(mapImage, + imageCol * TILE_SIZE, + imageRow * TILE_SIZE, + TILE_SIZE,TILE_SIZE, + col*TILE_SIZE - camX, + row*TILE_SIZE - camY, + TILE_SIZE,TILE_SIZE + ); + } else if (id===107){ // overhanges (roofs) - opacity but not clear as house + canvas.drawImage(mapImage, + imageCol * TILE_SIZE, + imageRow * TILE_SIZE, + TILE_SIZE,TILE_SIZE, + col*TILE_SIZE - camX, + row*TILE_SIZE - camY, + TILE_SIZE,TILE_SIZE + ); + } + } + } + // ADVANCED PLANTS + // Air strike + // canvas.globalAlpha = 0.9; for (const id in frontEndAirstrikes){ const frontEndAirstrike = frontEndAirstrikes[id] if (frontEndPlayer.IsVisible(chunkInfo,getChunk(frontEndAirstrike.x,frontEndAirstrike.y),sightChunk+3) ){ canvas.drawImage(planeImage,frontEndAirstrike.x - camX - 384, frontEndAirstrike.y - camY - 558) - } } + canvas.restore(); + // GLOBAL ALPHA CHANGES + + + + if (frontEndPlayer.onBoard){ // show text message canvas.fillText('Press F to take off!', centerX - 110, centerY + PLAYERRADIUS*2) } @@ -1458,8 +1455,8 @@ document.querySelector('#usernameForm').addEventListener('submit', (event) => { resetKeys() listen = true // initialize the semaphore updateSightChunk(0) // scope to 0 - const playerX = TILE_SIZE*2 //MAPWIDTH * Math.random() - const playerY = MAPHEIGHT/2 //MAPHEIGHT * Math.random() + const playerX = MAPWIDTH * Math.random() //TILE_SIZE*2 // + const playerY = MAPHEIGHT * Math.random() //MAPHEIGHT/2 // const playerColor = `hsl(${Math.random()*360},100%,70%)` const myUserName = document.querySelector('#usernameInput').value diff --git a/src/backend.js b/src/backend.js index 885ac72..cb8777d 100644 --- a/src/backend.js +++ b/src/backend.js @@ -412,11 +412,11 @@ if (GROUNDITEMFLAG){ makeNdropItem('placeable', 'mine' ,getCoordTilesCenter({row:1,col:46}),onground=true,variantNameGiven='') } - for (let i=0;i<4;i++){ + for (let i=0;i<1;i++){ makeNdropItem('gun', 'flareGun', getCoordTilesCenter({row:24,col:3}),onground=true,variantNameGiven='green')// variant should be red,green etc. - makeNdropItem('gun', 'flareGun', getCoordTilesCenter({row:25,col:3}),onground=true,variantNameGiven='red')// variant should be red,green etc. - makeNdropItem('gun', 'flareGun', getCoordTilesCenter({row:26,col:3}),onground=true,variantNameGiven='yellow')// variant should be red,green etc. - makeNdropItem('gun', 'flareGun', getCoordTilesCenter({row:27,col:3}),onground=true,variantNameGiven='white')// variant should be red,green etc. + makeNdropItem('gun', 'flareGun', getCoordTilesCenter({row:14,col:5}),onground=true,variantNameGiven='red')// variant should be red,green etc. + makeNdropItem('gun', 'flareGun', getCoordTilesCenter({row:27,col:3}),onground=true,variantNameGiven='yellow')// variant should be red,green etc. + makeNdropItem('gun', 'flareGun', getCoordTilesCenter({row:37,col:5}),onground=true,variantNameGiven='white')// variant should be red,green etc. } // MAKE HOUSES @@ -694,27 +694,33 @@ async function main(){ // aux function for shoot function shootProjectile(angle,currentGun,startDistance){ - if (!backEndPlayers[socket.id]) return // player not defined const gunName = currentGun for (let i=0;i< gunInfo[currentGun].num;i++){ addProjectile(angle,currentGun,socket.id, backEndPlayers[socket.id],startDistance) } } - socket.on('shoot', ({angle,currentGun,startDistance=0,currentHoldingItemId=0})=>{ + socket.on('shoot', ({angle,currentGun,startDistance=0,currentHoldingItemId=0})=>{ // NOTE: reload does not use socket!!! + if (!backEndPlayers[socket.id]) return // player not defined + if (backEndPlayers[socket.id].onBoard){return} // cannot shoot if on board + if (currentHoldingItemId>0){ // decrease ammo let thisGun = backEndItems[currentHoldingItemId] - if (thisGun.iteminfo.ammo>0){ - if (thisGun.name==='flareGun'){ + if (thisGun.name==='flareGun'){ + if (thisGun.iteminfo.ammo>0){ thisGun.iteminfo.ammo = 0 } + shootProjectile(angle,currentGun,startDistance) + }else{ // not a flare gun, then ammo is not important shootProjectile(angle,currentGun,startDistance) } }else{ // on vehicle turret etc. shootProjectile(angle,currentGun,startDistance) } - + // shootProjectile(angle,currentGun,startDistance) + + } ) @@ -908,6 +914,7 @@ function onBoardCheck(player){ return player.onBoard } +let ServerTime = 0 let GLOBALCLOCK = 0 // backend ticker - update periodically server info to clients setInterval(() => { @@ -918,6 +925,19 @@ setInterval(() => { spawnEnemies() } GLOBALCLOCK = 0 // init + + // print entity object's lengths + console.log(`[ Entity amount check ${ServerTime} ]`) + console.log( + "Players ",Object.keys(backEndPlayers).length, + "\nEnemies ",Object.keys(backEndEnemies).length, + "\nProjectiles ",Object.keys(backEndProjectiles).length, + "\nItems ",Object.keys(backEndItems).length, + "\nVehicles ",Object.keys(backEndVehicles).length, + "\nObjects ",Object.keys(backEndObjects).length, + "\nAirstrikes ",Object.keys(backEndAirstrikes).length, + "\nSoundRequests ",Object.keys(backEndSoundRequest).length ) + ServerTime += 1 } // red zone? @@ -1903,14 +1923,14 @@ function explosion(location,BLASTNUM,playerID=0,shockWave=false){ // const AIRSTRIKE_TYPE_DICT = {'red':'bomb','green':'supply','white':'transport', 'yellow':'vehicle request'} -const STRIKE_INTERVAL_COEF = 15 +const STRIKE_INTERVAL_COEF = 10 const PLANE_PICKUP_RADIUS = 256 // plane rad is 384 function spawnAirstrike(location, callerID, signalColor='green'){ // currently only makes cars airstrikeId++ const x = location.x - let speed = Math.min( ((MAPHEIGHT - location.y)/MAPHEIGHT)*6+2 , 5) // 1~4 + let speed = Math.min( ((MAPHEIGHT - location.y)/MAPHEIGHT)*6+2 , 5) // 2~5 const y = MAPHEIGHT-1 // goes up const signal = AIRSTRIKE_TYPE_DICT[signalColor] @@ -1919,7 +1939,7 @@ function spawnAirstrike(location, callerID, signalColor='green'){ // currently o let strikeNumber = 1 if (signal==='bomb'){ - speed = 8 // fly fast and bomber (same speed as B2) + speed = 12 // fly fast and bomber (same speed as B2) strikeNumber = 16 strike_Y_level = Math.round(location.y + (strikeNumber/2)*speed*STRIKE_INTERVAL_COEF) } else if(signal==='transport'){ @@ -2009,8 +2029,8 @@ function safeTakeOff(airstrikeID){ passenger.strikeID = -1 airstrike.onBoard = false NONitemBorderUpdate(passenger) + pushSoundRequest({x:airstrike.x,y:airstrike.y},'takeoff',TILE_SIZE*3, duration=1) } - pushSoundRequest({x:airstrike.x,y:airstrike.y},'takeoff',TILE_SIZE*3, duration=1) }