Add in clunky stairs
This commit is contained in:
parent
7f61766b0b
commit
ab7879e9f7
@ -1,8 +1,12 @@
|
||||
--basic grid based collision detection
|
||||
|
||||
function collision(oldposx,oldposy)
|
||||
|
||||
if (player.playerx > mapwidth or player.playerx <= 0) or (player.playery > mapheight or player.playery <= 0) or tiles[player.playerx][player.playery]["block"] ~= 0 then
|
||||
--stairs
|
||||
if (player.playerx <= mapwidth and player.playerx > 1) and
|
||||
(player.playery < mapheight and player.playery > 1) and
|
||||
tiles[player.playerx][player.playery]["block"] == 2 then
|
||||
player.playery = player.playery - 1
|
||||
elseif (player.playerx > mapwidth or player.playerx <= 0) or (player.playery > mapheight or player.playery <= 0) or tiles[player.playerx][player.playery]["block"] ~= 0 then
|
||||
player.playerx,player.playery = oldposx,oldposy
|
||||
--can't move
|
||||
oof:setPitch(love.math.random(65,100)/100)
|
||||
@ -19,7 +23,7 @@ gravtimer = 0
|
||||
function gravity(dt)
|
||||
if player.playery < mapheight and tiles[player.playerx][player.playery+1]["block"] == 0 then
|
||||
gravtimer = gravtimer + dt
|
||||
if gravtimer >= 0.35 then
|
||||
if gravtimer >= 0.2 then
|
||||
local oldposx,oldposy = player.playerx,player.playery
|
||||
|
||||
player.playery = player.playery + 1
|
||||
|
1
inventory.lua
Normal file
1
inventory.lua
Normal file
@ -0,0 +1 @@
|
||||
--the inventory library
|
13
map.lua
13
map.lua
@ -13,12 +13,7 @@ function maplib.createmap()
|
||||
for y = 1,mapheight do
|
||||
tiles[x][y] = {}
|
||||
|
||||
local randomtile = love.math.random(0,1)
|
||||
if randomtile == 0 then
|
||||
tiles[x][y]["block"] = 0
|
||||
elseif randomtile == 1 then
|
||||
tiles[x][y]["block"] = 1
|
||||
end
|
||||
tiles[x][y]["block"] = love.math.random(0,1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -31,9 +26,11 @@ function maplib.draw()
|
||||
for y = 1,mapheight do
|
||||
local graphic
|
||||
if tiles[x][y]["block"] == 0 then
|
||||
graphic = ""
|
||||
graphic = "" --air
|
||||
elseif tiles[x][y]["block"] == 1 then
|
||||
graphic = "#"
|
||||
graphic = "#" --stone
|
||||
elseif tiles[x][y]["block"] == 2 then
|
||||
graphic = "/" --stairs
|
||||
end
|
||||
love.graphics.print(graphic, x*scale, y*scale)
|
||||
end
|
||||
|
7
menu.lua
7
menu.lua
@ -86,6 +86,13 @@ function menu.draw()
|
||||
--debug mouse's pos
|
||||
love.graphics.setColor(255,255,255,255)
|
||||
love.graphics.print("MX:"..mx.." MY:"..my, 400,220)
|
||||
--debug selected item
|
||||
love.graphics.setColor(255,255,255,255)
|
||||
if player.selected == 1 then
|
||||
love.graphics.print("ITEM: #", 400,250)
|
||||
elseif player.selected == 2 then
|
||||
love.graphics.print("ITEM: /", 400,250)
|
||||
end
|
||||
end
|
||||
|
||||
function menu.cursor()
|
||||
|
16
player.lua
16
player.lua
@ -1,9 +1,10 @@
|
||||
--the player library
|
||||
player = {}
|
||||
player.playerx,player.playery = 1,1
|
||||
player.playerx,player.playery = 1,38
|
||||
|
||||
player.mining = true
|
||||
|
||||
player.selected = 1
|
||||
--controls
|
||||
|
||||
function love.keypressed( key, scancode, isrepeat )
|
||||
@ -27,17 +28,24 @@ function love.keypressed( key, scancode, isrepeat )
|
||||
end
|
||||
|
||||
--footsteps
|
||||
if collision(oldposx,oldposy) ~= true and (player.playery < mapheight and tiles[oldposx][oldposy+1]["block"] ~= 0) then
|
||||
if collision(oldposx,oldposy) ~= true and oldposy < mapheight and tiles[oldposx][oldposy+1]["block"] ~= 0 then
|
||||
stepsound:setPitch(love.math.random(50,100)/100)
|
||||
stepsound:stop()
|
||||
stepsound:play()
|
||||
end
|
||||
|
||||
if key == "1" then
|
||||
player.selected = 1
|
||||
elseif key == "2" then
|
||||
player.selected = 2
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
--try to jump
|
||||
function jump()
|
||||
if player.playery < mapheight and tiles[player.playerx][player.playery+1]["block"] ~= 0 then
|
||||
if (player.playery < mapheight and tiles[player.playerx][player.playery+1]["block"] ~= 0) or player.playery == mapheight then
|
||||
player.playery = player.playery - 1
|
||||
end
|
||||
|
||||
@ -64,7 +72,7 @@ function mine(key)
|
||||
placesound:setPitch(love.math.random(50,100)/100)
|
||||
placesound:stop()
|
||||
placesound:play()
|
||||
tiles[mx][my]["block"] = 1
|
||||
tiles[mx][my]["block"] = player.selected
|
||||
player.mining = false
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user