Page 1 of 1

[SOLVED] Why do i pass through the barrier i made?

Posted: Mon Sep 28, 2015 2:28 am
by Cvear

Code: Select all


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)

Re: Why do i pass through the barrier i made?

Posted: Mon Sep 28, 2015 3:01 am
by Fang86
If you upload a .love, I could help. To do this, follow these instructions: viewtopic.php?f=4&t=451

Re: Why do i pass through the barrier i made?

Posted: Mon Sep 28, 2015 3:19 am
by Cvear
Here is the .love file.

Re: Why do i pass through the barrier i made?

Posted: Mon Sep 28, 2015 3:54 am
by Fang86
I'm definitely not the most qualified to be trying to help but I can't find anything wrong.

Re: [SOLVED] Why do i pass through the barrier i made?

Posted: Mon Sep 28, 2015 3:56 am
by Cvear
I found out what I did wrong. It's ok.