Need a little help with something

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
User avatar
TehPencilmaster
Prole
Posts: 4
Joined: Thu Jan 02, 2014 11:46 am

Need a little help with something

Post by TehPencilmaster »

Hello! I'm new to the forums and I'm currently making my first LOVE2D game.

First off, is there a way to check if the player is touching the walls of the levels? I don't need collisions, it's just that I'm making a game where touching the walls results in death.

Thanks!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Need a little help with something

Post by Robin »

Welcome!
TehPencilmaster wrote:First off, is there a way to check if the player is touching the walls of the levels?
Sure!

Do you mean you want to check if the player is touching the left or right edge of the window?

You'd do it something like this:

Code: Select all

if player.x < 0 or player.x + player.width > love.window.getWidth() then
    -- player dies
end
Help us help you: attach a .love.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Need a little help with something

Post by Plu »

Not by default. You'll need to calculate collisions yourself. (Or use a library)

(And touching is collisions; what you don't need is collision handling)

What kind of walls do you have? Are these tiled blocks? You can just iterate over those and compare their coordinates with the player with a little bit of rectangle math. Or have you drawn a level on an image? That'll be a little harder probably.

Give us some more information on what your game and walls look like and how accurate you want collisions and we can help you out :)
User avatar
TehPencilmaster
Prole
Posts: 4
Joined: Thu Jan 02, 2014 11:46 am

Re: Need a little help with something

Post by TehPencilmaster »

Well, basically, these are the kind of walls it has. With each level the walls get absurder. I just want to make it that the player gets teleported once touching the walls (I know how to do the teleportation though)

Image

Image
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Need a little help with something

Post by Plu »

I'm assuming each of those walls is an entity of sorts? If so, you need to loop over your list of wall pieces and compare their location with that of the player to detect overlap.

For some idea on how to detect rectangle overlap, check out this:
http://stackoverflow.com/questions/1339 ... tersection

The accepted answer should get you on the right path :)
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Need a little help with something

Post by kikito »

There is also [wiki]BoundingBox.lua[/wiki]
When I write def I mean function.
User avatar
TehPencilmaster
Prole
Posts: 4
Joined: Thu Jan 02, 2014 11:46 am

Re: Need a little help with something

Post by TehPencilmaster »

Well, to be honest, the white square is a rectangle which gets moved by variables and the level is actually an image being loaded.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests