From 0221a7a65af55f526f5fdc77057956784c3c8034 Mon Sep 17 00:00:00 2001 From: blueSparrow2000 Date: Thu, 20 Jun 2024 21:25:50 +0900 Subject: [PATCH] Added Gun recoil effect --- README.md | 3 +-- public/classes/Player.js | 9 ++++++++- public/frontend.js | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 26310a3..05ccc1d 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ or 2024.6.19 Smooth vehicle movement -2024.6.20 Added airdrop gun: Lynx (penetrates players & enemies) / Added airstrike: emergency cover & plane speeds adjusted / Consumable update: Added adrenaline & drink / Armor update: anti-blast & turtle / Inventory selection show up +2024.6.20 Added airdrop gun: Lynx (penetrates players & enemies) / Added airstrike: emergency cover & plane speeds adjusted / Consumable update: Added adrenaline & drink / Armor update: anti-blast & turtle / Inventory selection show up / Added Gun recoil effect Future plan: @@ -131,7 +131,6 @@ Future plan: - vehicle-vehicle collision - Military base: finish structures / add trees (object) in the dense forest -- Gun recoil effect - SONA (shows location of enemy in the map & direction for 1 seconds) - smarter AI (zombies shoots projectiles) - wind update diff --git a/public/classes/Player.js b/public/classes/Player.js index 8948d1b..b8ce364 100644 --- a/public/classes/Player.js +++ b/public/classes/Player.js @@ -25,6 +25,7 @@ class Player{ this.start_offset = 16 this.rotation_alpha = Math.PI/6 this.healthboost = healthboost + this.recoil = 0 } drawPlayer(canvas, skin, xloc, yloc){ @@ -109,7 +110,13 @@ class Player{ if (currentHoldingItem.itemtype==='gun'){ const itemSize = currentHoldingItem.size - const itemlength = itemSize.length*2 + const itemlength = itemSize.length*2 - this.recoil + if (this.recoil<0.05){ + this.recoil =0 + }else{ + this.recoil -= this.recoil/10 + } + const gunmainwidth = itemSize.width*2 let angle = Math.atan2( (this.cursorPos.y) - this.canvasHeight/2, diff --git a/public/frontend.js b/public/frontend.js index be6efb8..87a304f 100644 --- a/public/frontend.js +++ b/public/frontend.js @@ -540,13 +540,13 @@ function shootCheck(event,holding = false){ listen = false // block socket.emit("shoot", {angle:getAngle(event),currentGun:currentGunName,currentHoldingItemId,holding}) - + if (!(currentHoldingItem.itemtype==='melee')){ // not malee, i.e. gun! // decrease ammo here!!!!! currentHoldingItem.ammo -= 1 //console.log(`${currentGunName} ammo: ${currentHoldingItem.ammo}`) } - + frontEndPlayer.recoil = 5 //console.log("fired") fireTimeout = window.setTimeout(function(){ if (!frontEndPlayer) {clearTimeout(fireTimeout);return};clearTimeout(fireTimeout);listen = true},GUNFIRERATE) //console.log("ready to fire")