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!
Need a little help with something
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- TehPencilmaster
- Prole
- Posts: 4
- Joined: Thu Jan 02, 2014 11:46 am
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Need a little help with something
Welcome!
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:
Sure!TehPencilmaster wrote:First off, is there a way to check if the player is touching the walls of the levels?
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.
Re: Need a little help with something
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
(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
- TehPencilmaster
- Prole
- Posts: 4
- Joined: Thu Jan 02, 2014 11:46 am
Re: Need a little help with something
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)
Re: Need a little help with something
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
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
- 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
There is also [wiki]BoundingBox.lua[/wiki]
When I write def I mean function.
- TehPencilmaster
- Prole
- Posts: 4
- Joined: Thu Jan 02, 2014 11:46 am
Re: Need a little help with something
Well, to be honest, the white square is a rectangle which gets moved by variables and the level is actually an image being loaded.
Who is online
Users browsing this forum: Bing [Bot] and 3 guests