Making a sprite "die"

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
DeadlyHooves
Prole
Posts: 2
Joined: Sat Nov 02, 2013 6:56 am

Making a sprite "die"

Post by DeadlyHooves »

So, Im new to the forums, and overall to Love2D, but I have a basic game I'm creating, and it involves the idea of whenever the player touches an enemy, he "dies"
So for my first thought, I thought "Oh! Collision detection will surely work!" and I cant find any good tutorials.
So I thought "maybe if I make it so if the enemies sprite is within a certain amount of pixels from my character it'd work!" and I cant find any tutorial for that either. I can make it so if my top left X and Y touch his it "kills" him, but I cant figure out how to make it a proximity thing?
So if ANY part of me touches him it'd kill.
If anyone can offer a poor man some code or help, that'd be wonderful ^^
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Making a sprite "die"

Post by Plu »

Collision is the right way to go. What you´re looking for is probably bounding box collision. There´s an example on the wiki:

http://love2d.org/wiki/BoundingBox.lua

Here's a visual example:

Image


What you want to do is compare the locations of the various corners of each object (which are rectangles in bounding box collision) and see if any of the points of one rectangle lies inside the other rectangle, by checking if a point in A is between the four corners of B. That's also what the code snippet posted does.
User avatar
DeadlyHooves
Prole
Posts: 2
Joined: Sat Nov 02, 2013 6:56 am

Re: Making a sprite "die"

Post by DeadlyHooves »

Thank you so much! ^^ I've been working for a couple hours trying to figure it out! Ill have to look at that tutorial long and hard till I got this!
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests