Collision Detection Problems 
Author Message
 Collision Detection Problems

I know how to make it so the person playing the game cannot go passed the edges
of the form but can't make it so the perosn can't go over a wall or a block in
my game, My question is: Is there anyway to detect if a person is going over a
line and make it so they can't go over it, but going along side of it on two
lines like this:

X |
   |
   | X       The person can move on both sides of a line, but not go over it,
get it?  

frustrating
X |
From,
The Unknown



Thu, 15 Aug 2002 03:00:00 GMT  
 Collision Detection Problems

Quote:

> know how to make it so the person playing the game cannot go passed the
>edges
>of the form but can't make it so the perosn can't go over a wall or a block
>in
>my game, My question is: Is there anyway to detect if a person is going over
>a
>line and make it so they can't go over it, but going along side of it on two
>lines like this:

>X |
>   |
>   | X       The person can move on both sides of a line, but not go over it,
>get it?  

>frustrating
>X |
>From,
>The Unknown

I remember (fills pipe) in the old days of machine code game programming that
everything was done via arrays (and offsets) and not via the screen.  All the
detection is done by looking at your arrays and the stuff on screen is just
guided by what's happening underneath.

You could represent it like this;

Think of your array as gamePosition(200,200) and your screen being three times
that in pixels which gives you a viewport of 600 by 600.

You could fill parts of the array by using for example '1' for something solid
and '0' for nothing.

This could be done by reading in a database using a seperate level editor or
typing in by hand,  seperated blocks for each row in a text editor and reading
it in;

11111111111111111101111111111111111 etc, etc....
10000000000000000000000100000000001 ..........
10000000000000000000000100000000001 .....
10000000000000000000000100000000001 ....

Using variables 'h' and 'v' for your array cell pointer coordinates you check
what's in your array at the point where we are or will be in our next step by
using;

If gamePosition(h,v) <>0 then DoSomething as we will be hitting something.

Using a variable direction variable that can switch between positive and
negative steps you can change direction, as in;

  h = h + HorizMove ' Update position in steps left or right
  v = v + VertMove ' Update position in steps up or down.

So, if you hit something you could make a jump to your update action routine to
do the following;

HorizMove = -HorizMove

If HorizMove is 1 then it will be -1 and conversely if -1 then it is switched
to 1 again.  You can even switch HorizMove to '0' or in a different step count
by using a variation on the above line.

To improve by using 'look ahead';

If gamePosition(h + HorizMove, v + VertMove) <>0 then DoSomething as we will be
hitting something.

Examining the above, if we are now at 'h' then adding our movement step to
where we are now is where we will be in the next movement no matter whether
HorizMove is +1 or -1, going left or right.

Your on-screen coordinates system will be

Where I am in left/right = h * 3
Where I am Up/Down = v * 3

Remembering that your screen in pixels is three times the array (assuming
you've set your viewport to pixels).

This allows for very fine movement of three pixels per one cells size but you
can jump around in larger steps for 'h' & 'v' by changing HorizMove and
VertMove.

One tip!

Hunt the Wumpus has been done!  Whether in Windows version I don't know?  :-)

Richard.



Fri, 16 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Collision detection problems w/ scrolling?

2. Collision detection routines between images

3. Sprites and collision detection

4. Collision detection

5. Collision detection

6. VB InterSectRect Collision detection...

7. Help with collision detection (rectangular)

8. Collision Detection

9. collision detection

10. Collision Detection in VB5

11. High speed sorting and collision detection.

12. Collision Detection in VB4

 

 
Powered by phpBB® Forum Software