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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Cvear
Prole
Posts: 3
Joined: Mon Sep 28, 2015 1:56 am

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

Post 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)
Last edited by Cvear on Mon Sep 28, 2015 3:55 am, edited 1 time in total.
Fang86
Prole
Posts: 15
Joined: Fri Sep 25, 2015 2:03 am

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

Post by Fang86 »

If you upload a .love, I could help. To do this, follow these instructions: viewtopic.php?f=4&t=451
Last edited by Fang86 on Mon Sep 28, 2015 3:35 am, edited 2 times in total.
Cvear
Prole
Posts: 3
Joined: Mon Sep 28, 2015 1:56 am

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

Post by Cvear »

Here is the .love file.
Attachments
archive.love
.love file
(20.55 KiB) Downloaded 129 times
Fang86
Prole
Posts: 15
Joined: Fri Sep 25, 2015 2:03 am

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

Post by Fang86 »

I'm definitely not the most qualified to be trying to help but I can't find anything wrong.
Cvear
Prole
Posts: 3
Joined: Mon Sep 28, 2015 1:56 am

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

Post by Cvear »

I found out what I did wrong. It's ok.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Google [Bot] and 6 guests