Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weapons bounding box follows #1035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/nodes/weapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ function Weapon:collide(node, dt, mtv_x, mtv_y)

if node.hurt then
node:hurt(self.damage)
self.collider:setGhost(self.bb)
if self.player then
self.collider:setGhost(self.bb)
end
end

if self.hitAudioClip and node.hurt then
Expand All @@ -145,8 +147,8 @@ function Weapon:collide(node, dt, mtv_x, mtv_y)
end

function Weapon:initializeBoundingBox(collider)
self.boxTopLeft = {x = self.position.x + self.bbox_offset_x,
y = self.position.y + self.bbox_offset_y}
self.boxTopLeft = {x = self.position.x + self.bbox_offset_x[1],
y = self.position.y + self.bbox_offset_y[1]}
self.boxWidth = self.bbox_width
self.boxHeight = self.bbox_height

Expand Down Expand Up @@ -206,18 +208,19 @@ function Weapon:update(dt)

if not self.position or not self.position.x or not player.position or not player.position.x then return end

local framePos = (player.wielding) and self.animation.position or 1
if player.character.direction == "right" then
self.position.x = math.floor(player.position.x) + (plyrOffset-self.hand_x) +player.offset_hand_left[1]
self.position.y = math.floor(player.position.y) + (-self.hand_y) + player.offset_hand_left[2]

self.bb:moveTo(self.position.x + self.bbox_offset_x + self.bbox_width/2,
self.position.y + self.bbox_offset_y + self.bbox_height/2)
self.bb:moveTo(self.position.x + self.bbox_offset_x[framePos] + self.bbox_width/2,
self.position.y + self.bbox_offset_y[framePos] + self.bbox_height/2)
else
self.position.x = math.floor(player.position.x) + (plyrOffset+self.hand_x) +player.offset_hand_right[1]
self.position.y = math.floor(player.position.y) + (-self.hand_y) + player.offset_hand_right[2]

self.bb:moveTo(self.position.x - self.bbox_offset_x - self.bbox_width/2,
self.position.y + self.bbox_offset_y + self.bbox_height/2)
self.bb:moveTo(self.position.x - self.bbox_offset_x[framePos] - self.bbox_width/2,
self.position.y + self.bbox_offset_y[framePos] + self.bbox_height/2)
end

if player.offset_hand_right[1] == 0 or player.offset_hand_left[1] == 0 then
Expand All @@ -226,7 +229,6 @@ function Weapon:update(dt)

if player.wielding and self.animation and self.animation.status == "finished" then
self.collider:setGhost(self.bb)
self.wielding = false
player.wielding = false
self.animation = self.defaultAnimation
end
Expand Down Expand Up @@ -257,7 +259,6 @@ end

--handles a weapon being activated
function Weapon:wield()
if self.wielding then return end
self.collider:setSolid(self.bb)

self.player.wielding = true
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/weapons/mace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ return {
damage = 4,
bbox_width = 25,
bbox_height = 25,
bbox_offset_x = 25,
bbox_offset_y = 25,
bbox_offset_x = {0,3,25},
bbox_offset_y = {0,1,25},
hitAudioClip = 'mace_hit',
animations = {
default = {'once', {'1,1'}, 1},
Expand Down
8 changes: 4 additions & 4 deletions src/nodes/weapons/mallet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ return{
frameAmt = 3,
width = 30,
height = 40,
damage = 4,
damage = 10,
bbox_width = 16,
bbox_height = 16,
bbox_offset_x = 6,
bbox_offset_y = 16,
bbox_height = 28,
bbox_offset_x = {0,4,6,4},
bbox_offset_y = {0,0,16,0},
hitAudioClip = 'mallet_hit',
animations = {
default = {'once', {'1,1'}, 1},
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/weapons/sword.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ return{
height = 40,
damage = 4,
dead = false,
bbox_width = 28,
bbox_width = 40,
bbox_height = 7,
bbox_offset_x = 21,
bbox_offset_y = 28,
bbox_offset_x = {21,21,21},
bbox_offset_y = {28,28,28},
unuseAudioClip = 'sword_sheathed',
hitAudioClip = 'sword_hit',
swingAudioClip = 'sword_air',
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/weapons/torch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ return{
width = 48,
height = 48,
damage = 4,
bbox_width = 20,
bbox_width = 30,
bbox_height = 33,
bbox_offset_x = 6 ,
bbox_offset_y = 17,
bbox_offset_x = {6,12,12,12} ,
bbox_offset_y = {17,17,17,17},
swingAudioClip = 'fire_thrown',
isFlammable = true,
animations = {
Expand Down