-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1297 from Nicko21/consumables
Add support for potions
- Loading branch information
Showing
12 changed files
with
167 additions
and
27 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
return{ | ||
name = "baggle", | ||
type = "consumable", | ||
MAX_ITEMS = 10, | ||
use = function( consumable, player ) | ||
player.health = player.max_health | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
return{ | ||
name = "healthpot", | ||
type = "consumable", | ||
MAX_ITEMS = 10, | ||
regen = 5, | ||
use = function( consumable, player ) | ||
if (player.health + consumable.props.regen) >= player.max_health then | ||
player.health = player.max_health | ||
else | ||
player.health = player.health + consumable.props.regen | ||
end | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
----------------------------------------------- | ||
-- consumable.lua | ||
-- Represents a consumable when it is in the world | ||
-- Created by Nicko21 | ||
----------------------------------------------- | ||
|
||
local controls = require 'controls' | ||
local Item = require 'items/item' | ||
|
||
local Consumable = {} | ||
Consumable.__index = Consumable | ||
Consumable.isConsumable = true | ||
|
||
--- | ||
-- Creates a new consumable object | ||
-- @return the consumable object created | ||
function Consumable.new(node, collider) | ||
local consumable = {} | ||
setmetatable(consumable, Consumable) | ||
consumable.name = node.name | ||
consumable.type = 'consumable' | ||
consumable.image = love.graphics.newImage('images/consumables/'..node.name..'.png') | ||
consumable.image_q = love.graphics.newQuad( 0, 0, 24, 24, consumable.image:getWidth(),consumable.image:getHeight() ) | ||
consumable.foreground = node.properties.foreground | ||
consumable.collider = collider | ||
consumable.bb = collider:addRectangle(node.x, node.y, node.width, node.height) | ||
consumable.bb.node = consumable | ||
collider:setPassive(consumable.bb) | ||
|
||
consumable.position = {x = node.x, y = node.y} | ||
consumable.width = node.width | ||
consumable.height = node.height | ||
|
||
consumable.touchedPlayer = nil | ||
consumable.exists = true | ||
|
||
return consumable | ||
end | ||
|
||
--- | ||
-- Draws the consumable to the screen | ||
-- @return nil | ||
function Consumable:draw() | ||
if not self.exists then | ||
return | ||
end | ||
love.graphics.drawq(self.image, self.image_q, self.position.x, self.position.y) | ||
end | ||
|
||
|
||
function Consumable:keypressed( button, player ) | ||
if button ~= 'INTERACT' then return end | ||
|
||
local itemNode = require( 'items/consumables/' .. self.name ) | ||
itemNode.type = 'consumable' | ||
local item = Item.new(itemNode) | ||
if player.inventory:addItem(item) then | ||
self.exists = false | ||
self.containerLevel:removeNode(self) | ||
self.collider:remove(self.bb) | ||
end | ||
end | ||
|
||
--- | ||
-- Called when the consumable begins colliding with another node | ||
-- @return nil | ||
function Consumable:collide(node, dt, mtv_x, mtv_y) | ||
if node and node.character then | ||
self.touchedPlayer = node | ||
end | ||
end | ||
|
||
--- | ||
-- Called when the consumable finishes colliding with another node | ||
-- @return nil | ||
function Consumable:collide_end(node, dt) | ||
if node and node.character then | ||
self.touchedPlayer = nil | ||
end | ||
end | ||
|
||
--- | ||
-- Updates the consumable and allows the player to pick it up. | ||
function Consumable:update() | ||
if not self.exists then | ||
return | ||
end | ||
end | ||
|
||
return Consumable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
return{ | ||
name = "baggle" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,7 @@ return { | |
{"bone",30,50}, | ||
{"ember",30,70}, | ||
}, | ||
consumables = { | ||
{"healthpot",5,100} | ||
} | ||
} |