Tommy: Added screen edge detection
This commit is contained in:
parent
fe2e540963
commit
14a36ae366
@ -1,5 +1,32 @@
|
|||||||
require "Tserial"
|
require "Tserial"
|
||||||
|
|
||||||
|
--Detect when player hits screen edges
|
||||||
|
function colDetect()
|
||||||
|
-- Is it above 0? Awesome, we're probably on screen
|
||||||
|
if player.x >= 0 then
|
||||||
|
-- Is it below the screen width minus the plaers width?
|
||||||
|
if player.x >= (screen.w - player.w) then
|
||||||
|
--No? Guess we better stop our guy from going off screen
|
||||||
|
--by setting his position to the screen edge
|
||||||
|
player.x = screen.w - player.w
|
||||||
|
end
|
||||||
|
-- Oh, we weren't above or equal to 0?
|
||||||
|
-- Obviously it can't be above the max if it is 0 or less
|
||||||
|
-- so let's just set it to 0
|
||||||
|
else player.x = 0
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Same as above except for y
|
||||||
|
if player.y >= 0 then
|
||||||
|
if player.y >= (screen.h - player.h) then
|
||||||
|
player.y = screen.h - player.h
|
||||||
|
end
|
||||||
|
else
|
||||||
|
player.y = 0
|
||||||
|
end
|
||||||
|
return player.x, player.y
|
||||||
|
end
|
||||||
--Create a function to deal with acceleration
|
--Create a function to deal with acceleration
|
||||||
--accel is just a TRUE/False flag that tells us if we want to accel or decel
|
--accel is just a TRUE/False flag that tells us if we want to accel or decel
|
||||||
--axis is directional speed, shoudl probably change its name
|
--axis is directional speed, shoudl probably change its name
|
||||||
@ -40,11 +67,17 @@ function love.load()
|
|||||||
|
|
||||||
-- Check if Save file exists
|
-- Check if Save file exists
|
||||||
save_exists = love.filesystem.exists(saveFile)
|
save_exists = love.filesystem.exists(saveFile)
|
||||||
|
|
||||||
|
-- Create a table and grab the screen width/height for colision detection
|
||||||
|
screen = {}
|
||||||
|
screen.w = love.graphics.getWidth()
|
||||||
|
screen.h = love.graphics.getHeight()
|
||||||
|
|
||||||
-- Create a table to hold all the player data
|
-- Create a table to hold all the player data
|
||||||
player = {}
|
player = {}
|
||||||
-- Player x/y position
|
-- Player x/y position
|
||||||
player.x = 100
|
player.x = 250
|
||||||
player.y = 100
|
player.y = 250
|
||||||
-- player height/width
|
-- player height/width
|
||||||
player.w = 25
|
player.w = 25
|
||||||
player.h = 25
|
player.h = 25
|
||||||
@ -181,7 +214,9 @@ function love.update(dt)
|
|||||||
|
|
||||||
player.x = player.x + (player.current_speed.x)*dt
|
player.x = player.x + (player.current_speed.x)*dt
|
||||||
player.y = player.y + (player.current_speed.y)*dt
|
player.y = player.y + (player.current_speed.y)*dt
|
||||||
|
|
||||||
|
--Make sure player doesn't go off screen
|
||||||
|
colDetect()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user