player = {}
function player.load()
player.x = 5
player.y = 5
player.xvel = 0
player.yvel = 0
player.friction = 7
player.speed = 2250
player.width = 50
player.height = 5
end
function player.draw()
if love.keyboard.isDown('left') then
stance1 = love.graphics.newImage("images/jackstance2.png")
love.graphics.draw(stance1, player.x, player.y)
else
stance1 = love.graphics.newImage("images/jackstance1.png")
love.graphics.draw(stance1, player.x, player.y)
end
end
function player.physics(dt)
player.x = player.x + player.xvel * dt
player.y = player.y + player.yvel * dt
player.yvel = player.yvel + gravity * dt
player.xvel = player.xvel * (1 - math.min(dt*player.friction, 1))
end
function player.move(dt)
if love.keyboard.isDown('right') and
player.xvel < player.speed then
player.xvel = player.xvel + player.speed * dt
end
if love.keyboard.isDown('left') and
player.xvel > -player.speed then
player.xvel = player.xvel - player.speed * dt
end
end
function player.boundary()
if player.x < 0 then
player.x = 0
player.xvel = 0
end
if player.y + player.height > groundlevel then
player.y = groundlevel - player.height
player.yvel = 0
end
end
function UPDATE_PLAYER(dt)
player.physics(dt)
player.move(dt)
end
function DRAW_PLAYER()
player.draw()
end
I have this code, and in the function player.boundary(), ground level is set to 700, and screen height is 750. However, when i run the game, it oddly makes me fall through the set boundary. Any causes for this? EDIT: So I figured out what i did wrong. I forgot to add player.boundary() into function UPDATE_PLAYER(dt)
Last edited by Cvear on Mon Sep 28, 2015 3:55 am, edited 1 time in total.