realbasic-games
[Top] [All Lists]

Re: Doc's on box to box

To: realbasic-games at lists dot realsoftware dot com
Subject: Re: Doc's on box to box
From: "Heinz J. Gattringer" <heinzjos at uio dot satnet dot net>
Date: Mon, 28 Feb 2005 15:30:45 -0500
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <20050228180019 dot B8160768897 at lists dot realsoftware dot com>
On Feb 28, 2005, at 1:00 PM, realbasic-games-request at lists dot realsoftware dot com wrote:

I don't know of any documents, but box/box tests in 2D are pretty
trivial.  Assuming that b1 and b2 are the bounds objects of the two
sprites, each with left/top/right/bottom properties.  Then, they're
overlapping if

  b1.right > b2.left and b1.left < b2.right and _
  b1.bottom > b2.top and b1.top < b2.bottom



Would this apply when using canvas and tile based?

Right now the tiles/objects that the character can run
into have no properties. It just - ok look at each layer of the map
and draw tiles according to the data. Layer 3 holds only that which
you can not pass. Now layer 3 is just drawn like the others but is checked
to see if there is an object in the way.

Now would I need to provide properties for the "objects" in layer 3?

Thanks

Eric

In a canvas you don't really need bounds properties, the position of your aproximately square character is enough to allow the easy mathematical establishment of its "boundaries".

For your particular problem you could try following: your map layer 3 holds the data for the objects that cannot be passed. So, if your character is crossing into a tile which holds such a non passable object from left to right, check the right boundary of your character against the left boundary of the object, something like:

if MyCharacterPositionX+MyCharacterWidth "corresponds to a tile with an impassable object" then if MyCharacterPositionX+MyCharacterWidth>=ObjectPositionX then -> do not allow movement

Analog solutions would apply for right to left and up-down movements, always checking carefully when you need to add the widht and/or height of the objects.

But perhaps the best solution for you would be to use a Sprite Surface. Make your character and all impassable objects in your game a sprite. Make the ground and all passable objects part of the background graphics of the SpriteSurface. Then use the collision event to detect and respond to collisions. In other words, read all map layers except layer 3 into the background with the PaintTile event. Map layer 3 would have to be made into sprites and positioned with their X and Y properties.

Since the collision event of the Spritesurface works at a pixel level, you would get very accurate collision detection even with irregular shapes without any need for math on your part. Just put the different objects in your game cleverly into different groups and your collision-detection will be a snap and a joy to use.

Hope all of this makes sense and helps a bit
Heinz

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>