Collision - bitmap background

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
mLaPL
Prole
Posts: 20
Joined: Mon Mar 09, 2009 2:46 pm

Collision - bitmap background

Post by mLaPL »

please help me... :) i try but cant create good collision.

this is map from game, map is none object ( standard png image ) player hero image is png format 48x64. how create good collision for elements from image ?

this is map (1024x768)
Image

and this is first plan to hide hero to back (1024x768)
Image
User avatar
Illidane
Prole
Posts: 12
Joined: Sat Nov 29, 2008 8:01 pm

Re: Collision - bitmap background

Post by Illidane »

I think you need to place rectangle shapes on your level, that hero may collide with it.
User avatar
mLaPL
Prole
Posts: 20
Joined: Mon Mar 09, 2009 2:46 pm

Re: Collision - bitmap background

Post by mLaPL »

i try with rectangle and for me this is not what i need :/ the best way if can I use line collision.

i have problem with none horizontal and none vertical lines :/ like this on image.

i use to collision one center point from hero image.

Image
User avatar
mLaPL
Prole
Posts: 20
Joined: Mon Mar 09, 2009 2:46 pm

Re: Collision - bitmap background

Post by mLaPL »

eureka... :) Collision - Point with any Line. For me this thopic is closed :) thx...

Code: Select all

function PointCollisionWithLine(x,y,x1,y1,x2,y2,tolerance)

        -- range from x,y to x1,y1
	a = x - x1
	b = y - y1
	c = (a*a) + (b*b)
	c1 = math.sqrt(c)
	
        -- range from x,y to x2,y2
	a = x - x2
	b = y - y2
	c = (a*a) + (b*b)
	c2 = math.sqrt(c)
	
        -- range from x1,y1 to x2,y2
	a = x1 - x2
	b = y1 - y2
	c = (a*a) + (b*b)
        c3 = math.sqrt(c)

       if (c1+c2)<=(c3+tolerance) then return true else return false end

end
User avatar
Skofo
Party member
Posts: 146
Joined: Mon Dec 22, 2008 10:55 pm

Re: Collision - bitmap background

Post by Skofo »

Woo! ^^ You're pretty smart.
Working on: Viator
Need a 64-bit Debian package for LÖVE? Here it is!
User avatar
mLaPL
Prole
Posts: 20
Joined: Mon Mar 09, 2009 2:46 pm

Re: Collision - bitmap background

Post by mLaPL »

thx...

good think for this is the same function but short.

if collision lines is constant then we not must calculate line range any time, we can use function like this:

Code: Select all

function PointCollisionWithLine2(x,y,x1,y1,x2,y2,line_range_with_tolerance)

        -- range from x,y to x1,y1
   a = x - x1
   b = y - y1
   c1 = math.sqrt((a*a) + (b*b))
   
        -- range from x,y to x2,y2
   a = x - x2
   b = y - y2
   c2 = math.sqrt((a*a) + (b*b))

       if (c1+c2)<=line_range_with_tolerance then return true else return false end

end
Post Reply

Who is online

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