Better physics
This commit is contained in:
parent
848ac0418e
commit
d5472c4e39
@ -11,12 +11,18 @@ function collision(oldposx,oldposy)
|
||||
-- loaded_chunks[0][0][player.playerx][player.playery]["block"] == 3 then
|
||||
-- player.playery = player.playery - 1
|
||||
local xer = {0.3,0.7}
|
||||
local yer = {0.3,0.7}
|
||||
local yer = {0,1}
|
||||
for q = 1,2 do
|
||||
for r = 1,2 do
|
||||
local squarex1 = math.floor(player.playerx+xer[q])
|
||||
local squarey1 = math.floor(player.playery+yer[r])
|
||||
if (squarex1 > map_max or squarex1 <= 0) or (squarey1 > map_max or squarey1 <= 0) or ore[loaded_chunks[0][0][squarex1][squarey1]["block"]]["collide"] ~= false then
|
||||
--if (squarex1 > map_max or squarex1 <= 0) or (squarey1 > map_max or squarey1 <= 0) or ore[loaded_chunks[0][0][squarex1][squarey1]["block"]]["collide"] ~= false then
|
||||
if ore[loaded_chunks[0][0][squarex1][squarey1]["block"]]["collide"] ~= false then
|
||||
--if q == 1 then
|
||||
--print("left")
|
||||
--end
|
||||
player.inertiax = 0
|
||||
player.inertiay = 0
|
||||
--print("collide")
|
||||
player.playerx,player.playery = oldposx,oldposy
|
||||
return(true)
|
||||
|
13
physics.lua
13
physics.lua
@ -7,16 +7,25 @@ player.inertiay = 0
|
||||
|
||||
--left and right
|
||||
function physics.player_mod_x(value)
|
||||
print(player.inertiax)
|
||||
--print(player.inertiax)
|
||||
if math.abs(player.inertiax+value) <= 0.1 then
|
||||
player.inertiax = player.inertiax + value
|
||||
end
|
||||
end
|
||||
--up and down
|
||||
function physics.player_mod_y(value)
|
||||
print(player.inertiay)
|
||||
if math.abs(player.inertiay+value) <= 0.1 then
|
||||
player.inertiay = player.inertiay + value
|
||||
end
|
||||
end
|
||||
--apply left and right
|
||||
function physics.player_x_apply(dt)
|
||||
local oldposx,oldposy = player.playerx,player.playery
|
||||
player.playerx = player.playerx + player.inertiax
|
||||
|
||||
player.playerx = player.playerx + player.inertiax
|
||||
player.playery = player.playery + player.inertiay
|
||||
collision(oldposx,oldposy)
|
||||
|
||||
|
||||
end
|
||||
|
35
player.lua
35
player.lua
@ -10,12 +10,9 @@ player.selected = 2
|
||||
|
||||
score = 0
|
||||
|
||||
playermovetimer = 0
|
||||
|
||||
|
||||
function move(dt)
|
||||
playermovetimer = playermovetimer + dt
|
||||
|
||||
function move(dt)
|
||||
--debug - stresstest
|
||||
--if love.keyboard.isDown("f5") then
|
||||
-- chunkx,chunky = math.random(-1000,1000),math.random(2,3)
|
||||
@ -25,13 +22,17 @@ function move(dt)
|
||||
|
||||
--local oldposx,oldposy = player.playerx,player.playery
|
||||
local oldposx,oldposy
|
||||
if love.keyboard.isDown("a","d","w") then
|
||||
--if love.keyboard.isDown("a","d","w") then
|
||||
--print("gude")
|
||||
oldposx,oldposy = player.playerx,player.playery
|
||||
playermovetimer = 0
|
||||
end
|
||||
--oldposx,oldposy = player.playerx,player.playery
|
||||
--end
|
||||
|
||||
if love.keyboard.isDown("w") then
|
||||
jump()
|
||||
--jump()
|
||||
physics.player_mod_y(-0.01)
|
||||
end
|
||||
if love.keyboard.isDown("s") then
|
||||
physics.player_mod_y(0.01)
|
||||
end
|
||||
if love.keyboard.isDown("a") then
|
||||
--player.playerx = player.playerx - 0.1
|
||||
@ -41,9 +42,13 @@ function move(dt)
|
||||
physics.player_mod_x(0.01)
|
||||
end
|
||||
|
||||
if love.keyboard.isDown("=") then
|
||||
scale = scale + 1
|
||||
elseif love.keyboard.isDown("-") then
|
||||
scale = scale - 1
|
||||
end
|
||||
|
||||
|
||||
if love.keyboard.isDown("a","d","w") then
|
||||
--if love.keyboard.isDown("a","d","w") then
|
||||
--print("guude 2")
|
||||
--local collide = maplib.new_block(oldposx,oldposy)
|
||||
|
||||
@ -57,7 +62,7 @@ function move(dt)
|
||||
end
|
||||
]]--
|
||||
--end
|
||||
end
|
||||
--end
|
||||
end
|
||||
--controls for 1 hit things
|
||||
function love.keypressed( key, scancode, isrepeat )
|
||||
@ -102,12 +107,6 @@ function love.keypressed( key, scancode, isrepeat )
|
||||
player.selected = tonumber(key)
|
||||
end
|
||||
|
||||
if key == "=" then
|
||||
scale = scale + 1
|
||||
elseif key == "-" then
|
||||
scale = scale - 1
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user