Screen Collision [BEGINNER]
Posted: Tue Jul 12, 2016 1:44 pm
Hey,
I am kinda new in the world of LOVE2D and I was looking for some "around the screen collision" but it seems like when I use my player to try to see if he is colliding, part of the player moves off the screen and when his speed is really high he goes off the screen. Bellow I have the code with the player's speed high so you can see the effect mentioned above. By the way the collision for the right part of the screen hasn't been done because I stopped during the process of writing the code cause I got mad !!!
I am kinda new in the world of LOVE2D and I was looking for some "around the screen collision" but it seems like when I use my player to try to see if he is colliding, part of the player moves off the screen and when his speed is really high he goes off the screen. Bellow I have the code with the player's speed high so you can see the effect mentioned above. By the way the collision for the right part of the screen hasn't been done because I stopped during the process of writing the code cause I got mad !!!
Code: Select all
function love.load()
player = {}
player.x = 100
player.y = 100
player.w = 100
player.h = 100
player.speed = 100
end
function love.update(dt)
if player.x < 0 then
player.x = 0
end
if player.y < 0 then
player.y = 0
end
if player.y + player.h >= 600 then
player.y = 600 - player.h
end
if love.keyboard.isDown("left") then
player.x = player.x - player.speed
end
if love.keyboard.isDown("right") then
player.x = player.x + player.speed
end
if love.keyboard.isDown("up") then
player.y = player.y - player.speed
end
if love.keyboard.isDown("down") then
player.y = player.y + player.speed
end
end
function love.draw()
love.graphics.rectangle("fill", player.x, player.y, player.w, player.h)
end