Hey, I'm really new to LOVE and I just don't know how to restrict a simple key-controlled rectangle to the screen. I don't want it to pass the edges of the screen. There has to be an unbelievably simple way of doing this, but I couldn't find it in the API or the forums. Maybe I wasn't looking in the right place.
The other thing I need to do is restrict the rectangle from moving past the edges of other objects. I read on the API that you can do a lot without love.physics and so I'd like to be able to this without it if possible.
Basically my end goal here is a simple prototype of a square cursor moving through a maze made up of other rectangles, but with anything I draw, the square just keeps passing through the edges of any other shape. I just need to limit it to only being able to move in the empty areas of the screen.
Thanks so much!
Restrict Rectangle Movement
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Restrict Rectangle Movement
You're going to need to create a map of passable and impassable squares: a grid of tiles. There's an uncountable number of ways you could do this, but perhaps this tutorial will help you a little. http://love2d.org/wiki/Tutorial:Tile-based_Scrolling
Kurosuke needs beta testers
Re: Restrict Rectangle Movement
Don't think in terms of Love API, but how to program it in a programming language (Lua in this case).tdq11 wrote:Hey, I'm really new to LOVE and I just don't know how to restrict a simple key-controlled rectangle to the screen. I don't want it to pass the edges of the screen. There has to be an unbelievably simple way of doing this, but I couldn't find it in the API or the forums. Maybe I wasn't looking in the right place.
The other thing I need to do is restrict the rectangle from moving past the edges of other objects. I read on the API that you can do a lot without love.physics and so I'd like to be able to this without it if possible.
Basically my end goal here is a simple prototype of a square cursor moving through a maze made up of other rectangles, but with anything I draw, the square just keeps passing through the edges of any other shape. I just need to limit it to only being able to move in the empty areas of the screen.
Thanks so much!
Hint: each of the rectangle vertex/edge must be on the screen (so you need to know vertex coordinates and screen size).
Similarly, if your cursor move would collide with any other object, then the move is not allowed.
Check out the attachment
- Attachments
-
- CollisionExample.love
- (819 Bytes) Downloaded 180 times
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Re: Restrict Rectangle Movement
Thanks a lot, guys. It's great to be pointed in the right direction, because there's a lot to learn. I tried doing it in love.physics, but I think that was quite a bit too complicated for something this rudimentary.
Who is online
Users browsing this forum: Bing [Bot] and 3 guests