Skip to content

Commit

Permalink
Plane design: more transparent
Browse files Browse the repository at this point in the history
  • Loading branch information
blueSparrow2000 committed Feb 9, 2024
1 parent 3deb40f commit 22dcfe2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 67 deletions.
Binary file modified gun infos.xlsx
Binary file not shown.
105 changes: 51 additions & 54 deletions public/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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'})
}
Expand Down Expand Up @@ -509,6 +498,8 @@ setInterval(()=>{
} else{ // builtin
socket.emit('playermousechange', {x:cursorX,y:cursorY}) // report mouseposition every TICK, not immediately
}


},TICKRATE)


Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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++){
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
46 changes: 33 additions & 13 deletions src/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


} )


Expand Down Expand Up @@ -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(() => {
Expand All @@ -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?
Expand Down Expand Up @@ -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]
Expand All @@ -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'){
Expand Down Expand Up @@ -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)

}

Expand Down

0 comments on commit 22dcfe2

Please sign in to comment.