From 8ec73d1d2fe4421a92c4bdaacb16988b4b65542b Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Wed, 12 Jul 2017 02:14:30 -0400 Subject: [PATCH] Rework rendering and collision box --- collision.lua | 34 +++++++++++++++++----------------- main.lua | 2 +- physics.lua | 2 ++ player.lua | 2 +- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/collision.lua b/collision.lua index 4f364be..d97fd7f 100644 --- a/collision.lua +++ b/collision.lua @@ -8,7 +8,7 @@ function collision(oldposx,oldposy) - local xer = {0.3,0.7} + local xer = {-0.2,0.2} local yer = {0,1} local fall = true @@ -16,10 +16,20 @@ function collision(oldposx,oldposy) player.playery = player.playery + player.inertiay 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]) + local squarex = math.floor(player.playerx+xer[q]) + local squarey = math.floor(player.playery+yer[r]) + + --use this to detect outside chunk 00 + local chunkerx = 0 + local chunkery = 0 + + if squarex < 1 or squarex > map_max then + print(squarex) + end + + --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 (player.playerx <= map_max and player.playerx > 1) and (player.playery < map_max and player.playery > 1) and ore[loaded_chunks[0][0][squarex1][squarey1]["block"]]["collide"] ~= false then + if (squarex <= map_max and squarex >= 1) and (squarey <= map_max and squarey >= 1) and ore[loaded_chunks[0][0][squarex][squarey]["block"]]["collide"] ~= false then player.playery = oldposy if r == 2 then player.on_block = true @@ -40,10 +50,10 @@ function collision(oldposx,oldposy) player.playerx = player.playerx + player.inertiax 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]) + local squarex = math.floor(player.playerx+xer[q]) + local squarey = 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 (player.playerx <= map_max and player.playerx > 1) and (player.playery < map_max and player.playery > 1) and ore[loaded_chunks[0][0][squarex1][squarey1]["block"]]["collide"] ~= false then + if (squarex <= map_max and squarex >= 1) and (squarey <= map_max and squarey >= 1) and ore[loaded_chunks[0][0][squarex][squarey]["block"]]["collide"] ~= false then player.inertiax = 0 player.playerx = oldposx --print("stopping x inertia and pos") @@ -51,17 +61,7 @@ function collision(oldposx,oldposy) 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 diff --git a/main.lua b/main.lua index 14beaf8..b97513a 100644 --- a/main.lua +++ b/main.lua @@ -28,7 +28,7 @@ function love.draw() maplib.draw() player.draw() menu.draw() - love.graphics.rectangle( "line", player_drawnx+(scale/4)+(scale/16), player_drawny, 0.4*scale,1*scale ) + love.graphics.rectangle( "line", player_drawnx-(scale/5), player_drawny, 0.4*scale,1*scale ) fpsGraph:draw() memGraph:draw() dtGraph:draw() diff --git a/physics.lua b/physics.lua index 86e6557..3a0ff86 100644 --- a/physics.lua +++ b/physics.lua @@ -44,6 +44,7 @@ end function physics.gravity() if player.on_block == true then --fall damage + --[[ if lastheight and math.floor(((map_max-player.playery)+(chunky*map_max))) < lastheight - 5 then --health = health - math.floor(player.inertiay*10) health = health - ((lastheight - 5) - math.floor(((map_max-player.playery)+(chunky*map_max)))) @@ -57,6 +58,7 @@ function physics.gravity() health = 10 end end + ]]-- player.inertiay = 0 lastheight = math.floor(((map_max-player.playery)+(chunky*map_max))) --print(lastheight) diff --git a/player.lua b/player.lua index 9592612..bd5e3aa 100644 --- a/player.lua +++ b/player.lua @@ -180,7 +180,7 @@ function player.draw() --love.graphics.setColor(255,0,0,255) player_drawnx,player_drawny = screenwidth/2-(scale/32)+offsetx,screenheight/2-(scale/32)+offsety--((scale*map_max)/2)+offsetx,((scale*map_max)/2)+offsety --love.graphics.print("8", player_drawnx,player_drawny ) - love.graphics.draw(playertexture, player_drawnx+(scale/4), player_drawny,0, scale/32, scale/32) + love.graphics.draw(playertexture, player_drawnx-(scale/4), player_drawny,0, scale/32, scale/32) end