Functioning crafting table

This commit is contained in:
jordan4ibanez 2017-07-25 02:10:03 -04:00
parent e61a90ce3f
commit 8b55f4d71e
3 changed files with 43 additions and 2 deletions

View File

@ -3,14 +3,50 @@
crafting = {}
crafting_open = false
crafting.craft_size = 3 --number x number
crafting_x = 120
crafting_y = 270
crafting_y = 350
craft_inv_x = 120
craft_inv_y = 50
crafting_selection_x = 1
crafting_selection_y = 1
craft_inventory_selection_x = 0
craft_inventory_selection_y = 0
crafting.craft_inventory = {}
--create crafting inventory
for i = 1,crafting.craft_size*crafting.craft_size do
crafting.craft_inventory[i] = {}
end
--draw entire inventory
function crafting.render_crafting()
if crafting_open == true then
--draw crafting table
local xstep = 0
local ystep = 0
local nextline = 0
for i = 1,table.getn(crafting.craft_inventory) do
--print(i)
love.graphics.draw(inventory_slot, craft_inv_x+(xstep*84), craft_inv_y+(84*ystep),0, 1, 1)
--move to next step
nextline = nextline + 1
xstep = xstep + 1
if nextline >=crafting.craft_size then
nextline = 0
ystep = ystep + 1
xstep = 0
end
end
--draw craft selection
if craft_inventory_selection_x > 0 and craft_inventory_selection_y > 0 then
love.graphics.draw(inventory_slot_selection, ((craft_inventory_selection_x-1)*84)+craft_inv_x, ((craft_inventory_selection_y-1)*84)+craft_inv_y,0, 1, 1)
end
--draw inventory
local xstep = 0

View File

@ -107,8 +107,8 @@ function love.wheelmoved(x, y)
end
--render hot bar
function render_inventory()
--draw inventory
for i = 1,inventory_size do
love.graphics.draw(inventory_slot, inventory_x+(i*(inv_slot_width/2)), inventory_y,0, 1/2, 1/2)
end

View File

@ -201,9 +201,14 @@ function menu.cursor()
if x > crafting_x and x < crafting_x + (inventory_size*84) and y > crafting_y and y < crafting_y + (inventory_height*84) then
crafting_selection_x = math.ceil((x-crafting_x)/84)
crafting_selection_y = math.ceil((y-crafting_y)/84)
elseif x > craft_inv_x and x < craft_inv_x + (crafting.craft_size*84) and y > craft_inv_y and y < craft_inv_y + (crafting.craft_size*84) then
craft_inventory_selection_x = math.ceil((x-craft_inv_x)/84)
craft_inventory_selection_y = math.ceil((y-craft_inv_y)/84)
else
crafting_selection_x = -1
crafting_selection_y = -1
craft_inventory_selection_x = -1
craft_inventory_selection_y = -1
end
end