Now that that's out of the way, onto the issue.
My familiarity with Lua, and programming in general, are both still very early in development, though I'm doing the best that I can. I can't seem to figure out how to use return values such as true or false when they are given by a function, such as the CheckCollision functions within the code provided. Any help would be greatly appreciated. Thank you for your time.
Code: Select all
function love.load()
f = love.graphics --Shortcut to love.graphics(my 'g' key is broken and does not work)
px = -15 --The player's x-position
py = 32 --The player's y-position
pw = 32 --Player Width
ph = 32 --Player height
x1 = 32
x2 = 468
x3 = 468
x4 = 403
x5 = 105
x6 = 105
x7 = 568
y1 = 345
y2 = 240
y3 = 0
y4 = 35
y5 = 0
y6 = 447
y7 = 410
w1 = 105
w2 = 37
w3 = 37
w4 = 65
w5 = 37
w6 = 105
w7 = 37
h1 = 37
h2 = 105
h3 = 105
h4 = 37
h5 = 105
h6 = 37
h7 = 105
xCoord = 5
yCoord = 5
y = 0
x = 0
end
function love.update(dt)
x = math.floor(px)
y = math.floor(py)
if (px >= -16) and (px <= 32) then --Makes the player come into the screen from the left border
px = px + 50*dt
end
if px == 32 then --Stops the player at a specific location
px = 32
end
if love.keyboard.isDown("down") then
py = py + 100*dt
if py >= 536 then
py = 536
end
end
if love.keyboard.isDown("up") then
py = py - 100*dt
if py <= 32 then
py = 32
end
end
if love.keyboard.isDown("right") then
px = px + 100*dt
if (px >= 736) and (py >= 64) then
px = 736
elseif (px >= 736) and (py == 64) then
px = px
end
end
if love.keyboard.isDown("left") then
px = px - 100*dt
if px <= 32 then
px = 32
end
end
if CheckCollision1 == true then
px = x1+w1
x1 = px+pw
py = y1+h1
y1 = py+ph
end
if CheckCollision2 == true then
px = x2+w2
x2 = px+pw
py = y2+h2
y2 = py+ph
end
if CheckCollision3 == true then
px = x3+w3
x3 = px+pw
py = y3+h3
y3 = py+ph
end
if CheckCollision4 == true then
px = x4+w4
x4 = px+pw
py = y4+h4
y4 = py+ph
end
if CheckCollision5 == true then
px = x5+w5
x5 = px+pw
py = y5+h5
y5 = py+ph
end
if CheckCollision6 == true then
px = x6+w6
x6 = px+pw
py = y6+h6
y6 = py+ph
end
if CheckCollision7 == true then
px = x7+w7
x7 = px+pw
py = y17h7
y7 = py+ph
end
end
function love.draw()
f.setBackgroundColor(150,150,150,255)
f.setColor(0,0,0,255)
f.rectangle("fill",x1,y1,w1,h1)
f.setColor(0,0,0,255)
f.rectangle("fill",x2,y2,w2,h2)
f.setColor(0,0,0,255)
f.rectangle("fill",x3,y3,w3,h3)
f.setColor(0,0,0,255)
f.rectangle("fill",x4,y4,w4,h4)
f.setColor(0,0,0,255)
f.rectangle("fill",x5,y5,w5,h5)
f.setColor(0,0,0,255)
f.rectangle("fill",x6,y6,w6,h6)
f.setColor(0,0,0,255)
f.rectangle("fill",x7,y7,w7,h7)
f.setColor(0,255,64,255)
f.rectangle("fill",px,py,pw,ph)
f.setColor( 255, 0, 255, 255 )
local isTrue = ""
f.print( "Player coordinates: ("..x..","..y..")", xCoord, yCoord )
end
function CheckCollision1(px,py,pw,ph, x1,y1,w1,h1)
return
px < x1+w1 and
x1 < px+pw and
py < y1+h1 and
y1 < py+ph
end
function CheckCollision2(px,py,pw,ph, x2,y2,w2,h2)
return
px < x2+w2 and
x2 < px+pw and
py < y2+h2 and
y2 < py+ph
end
function CheckCollision3(px,py,pw,ph, x3,y3,w3,h3)
return
px < x3+w3 and
x3 < px+pw and
py < y3+h3 and
y3 < py+ph
end
function CheckCollision4(px,py,pw,ph, x4,y4,w4,h4)
return
px < x4+w4 and
x4 < px+pw and
py < y4+h4 and
y4 < py+ph
end
function CheckCollision5(px,py,pw,ph, x5,y5,w5,h5)
return
px < x5+w5 and
x5 < px+pw and
py < y5+h5 and
y5 < py+ph
end
function CheckCollision6(px,py,pw,ph, x6,y6,w6,h6)
return
px < x6+w6 and
x6 < px+pw and
py < y6+h6 and
y6 < py+ph
end
function CheckCollision7(px,py,pw,ph, x7,y7,w7,h7)
return
px < x7+w7 and
x7 < px+pw and
py < y7+h7 and
y7 < py+ph
end
function love.focus(bool)
if bool == false then --Quits the program if the mouse clicks outside of the screen
love.event.quit()
end
end