Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Expanded inventory system.

  • Loading branch information...
commit 8c95a49deb43616f54a5554a11223614a0652866 1 parent 0c7db15
@Middlerun authored
View
17 README
@@ -8,11 +8,13 @@
A game by Middlerun
http://www.middlerun.net
-A 2D Minecraft-style game.
+Lövecraft is a 2D mining and building sim in the vein of Minecraft and
+Terraria.
Controls:
Move left: A
Move right: D
+Open inventory: E
Break block: Left mouse
Place block: Right mouse
Select block: Scroll wheel
@@ -24,15 +26,20 @@ Lengthen hook line: S
Requires LÖVE 0.7.2. See http://www.love2d.org for more info.
+Lövecraft is currently in a very early stage of development. The current
+version can always be found at https://github.com/Middlerun/lovecraft
+
+Despite the name, it has nothing to do with the works of H.P. Lovecraft. I'll
+rename it to something less misleading when I think of a good name.
+
To do:
------
-- Fix grappling hook bugs
+- Crafting
- Tools and items
-- Inventory management system
- More block types
-- Crafting
+- Fix grappling hook bugs
- Music and sound effects
- Menu screen
- Save/load system
@@ -49,7 +56,7 @@ Credits, attributions and other rubbish:
Made with the LÖVE framework
http://www.love2d.org
-Inspired by Minecraft and Terraria.
+Inspired by Minecraft, Terraria and the Worms games.
Assets used under Creative Commons license:
Cobblestone graphics by Arachne
View
1  chunk.lua
@@ -69,6 +69,7 @@ function Chunk:generate(seed, chunkR, chunkC)
end
end
end
+ self.perlin = {}
self.generated = true
self.changed = true
self.r = chunkR
View
94 gameplay.lua
@@ -0,0 +1,94 @@
+function handleGameplayInput(player, terrain, dt)
+ cursor.x = (love.mouse.getX() - love.graphics.getWidth() / 2) / view.zoom + view.x
+ cursor.y = (love.mouse.getY() - love.graphics.getHeight() / 2) / view.zoom + view.y
+
+ if not player.hook.hooked and love.keyboard.isDown(" ") and not player.falling and not hookRelease then
+ player.falling = true
+ player.vy = -15
+ end
+ if player.hook.hooked then
+ if love.keyboard.isDown("w") then
+ player.hook:shorten(dt)
+ elseif love.keyboard.isDown("s") then
+ player.hook:lengthen(dt)
+ end
+ if love.keyboard.isDown("a") then
+ player.hook.push = 2
+ player.direction = -1
+ elseif love.keyboard.isDown("d") then
+ player.hook.push = -2
+ player.direction = 1
+ else
+ player.hook.push = 0
+ end
+ end
+
+ if love.keyboard.isDown("w") or love.keyboard.isDown("a") or love.keyboard.isDown("s") or love.keyboard.isDown("d") then
+ cursorFade = true
+ end
+ if love.mouse.getX() ~= oldMouse.x or love.mouse.getY() ~= oldMouse.y or love.mouse.isDown("l") or love.mouse.isDown("r") then
+ cursorFade = false
+ cursorAlpha = 255
+ end
+ if cursorFade then cursorAlpha = math.max(0, cursorAlpha - dt * 255 / 5) end
+ oldMouse.x = love.mouse.getX()
+ oldMouse.y = love.mouse.getY()
+
+ inreach = (pythag(cursor.x, cursor.y, player.x, player.y - player.height/2) < 5)
+ if inreach then
+ local block = terrain:getBlock(math.ceil(cursor.y), math.ceil(cursor.x))
+ if love.mouse.isDown("l") and block ~= AIR and block ~= UNGENERATED then
+ if math.ceil(cursor.x) == mineBlock.c and math.ceil(cursor.y) == mineBlock.r then
+ mineProgress = mineProgress + dt / durability[block]
+ if mineProgress >= 1 or instamine then
+ terrain:setBlock(math.ceil(cursor.y), math.ceil(cursor.x), AIR)
+ mineProgress = 0
+ mineBlock.r = nil
+ mineBlock.c = nil
+ terrain:addEntity(breakGive[block], math.ceil(cursor.y), math.ceil(cursor.x) - 0.5 - rand:num())
+ end
+ else
+ mineBlock.r = math.ceil(cursor.y)
+ mineBlock.c = math.ceil(cursor.x)
+ mineProgress = dt / durability[block]
+ end
+ elseif love.mouse.isDown("r") and block == AIR and placeTime > 0.2 then
+ local x = math.ceil(cursor.x)
+ local y = math.ceil(cursor.y)
+ if x - 1 >= player.x + player.width / 2 or x <= player.x - player.width / 2
+ or y - 1 >= player.y or y <= player.y - player.height then
+ if player:checkSlot(4, selected.hotbar).id then
+ terrain:setBlock(y, x, player:takeSlot(4, selected.hotbar).id)
+ placeTime = 0
+ end
+ end
+ mineProgress = 0
+ else
+ mineProgress = 0
+ end
+ end
+end
+
+function handleInventoryInput(player)
+ local x = love.mouse.getX()
+ local y = love.mouse.getY()
+ local offsetY
+ selected.r = nil
+ selected.c = nil
+ for r = 1, 4 do
+ if r < 4 then
+ offsetY = 216 + 52 * (r - 1)
+ else
+ offsetY = 396
+ end
+ for c = 1, 9 do
+ if x >= love.graphics.getWidth()/2 - inventory:getWidth()/2 + 12 + 54 * (c - 1) and
+ x <= love.graphics.getWidth()/2 - inventory:getWidth()/2 + 66 + 54 * (c - 1) and
+ y >= love.graphics.getHeight()/2 - inventory:getHeight()/2 + offsetY and
+ y <= love.graphics.getHeight()/2 - inventory:getHeight()/2 + offsetY + 52 then
+ selected.r = r
+ selected.c = c
+ end
+ end
+ end
+end
View
BIN  gfx/hotbar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  gfx/inventory.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  gfx/xcf/hotbar.xcf
Binary file not shown
View
BIN  gfx/xcf/inventory.xcf
Binary file not shown
View
1  grapplinghook.lua
@@ -188,5 +188,6 @@ end
function GrapplingHook:draw(view, x, y)
if not self.fired then return end
love.graphics.setColor(0, 0, 0, 255)
+ love.graphics.setLine(view.zoom/16, "smooth")
love.graphics.line((x-view.x)*view.zoom + love.graphics.getWidth()/2, (y-view.y)*view.zoom + love.graphics.getHeight()/2, (self.x-view.x)*view.zoom + love.graphics.getWidth()/2, (self.y-view.y)*view.zoom + love.graphics.getHeight()/2)
end
View
1  loadgraphics.lua
@@ -65,4 +65,5 @@ genChunk:setFilter("linear", "nearest")
sky = love.graphics.newImage("gfx/sky.png")
hotbar = love.graphics.newImage("gfx/hotbar.png")
+inventory = love.graphics.newImage("gfx/inventory.png")
highlight = love.graphics.newImage("gfx/highlight.png")
View
166 main.lua
@@ -7,6 +7,7 @@ love.filesystem.load("collision.lua")()
love.filesystem.load("common.lua")()
love.filesystem.load("loadgraphics.lua")()
love.filesystem.load("entity.lua")()
+love.filesystem.load("gameplay.lua")()
love.filesystem.load("AnAL.lua")()
love.filesystem.setIdentity("lovecraft")
@@ -17,14 +18,19 @@ cursor = {x = 0, y = 0}
cursorFade = false
cursorAlpha = 255
inreach = true
-selected = 1
+selected = {}
+selected.hotbar = 1
+selected.r = 1
+selected.c = 1
mineBlock = {r = nil, c = nil}
mineProgress = 0
placeTime = 0
instamine = false
debug = false
hookRelease = false
+showInventory = false
g = 40
+pickedItem = {id = nil, count = 0}
@@ -69,25 +75,8 @@ function love.update(dt)
checkCollisions(terrain, player)
- if not player.hook.hooked and love.keyboard.isDown(" ") and not player.falling and not hookRelease then
- player.falling = true
- player.vy = -15
- end
- if player.hook.hooked then
- if love.keyboard.isDown("w") then
- player.hook:shorten(dt)
- elseif love.keyboard.isDown("s") then
- player.hook:lengthen(dt)
- end
- if love.keyboard.isDown("a") then
- player.hook.push = 2
- player.direction = -1
- elseif love.keyboard.isDown("d") then
- player.hook.push = -2
- player.direction = 1
- else
- player.hook.push = 0
- end
+ if showInventory then handleInventoryInput(player)
+ else handleGameplayInput(player, terrain, dt)
end
view.x = view.x + (player.x - view.x) * 0.2
@@ -100,53 +89,6 @@ function love.update(dt)
end
first = false
- cursor.x = (love.mouse.getX() - love.graphics.getWidth() / 2) / view.zoom + view.x
- cursor.y = (love.mouse.getY() - love.graphics.getHeight() / 2) / view.zoom + view.y
- if love.keyboard.isDown("w") or love.keyboard.isDown("a") or love.keyboard.isDown("s") or love.keyboard.isDown("d") then
- cursorFade = true
- end
- if love.mouse.getX() ~= oldMouse.x or love.mouse.getY() ~= oldMouse.y or love.mouse.isDown("l") or love.mouse.isDown("r") then
- cursorFade = false
- cursorAlpha = 255
- end
- if cursorFade then cursorAlpha = math.max(0, cursorAlpha - dt * 255 / 5) end
- oldMouse.x = love.mouse.getX()
- oldMouse.y = love.mouse.getY()
-
- inreach = (pythag(cursor.x, cursor.y, player.x, player.y - player.height/2) < 5)
- if inreach then
- local block = terrain:getBlock(math.ceil(cursor.y), math.ceil(cursor.x))
- if love.mouse.isDown("l") and block ~= AIR and block ~= UNGENERATED then
- if math.ceil(cursor.x) == mineBlock.c and math.ceil(cursor.y) == mineBlock.r then
- mineProgress = mineProgress + dt / durability[block]
- if mineProgress >= 1 or instamine then
- terrain:setBlock(math.ceil(cursor.y), math.ceil(cursor.x), AIR)
- mineProgress = 0
- mineBlock.r = nil
- mineBlock.c = nil
- terrain:addEntity(breakGive[block], math.ceil(cursor.y), math.ceil(cursor.x) - 0.5 - rand:num())
- end
- else
- mineBlock.r = math.ceil(cursor.y)
- mineBlock.c = math.ceil(cursor.x)
- mineProgress = dt / durability[block]
- end
- elseif love.mouse.isDown("r") and block == AIR and placeTime > 0.2 then
- local x = math.ceil(cursor.x)
- local y = math.ceil(cursor.y)
- if x - 1 >= player.x + player.width / 2 or x <= player.x - player.width / 2
- or y - 1 >= player.y or y <= player.y - player.height then
- if player:checkSlot(selected) then
- terrain:setBlock(y, x, player:takeSlot(selected))
- placeTime = 0
- end
- end
- mineProgress = 0
- else
- mineProgress = 0
- end
- end
-
placeTime = placeTime + dt
player.walk:update(dt)
player.hook:update(terrain, dt)
@@ -172,7 +114,8 @@ function love.draw()
player:draw(view)
love.graphics.setColor(0, 0, 0, cursorAlpha)
- if inreach then
+ if inreach and not showInventory then
+ love.graphics.setLine(view.zoom/32, "rough")
love.graphics.rectangle("line", (math.ceil(cursor.x)-1-view.x)*view.zoom + love.graphics.getWidth()/2, (math.ceil(cursor.y)-1-view.y)*view.zoom+love.graphics.getHeight()/2, view.zoom, view.zoom)
end
@@ -180,16 +123,22 @@ function love.draw()
love.graphics.draw(breakImage[math.ceil(mineProgress * 8)], (mineBlock.c-1-view.x)*view.zoom + love.graphics.getWidth()/2, (mineBlock.r-1-view.y)*view.zoom+love.graphics.getHeight()/2, 0, view.zoom/16, view.zoom/16)
end
- love.graphics.setColor(255, 255, 255, 255)
- love.graphics.draw(hotbar, love.graphics.getWidth()/2 - hotbar:getWidth()/2, love.graphics.getHeight() - hotbar:getHeight())
- love.graphics.draw(highlight, love.graphics.getWidth()/2 - hotbar:getWidth()/2 + 20 + 54 * (selected - 1), love.graphics.getHeight() - hotbar:getHeight() + 8)
- for i = 1, 9 do
- if player.hotbar[i].id ~= nil then
- local base = tileBase(player.hotbar[i].id)
- if base ~= nil then love.graphics.draw(images[base][1], love.graphics.getWidth()/2 - hotbar:getWidth()/2 + 39 + 54 * (i - 1), love.graphics.getHeight() - hotbar:getHeight() + 26, 0, 1, 1, images[player.hotbar[i].id][1]:getWidth()/2, images[player.hotbar[i].id][1]:getHeight()/2) end
- love.graphics.draw(images[player.hotbar[i].id][1], love.graphics.getWidth()/2 - hotbar:getWidth()/2 + 39 + 54 * (i - 1), love.graphics.getHeight() - hotbar:getHeight() + 26, 0, 1, 1, images[player.hotbar[i].id][1]:getWidth()/2, images[player.hotbar[i].id][1]:getHeight()/2)
- love.graphics.print(player.hotbar[i].count, love.graphics.getWidth()/2 - hotbar:getWidth()/2 + 50 + 54 * (i - 1), love.graphics.getHeight() - hotbar:getHeight() + 35)
+ if showInventory then
+ player:drawInventory(selected)
+ if pickedItem.id ~= nil then
+ love.mouse.setVisible(false)
+ local x = love.mouse.getX()
+ local y = love.mouse.getY()
+ love.graphics.setColor(255, 255, 255, 255)
+ local base = tileBase(pickedItem.id)
+ if base ~= nil then love.graphics.draw(images[base][1], x, y, 0, 1, 1, images[pickedItem.id][1]:getWidth()/2, images[pickedItem.id][1]:getHeight()/2) end
+ love.graphics.draw(images[pickedItem.id][1], x, y, 0, 1, 1, images[pickedItem.id][1]:getWidth()/2, images[pickedItem.id][1]:getHeight()/2)
+ love.graphics.print(pickedItem.count, x + 11, y + 9)
+ else
+ love.mouse.setVisible(true)
end
+ else
+ player:drawHotbar(selected.hotbar)
end
if debug then
@@ -201,25 +150,36 @@ end
function love.keypressed(k, u)
+ if showInventory then
+ if k == "escape" and pickedItem.id == nil then
+ showInventory = false
+ end
+ else
+ if k == "escape" then
+ generator:send("command", "quit")
+ generator:wait()
+ love.event.push("q")
+ elseif k == " " then
+ if player.hook.fired then
+ player.hook:reset()
+ hookRelease = true
+ end
+ end
+ end
+
if k == "p" then
- showPerlin = not showPerlin
- elseif k == "escape" then
- generator:send("command", "quit")
- generator:wait()
- love.event.push("q")
+ --showPerlin = not showPerlin
+ elseif k == "f3" then
+ debug = not debug
+ instamine = debug
+ elseif k == "e" and pickedItem.id == nil then
+ showInventory = not showInventory
elseif k == "[" then
if view.zoom > 1 then view.zoom = view.zoom / 2 end
elseif k == "]" then
if view.zoom < 256 then view.zoom = view.zoom * 2 end
- elseif k == "f3" then
- debug = not debug
- instamine = debug
- elseif k == " " then
- if player.hook.fired then
- player.hook:reset()
- hookRelease = true
- end
end
+
end
@@ -233,14 +193,24 @@ end
function love.mousepressed(x, y, button)
- if button == "m" then
- player.hook:fire(player.x, player.y - player.height/2, cursor.x - player.x, cursor.y - (player.y - player.height/2))
- elseif button == "wd" then
- selected = selected + 1
- if selected == 10 then selected = 1 end
- elseif button == "wu" then
- selected = selected - 1
- if selected == 0 then selected = 9 end
+ if showInventory then
+ if selected.r ~= nil and selected.c ~= nil then
+ if button == "l" then
+ local tempItem = player:takeSlot(selected.r, selected.c, player:checkSlot(selected.r, selected.c).count)
+ player:setSlot(selected.r, selected.c, pickedItem)
+ pickedItem = tempItem
+ end
+ end
+ else
+ if button == "m" then
+ player.hook:fire(player.x, player.y - player.height/2, cursor.x - player.x, cursor.y - (player.y - player.height/2))
+ elseif button == "wd" then
+ selected.hotbar = selected.hotbar + 1
+ if selected.hotbar == 10 then selected.hotbar = 1 end
+ elseif button == "wu" then
+ selected.hotbar = selected.hotbar - 1
+ if selected.hotbar == 0 then selected.hotbar = 9 end
+ end
end
end
View
127 player.lua
@@ -33,10 +33,14 @@ function Player:new()
o.direction = 1
o.hook = GrapplingHook:new(o)
o.landTime = 0
- o.hotbar = {}
- for i = 1, 9 do
- o.hotbar[i] = {}
+ o.inventory = {}
+ for r = 1, 4 do
+ o.inventory[r] = {}
+ for c = 1, 9 do
+ o.inventory[r][c] = {}
+ end
end
+ o.hotbar = o.inventory[4]
return o
end
@@ -44,41 +48,53 @@ end
function Player:give(thing)
if thing == nil then return false end
- for i = 1, 9 do
- if self.hotbar[i].id == thing and self.hotbar[i].count ~= nil and self.hotbar[i].count < 64 then
- self.hotbar[i].count = self.hotbar[i].count + 1
- return true
+ for r = 4, 1, -1 do
+ for c = 1, 9 do
+ if self.inventory[r][c].id == thing and self.inventory[r][c].count ~= nil and self.inventory[r][c].count < 64 then
+ self.inventory[r][c].count = self.inventory[r][c].count + 1
+ return true
+ end
end
end
- for i = 1, 9 do
- if self.hotbar[i].id == nil then
- self.hotbar[i].id = thing
- self.hotbar[i].count = 1
- return true
+ for r = 4, 1, -1 do
+ for c = 1, 9 do
+ if self.inventory[r][c].id == nil then
+ self.inventory[r][c].id = thing
+ self.inventory[r][c].count = 1
+ return true
+ end
end
end
return false
end
-function Player:takeSlot(slot)
- assert (slot ~= nil)
- assert (slot >= 1)
- assert (slot <= 9)
- if self.hotbar[slot].id == nil or self.hotbar[slot].count == nil or self.hotbar[slot].count <= 0 then return nil
+function Player:takeSlot(r, c, count)
+ assert (r ~= nil and c ~= nil)
+ assert (r >= 1 and r <= 4)
+ assert (c >= 1 and c <= 9)
+ if count == nil then count = 1 end
+ if self.inventory[r][c].id == nil or self.inventory[r][c].count == nil or self.inventory[r][c].count - count < 0 then return {id = nil, count = 0}
else
- self.hotbar[slot].count = self.hotbar[slot].count - 1
- local id = self.hotbar[slot].id
- if self.hotbar[slot].count == 0 then self.hotbar[slot].id = nil end
- return id
+ self.inventory[r][c].count = self.inventory[r][c].count - count
+ local id = self.inventory[r][c].id
+ if self.inventory[r][c].count == 0 then self.inventory[r][c].id = nil end
+ return {id = id, count = count}
end
end
-function Player:checkSlot(slot)
- assert (slot ~= nil)
- assert (slot >= 1)
- assert (slot <= 9)
- if self.hotbar[slot].id == nil or self.hotbar[slot].count == nil or self.hotbar[slot].count <= 0 then return nil
- else return self.hotbar[slot].id end
+function Player:setSlot(r, c, stuff)
+ assert (r ~= nil and c ~= nil)
+ assert (r >= 1 and r <= 4)
+ assert (c >= 1 and c <= 9)
+ self.inventory[r][c] = stuff
+end
+
+function Player:checkSlot(r, c)
+ assert (r ~= nil and c ~= nil)
+ assert (r >= 1 and r <= 4)
+ assert (c >= 1 and c <= 9)
+ if self.inventory[r][c].id == nil or self.inventory[r][c].count == nil or self.inventory[r][c].count <= 0 then return {id = nil, count = 0}
+ else return {id = self.inventory[r][c].id, count = self.inventory[r][c].count} end
end
function Player:update(dt)
@@ -90,22 +106,22 @@ function Player:update(dt)
else
if self.falling and not self.hook.hooked then
self.vy = self.vy + g * dt
- if love.keyboard.isDown("a") and not self.againstLeftWall then
+ if love.keyboard.isDown("a") and not self.againstLeftWall and not showInventory then
self.vx = math.max(-8, self.vx - 16 * dt)
self.direction = -1
self.landTime = 0
- elseif love.keyboard.isDown("d") and not self.againstRightWall then
+ elseif love.keyboard.isDown("d") and not self.againstRightWall and not showInventory then
self.vx = math.min( 8, self.vx + 16 * dt)
self.direction = 1
self.landTime = 0
end
end
if not first and not self.falling and not self.hook.hooked then
- if love.keyboard.isDown("a") and not self.againstLeftWall then
+ if love.keyboard.isDown("a") and not self.againstLeftWall and not showInventory then
self.vx = math.max(-8, self.vx - 36 * dt)
self.direction = -1
self.landTime = 0
- elseif love.keyboard.isDown("d") and not self.againstRightWall then
+ elseif love.keyboard.isDown("d") and not self.againstRightWall and not showInventory then
self.vx = math.min( 8, self.vx + 36 * dt)
self.direction = 1
self.landTime = 0
@@ -116,7 +132,7 @@ function Player:update(dt)
self.x = self.x + self.vx * dt
self.y = self.y + self.vy * dt
- if not self.falling and math.abs(self.vx) > 0.5 and (love.keyboard.isDown("a") or love.keyboard.isDown("d")) then
+ if not self.falling and math.abs(self.vx) > 0.5 and (love.keyboard.isDown("a") or love.keyboard.isDown("d")) and not showInventory then
if not self.walking then self.walk:seek(5) end
self.walking = true
else
@@ -142,3 +158,50 @@ function Player:draw(view)
love.graphics.draw(self.stand, (self.x-view.x)*view.zoom + love.graphics.getWidth()/2, (self.y-view.y+0.1)*view.zoom + love.graphics.getHeight()/2, 0, self.direction * view.zoom/32, view.zoom/32, 34, 103)
end
end
+
+function Player:drawHotbar(selected)
+ love.graphics.setColor(255, 255, 255, 255)
+ love.graphics.draw(hotbar, love.graphics.getWidth()/2 - hotbar:getWidth()/2, love.graphics.getHeight() - hotbar:getHeight())
+ love.graphics.draw(highlight, love.graphics.getWidth()/2 - hotbar:getWidth()/2 + 20 + 54 * (selected - 1), love.graphics.getHeight() - hotbar:getHeight() + 8)
+
+ for i = 1, 9 do
+ if player.hotbar[i].id ~= nil then
+ local base = tileBase(player.hotbar[i].id)
+ if base ~= nil then love.graphics.draw(images[base][1], love.graphics.getWidth()/2 - hotbar:getWidth()/2 + 39 + 54 * (i - 1), love.graphics.getHeight() - hotbar:getHeight() + 26, 0, 1, 1, images[player.hotbar[i].id][1]:getWidth()/2, images[player.hotbar[i].id][1]:getHeight()/2) end
+ love.graphics.draw(images[player.hotbar[i].id][1], love.graphics.getWidth()/2 - hotbar:getWidth()/2 + 39 + 54 * (i - 1), love.graphics.getHeight() - hotbar:getHeight() + 26, 0, 1, 1, images[player.hotbar[i].id][1]:getWidth()/2, images[player.hotbar[i].id][1]:getHeight()/2)
+ love.graphics.print(player.hotbar[i].count, love.graphics.getWidth()/2 - hotbar:getWidth()/2 + 50 + 54 * (i - 1), love.graphics.getHeight() - hotbar:getHeight() + 35)
+ end
+ end
+end
+
+function Player:drawInventory(selected)
+ love.graphics.setColor(0, 0, 0, 128)
+ love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
+ love.graphics.setColor(255, 255, 255, 255)
+ love.graphics.draw(inventory, love.graphics.getWidth()/2 - inventory:getWidth()/2, love.graphics.getHeight()/2 - inventory:getHeight()/2)
+ if selected.r == nil or selected.c == nil then
+ -- Do nothing
+ elseif selected.r >= 1 and selected.r <= 3 then
+ love.graphics.draw(highlight, love.graphics.getWidth()/2 - inventory:getWidth()/2 + 20 + 54 * (selected.c - 1), love.graphics.getHeight()/2 - inventory:getHeight()/2 + 224 + 52 * (selected.r - 1))
+ elseif selected.r == 4 then
+ love.graphics.draw(highlight, love.graphics.getWidth()/2 - inventory:getWidth()/2 + 20 + 54 * (selected.c - 1), love.graphics.getHeight()/2 - inventory:getHeight()/2 + 404)
+ end
+
+ local offsetY
+ for r = 1, 4 do
+ if r < 4 then offsetY = 242 + 52 * (r - 1)
+ else offsetY = 422
+ end
+ for c = 1, 9 do
+ if player.inventory[r][c].id ~= nil then
+ local base = tileBase(player.inventory[r][c].id)
+
+ if base ~= nil then love.graphics.draw(images[base][1], love.graphics.getWidth()/2 - inventory:getWidth()/2 + 39 + 54 * (c - 1), love.graphics.getHeight()/2 - inventory:getHeight()/2 + offsetY, 0, 1, 1, images[player.inventory[r][c].id][1]:getWidth()/2, images[player.inventory[r][c].id][1]:getHeight()/2) end
+
+ love.graphics.draw(images[player.inventory[r][c].id][1], love.graphics.getWidth()/2 - inventory:getWidth()/2 + 39 + 54 * (c - 1), love.graphics.getHeight()/2 - inventory:getHeight()/2 + offsetY, 0, 1, 1, images[player.inventory[r][c].id][1]:getWidth()/2, images[player.inventory[r][c].id][1]:getHeight()/2)
+
+ love.graphics.print(player.inventory[r][c].count, love.graphics.getWidth()/2 - inventory:getWidth()/2 + 50 + 54 * (c - 1), love.graphics.getHeight()/2 - inventory:getHeight()/2 + offsetY + 9)
+ end
+ end
+ end
+end
View
8 terrain.lua
@@ -110,13 +110,7 @@ function Terrain:checkGenerator()
if chunk ~= nil then
chunkNew = TSerial.unpack(chunk)
chunk = self:getChunk(chunkNew.r, chunkNew.c)
- for r = 1, 32 do
- for c = 1, 32 do
- chunk.block[r][c] = chunkNew.block[r][c]
- chunk.perlin[r][c] = chunkNew.perlin[r][c]
- chunk.coalNoise[r][c] = chunkNew.coalNoise[r][c]
- end
- end
+ chunk.block = chunkNew.block
chunk.generated = true
chunk.hasDirt = chunkNew.hasDirt
chunk:renderPerlin()
Please sign in to comment.
Something went wrong with that request. Please try again.