Condense collision detection into 1 function

This commit is contained in:
jordan4ibanez 2017-07-12 01:49:21 -04:00
parent 8299487d6f
commit 8ca5c029f8
2 changed files with 24 additions and 23 deletions

View File

@ -3,17 +3,17 @@
--squared collision detection
player.on_block = false
function collisiony(oldposy)
--stairs
--if (player.playerx <= map_max and player.playerx > 1) and
-- (player.playery < map_max and player.playery > 1) and
-- loaded_chunks[0][0][player.playerx][player.playery]["block"] == 3 then
-- player.playery = player.playery - 1
function collision(oldposx,oldposy)
--do stairs
local xer = {0.3,0.7}
local yer = {0,1}
local fall = true
--check the corners
--check the corners (y)
player.playery = player.playery + player.inertiay
for q = 1,2 do
for r = 1,2 do
local squarex1 = math.floor(player.playerx+xer[q])
@ -34,18 +34,10 @@ function collisiony(oldposy)
if fall == true then
player.on_block = false
end
end
function collisionx(oldposx)
--stairs
--if (player.playerx <= map_max and player.playerx > 1) and
-- (player.playery < map_max and player.playery > 1) and
-- 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,1}
local fall = true
--check the corners
--check the corners(x)
player.playerx = player.playerx + player.inertiax
for q = 1,2 do
for r = 1,2 do
local squarex1 = math.floor(player.playerx+xer[q])
@ -59,6 +51,17 @@ function collisionx(oldposx)
end
end
end
function collisionx(oldposx)
--do stairs
local xer = {0.3,0.7}
local yer = {0,1}
local fall = true
end
--make the player fall when in air
gravtimer = 0

View File

@ -24,12 +24,10 @@ function physics.player_mod_y(value)
end
--apply left and right
function physics.player_x_apply(dt)
local oldposx,oldposy = player.playerx,player.playery
--local oldposx,oldposy = player.playerx,player.playery
player.playery = player.playery + player.inertiay
collisiony(oldposy)
player.playerx = player.playerx + player.inertiax
collisionx(oldposx)
collision(player.playerx,player.playery)
--collisionx(oldposx)
--print(player.inertiax)
if math.abs(player.inertiax) <= 0.005 then
player.inertiax = 0