WARNING EXTREMELY NEW AND NEEDS HELP ON A BASIC PLATFORMER

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
tyrone8104
Prole
Posts: 2
Joined: Thu Jun 28, 2018 9:20 pm

WARNING EXTREMELY NEW AND NEEDS HELP ON A BASIC PLATFORMER

Post by tyrone8104 »

So i'm trying to make a small program that's like the platformer in the Tutorial. But there is a drawn square in the corner and when the player square touches it an image pops up like a jumpscare. Any help towards what to do?
User avatar
BruceTheGoose
Citizen
Posts: 76
Joined: Sat Sep 20, 2014 2:54 pm

Re: WARNING EXTREMELY NEW AND NEEDS HELP ON A BASIC PLATFORMER

Post by BruceTheGoose »

A simple way is to check AABB collision between the player and the square.

Here is a simple general purpose AABB function you can use

Code: Select all


checkCollision = function(x1,y1,w1,h1,x2,y2,w2,h2)

    return (x1 + w1 > x2) and (x1 < x2 + w2) and (y1 + h1 > y2) and (y1 < y2 + h2)

end
-- Here is how you would use it

if(checkCollision(...)) then
	-- SCARE
end

Last edited by BruceTheGoose on Sun Jul 01, 2018 1:18 am, edited 2 times in total.
"I don't know."
tyrone8104
Prole
Posts: 2
Joined: Thu Jun 28, 2018 9:20 pm

Re: WARNING EXTREMELY NEW AND NEEDS HELP ON A BASIC PLATFORMER

Post by tyrone8104 »

thank you for showing me that script can you also help me with a script to make an image appear thank you
User avatar
BruceTheGoose
Citizen
Posts: 76
Joined: Sat Sep 20, 2014 2:54 pm

Re: WARNING EXTREMELY NEW AND NEEDS HELP ON A BASIC PLATFORMER

Post by BruceTheGoose »

tyrone8104 wrote: Sun Jul 01, 2018 12:32 am thank you for showing me that script can you also help me with a script to make an image appear thank you
Sure but I would have to see how your game is structured. Anyway, It would look something along the lines of this.

Code: Select all


function love.load()
    scary = love.graphics.newImage("source here")
end

function love.draw()
    if(checkCollision(...)) then
        love.graphics.draw(scary)
    end
end

checkCollision = function(x1,y1,w1,h1,x2,y2,w2,h2)
    return (x1 + w1 > x2) and (x1 < x2 + w2) and (y1 + h1 > y2) and (y1 < y2 + h2)

end

"I don't know."
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 52 guests