Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Re: Doc's on box to box (Real Studio games Mailinglist archive)

Back to the thread list
Previous thread: MiniMax (AI for 2 player games)
Next thread: SS tiles bigger than 64px


Re: Doc's on box to box   -   Heinz J. Gattringer
  Re: Doc's on box to box   -   Eric Richards
   Doc's on box to box   -   Eric Richards
    Re: Doc's on box to box   -   Joseph J. Strout
  Re: Doc's on box to box   -   Eric Richards
  Re: Doc's on box to box   -   Heinz J. Gattringer
   Re: Doc's on box to box   -   Eric Richards

Re: Doc's on box to box
Date: 02.03.05 00:41 (Tue, 1 Mar 2005 18:41:29 -0500)
From: Heinz J. Gattringer
On Mar 1, 2005, at 1:00 PM,
<email address removed> wrote:

> We'll I've tried that. I do have something er..um "working". When the
> character is just walking around it works just fine.
> However when running the character can get stuck a bit in to the
> "object". This only happens when going right or down
> and it doesn't always happen. There's some fine points I don't know or
> understand..yet.

If I remember correctly from previous postings, your problem could be
related to the fact that you have a 'speed-property', which specifies
the speed (or number of pixels) the character is to be moved in each
update. If your handling of collision detection only affects a change
in speed, then if the speed of the character is quite a bit larger than
the number of pixels the character is away from an obstacle, he could
end up stuck inside an object. So perhaps you could do following check
(again based on a supposed left to right movement):

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

or another solution would be:

if MyCharacterPositionX+MyCharacterWidth "corresponds to a tile with an
impassable object" then
if MyCharacterPositionX+MyCharacterWidth>=ObjectPositionX then
MySpeed// this would stop your character dead cold turkey, which might not
give a nice optical illusion

Be sure to put this collision checks before you update the position of
your character with something like
MyCharacterPositionX=MyCharacterPositionX+MySpeedX

The part which I can't make sense off is why your Character gets stuck
only in down or right movements. Check to make sure you are really
adding up everything that needs to be added up correctly and check your
+/- signs.

> Well I've thought about that. The only thing is that SS is stuck at
> 64x64 tile size but
> my tiles are 32x32. I wish SS had a property or something that would
> let
> you set the tile size.
>
> Joe said I just need to draw 4 of my tiles for 1 of SS tiles and
> showed
> me some code but I tried to do it but
> it didn't work right.

It is really just a matter of reading 4 tiles of yours into a 64x64
pixels picture and then copying that picture into the correct tile.
Since you are given an X and Y position for each tile to be drawn in
the PaintTile Event, you would need to look up your map (which would be
in a 2 dimensional array, I suppose) something like this:

dim pic as picture
pic = NewPicture (64,64,whatever you have here)

if MapLayer3(Xpos*2,Ypos*2)='obstaclemarker' then
pic.graphics.drawpicture TheObstacle,0,0,32,32
else
pic.graphics.drawpicture PassableGround,0,0,32,32
end if

if MapLayer3(Xpos*2+1,Ypos*2)='obstaclemarker' then
pic.graphics.drawpicture TheObstacle,32,0,32,32
else
pic.graphics.drawpicture PassableGround,32,0,32,32
end if

if MapLayer3(Xpos*2,Ypos*2+1)='obstaclemarker' then
pic.graphics.drawpicture TheObstacle,0,32,32,32
else
pic.graphics.drawpicture PassableGround,0,32,32,32
end if

if MapLayer3(Xpos*2+1,Ypos*2+1)='obstaclemarker' then
pic.graphics.drawpicture TheObstacle,32,32,32,32
else
pic.graphics.drawpicture PassableGround,32,32,32,32
end if

g.drawpicture pic,0,0

I am sure that "pros" would code all this a bit more compact and maybe
bypass the local variable pic, but for me this makes the process very
clear.

Cheers,
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>

Re: Doc's on box to box
Date: 03.03.05 18:58 (Thu, 03 Mar 2005 11:58:21 -0600)
From: Eric Richards
>if MyCharacterPositionX+MyCharacterWidth "corresponds to a tile with an
>impassable object" then
>if MyCharacterPositionX+MyCharacterWidth+MySpeed>=ObjectPositionX then
-> do
>not allow movement

>or another solution would be:

>if MyCharacterPositionX+MyCharacterWidth "corresponds to a tile with an
>impassable object" then
>if MyCharacterPositionX+MyCharacterWidth>=ObjectPositionX then MySpeed >// this would stop your character dead cold turkey, which might not
give a nice optical >illusion

I've done something like this but hasn't worked. I think there is
something I'm missing or just not getting.

>The part which I can't make sense off is why your Character gets stuck
only in down or right >movements. Check to make sure you are really
adding up everything that needs to be added up >correctly and check your
+/- signs.

I'm not sure about that either. The other odd thing is it only happens
once in a while. Yep I've checked all that...
I think its just somehting I'm missing.

I'll try playing around with it a bit more and if I can't anything going
I'll go back to SS and try getting that to work.

Thanks

Eric

_______________________________________________
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>

Doc's on box to box
Date: 26.02.05 02:11 (Fri, 25 Feb 2005 19:11:43 -0600)
From: Eric Richards
Hi -

Does anyone know of any documents that I can download
that relate to collision detection of a "box to box" type - with
respect to 2D sprites?

Thanks

Eric

_______________________________________________
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>

Re: Doc's on box to box
Date: 26.02.05 03:14 (Fri, 25 Feb 2005 20:14:09 -0600)
From: Joseph J. Strout
At 7:11 PM -0600 2/25/05, Eric Richards wrote:

>Does anyone know of any documents that I can download
>that relate to collision detection of a "box to box" type - with
>respect to 2D sprites?

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

Best,
- Joe

Re: Doc's on box to box
Date: 28.02.05 03:51 (Sun, 27 Feb 2005 20:51:40 -0600)
From: Eric Richards

>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

_______________________________________________
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>

Re: Doc's on box to box
Date: 28.02.05 21:30 (Mon, 28 Feb 2005 15:30:45 -0500)
From: Heinz J. Gattringer
On Feb 28, 2005, at 1:00 PM,
<email address removed> 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>

Re: Doc's on box to box
Date: 01.03.05 00:38 (Mon, 28 Feb 2005 17:38:24 -0600)
From: Eric Richards
>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.

We'll I've tried that. I do have something er..um "working". When the
character is just walking around it works just fine.
However when running the character can get stuck a bit in to the
"object". This only happens when going right or down
and it doesn't always happen. There's some fine points I don't know or
understand..yet.

>But perhaps the best solution for you would be to use a Sprite Surface.

Well I've thought about that. The only thing is that SS is stuck at
64x64 tile size but
my tiles are 32x32. I wish SS had a property or something that would let
you set the tile size.

Joe said I just need to draw 4 of my tiles for 1 of SS tiles and showed
me some code but I tried to do it but
it didn't work right.

I may just have to go back to SS.

Thanks

Eric

_______________________________________________
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>