Skip to content

Commit

Permalink
Merge pull request #2379 from niamu/item_persistence
Browse files Browse the repository at this point in the history
Improve item persistence
  • Loading branch information
niamu committed May 19, 2015
2 parents a3eab58 + d5904ec commit bc3d8dc
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
11 changes: 8 additions & 3 deletions src/nodes/consumable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function Consumable:update(dt, player, map)
if not self.exists then
return
end
if self.dropping then
if self.dropping then
local nx, ny = collision.move(map, self, self.position.x, self.position.y,
self.width, self.height,
self.velocity.x * dt, self.velocity.y * dt)
Expand All @@ -107,6 +107,12 @@ function Consumable:update(dt, player, map)
-- 12 is half the size
self.bb:moveTo(self.position.x + 12, self.position.y + 12)
end

-- Item has finished dropping in the level
if not self.dropping and self.dropped and not self.saved then
self.containerLevel:saveAddedNode(self)
self.saved = true
end
end

function Consumable:drop(player)
Expand All @@ -116,6 +122,7 @@ function Consumable:drop(player)
end

self.dropping = true
self.dropped = true
end

function Consumable:floorspace_drop(player)
Expand All @@ -131,8 +138,6 @@ function Consumable:floor_pushback()
self.dropping = false
self.velocity.y = 0
self.collider:setPassive(self.bb)

self.containerLevel:saveAddedNode(self)
end

return Consumable
9 changes: 7 additions & 2 deletions src/nodes/material.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ function Material:update(dt, player, map)

self.bb:moveTo(self.position.x + self.width / 2 + self.bb_offset_x, self.position.y + self.height / 2)
end

-- Item has finished dropping in the level
if not self.dropping and self.dropped and not self.saved then
self.containerLevel:saveAddedNode(self)
self.saved = true
end
end

function Material:drop(player)
Expand All @@ -114,6 +120,7 @@ function Material:drop(player)
end

self.dropping = true
self.dropped = true
end

function Material:floorspace_drop(player)
Expand All @@ -129,8 +136,6 @@ function Material:floor_pushback()
self.dropping = false
self.velocity.y = 0
self.collider:setPassive(self.bb)

self.containerLevel:saveAddedNode(self)
end

return Material
14 changes: 10 additions & 4 deletions src/nodes/projectile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function Projectile.new(node, collider)
-- Don't forget to pass this into hurt functions in the props file
proj.special_damage = proj.props.special_damage or {}
proj.solid = proj.props.solid
proj.dropping = false
proj.dropped = false

proj.playerCanPickUp = proj.props.playerCanPickUp
Expand Down Expand Up @@ -176,13 +177,19 @@ function Projectile:update(dt, player, map)
self.position.y = ny - self.offset.y
end

if self.dropped then
if self.dropping then
self.position.x = nx
self.position.y = ny
-- X velocity won't need to change
self.velocity.y = self.velocity.y + game.gravity*dt
end

-- Item has finished dropping in the level
if not self.dropping and self.dropped and not self.saved then
self.containerLevel:saveAddedNode(self)
self.saved = true
end

if self.props.update then
self.props.update(dt, self)
end
Expand Down Expand Up @@ -304,10 +311,8 @@ function Projectile:floor_pushback(tile)

-- Pushback code for a dropped item
if self.dropped then
self.dropped = false
self.dropping = false
self.velocity.y = 0

self.containerLevel:saveAddedNode(self)
return
end

Expand Down Expand Up @@ -425,6 +430,7 @@ function Projectile:drop(thrower)
self:floorspace_drop(thrower)
return
end
self.dropping = true
self.dropped = true
end

Expand Down
10 changes: 8 additions & 2 deletions src/nodes/rangedWeapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function Weapon.new(node, collider, plyr, weaponItem)
weapon.actionwalk = props.actionwalk or 'shootarrowwalk'
weapon.actionjump = props.actionjump or 'shootarrowjump'
weapon.dropping = false
weapon.dropped = false

return weapon
end
Expand All @@ -113,6 +114,12 @@ function Weapon:update(dt, player, map)
self.velocity = { x = self.velocity.x,
y = self.velocity.y + game.gravity*dt }
end

-- Item has finished dropping in the level
if not self.dropping and self.dropped and not self.saved then
self.containerLevel:saveAddedNode(self)
self.saved = true
end
else
--the weapon is being used by a player
local player = self.player
Expand Down Expand Up @@ -194,6 +201,7 @@ end
-- handles weapon being dropped in the real world
function Weapon:drop(player)
self.dropping = true
self.dropped = true

self.player:setSpriteStates('default')
self.player.currently_held = nil
Expand Down Expand Up @@ -229,8 +237,6 @@ function Weapon:floor_pushback()

self.dropping = false
self.velocity.y = 0

self.containerLevel:saveAddedNode(self)
end

return Weapon
10 changes: 8 additions & 2 deletions src/nodes/scroll.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function Scroll.new(node, collider)
collider:setSolid(scroll.bb)

scroll.dropping = false
scroll.dropped = false

scroll.position = { x = node.x, y = node.y }
scroll.velocity = { x = node.x, y = node.y }
Expand All @@ -65,6 +66,12 @@ function Scroll:update(dt, player, map)

self.bb:moveTo(self.position.x + self.width / 2, self.position.y + self.height / 2)
end

-- Item has finished dropping in the level
if not self.dropping and self.dropped and not self.saved then
self.containerLevel:saveAddedNode(self)
self.saved = true
end
end

function Scroll:keypressed( button, player)
Expand Down Expand Up @@ -103,6 +110,7 @@ function Scroll:drop(player)
end

self.dropping = true
self.dropped = true
end

function Scroll:floorspace_drop(player)
Expand All @@ -118,8 +126,6 @@ function Scroll:floor_pushback()
self.dropping = false
self.velocity.y = 0
self.collider:setPassive(self.bb)

self.containerLevel:saveAddedNode(self)
end

function Scroll:wall_pushback()
Expand Down
8 changes: 6 additions & 2 deletions src/nodes/weapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ function Weapon:update(dt, player, map)
self.position.y + self.dropHeight / 2)
end
end

-- Item has finished dropping in the level
if not self.dropping and self.dropped and not self.saved then
self.containerLevel:saveAddedNode(self)
self.saved = true
end
else
--the weapon is being used by a player
local player = self.player
Expand Down Expand Up @@ -369,8 +375,6 @@ function Weapon:floor_pushback()
end

self.velocity.y = 0

self.containerLevel:saveAddedNode(self)
end

return Weapon

0 comments on commit bc3d8dc

Please sign in to comment.