# Re: [Audyssey] Conceiving Level Maps

```Hi Thomas,

I am wondering why you need to know a step ahead.  Why not just detect an
actual collision?  I have always found that to be good enough.  You know detect
the collision and do what would happen for a collision like before doing what
would happen if there was not a collision.  I E do not up date the graphics or
in our case the sounds etc.```
```
I also have always found that square, rectangle or cube is good enough and thus
do not do the circular or spherical detection that then requires trig or
whatever.  Maybe if we were doing graphics one would be able to tell, but I do
not believe that one would know the difference in our games.

I just do collision detection like

if hx > 32 and hx < 37 then
if hy > 44 and hy < 47 then
Bang! Homer ran into something.
end if
end if

And of course for a three D just add the third check

if hx > 32 and hx < 37 then
if hy > 44 and hy < 47 then
if hz > 22 and hz < 25 then
Bang! Homer ran into something.
end if
end if
end if

I guess that I just like to keep things simple because that is the only way
that I know how to do it with my limited math knowledge etc.

BFN

----- Original Message -----
Hi Kai,

Well, to help me draw level maps I actually created a level editor
that allows me to copy, cut, and paste things like walls, doors,
chasms, etc on a 2d or 3d grid. However, even without it it is not
that hard to actually draw or create a level such as you describe. To
create a room for a side-scroller all I need to do is something like
this.

// Draw the ceiling
for (x = 0; x < 51; x++)
g_map[x, 10] = SURFACE_CEILING;

// Draw the floor
for (x = 0; x < 25; x++)
g_map[x, 0] = SURFACE_STONE;
for (x = 36; x < 51; x++)
g_map[x, 0] = SURFACE_STONE;

// Draw the chasm
for (x = 25; x < 36; x++)
g_map[x, 0] = SURFACE_CHASM;

// Draw the left wall
for (y = 1; y < 10; y++)
g_map[0, y] = SURFACE_WALL;

// Draw the right wall
for (y = 1; y < 10; y++)
g_map[50, y] = SURFACE_WALL;

What we have here is a simple room 50 units wide and 10 units high. We
essentually created it by using surface constants and stored them in a
2d array. To figure out if we encountered anything all we need to do
is find out if the player's next x/y position will step into a chasm
or encounter one of the walls. Since my engine, G3D, actually deals
with a 3d array with an x/y/z position I have a set of trig formulas
to calculate the vector and figure out where the player's next x/y/z
position will be. However, since we are dealing with a simple
side-scroller we probably don't need anything that fancy. We can get
by just by adding or subtracting the player's velocity to or from x
and y. For example, here is some really really simplistic colision
checking. This isn't exactly the best collision detection method, but
it should work for a newbie like your self.

// Get the player's x/y coordinates
float speed = g_player.GetSpeed();
float x1 = g_player.GetX();
float y1 = g_player.GetY();
float x2 = 0;
float y2 = 0;

// If the player is moving left
// subtract the player's sspeed from x1
if (g_player.GetDirection() == -90)
{
x2 = x1 - speed;
y2 = y1 - 1;
}

// If the player is moving right
// add the player's speed to x1
if (g_player.GetDirection() == 90)
{
x2 = x1 + speed;
y2 = y1 - 1;
}

// Get the player's surface
int surface = g_map[(int)x2, (int)y2];

// Find out if the player encountered anything
int encountered = g_map[(int)x2, (int)y1];

// If the player stepped into a chasm kill the player
if (surface == SURFACE_CHASM)
{
KillPlayer();
}

// If the player hit a wall
// stop moving
if (encountered == SURFACE_WALL)
{
HitWall();
}

// Move forward
if (encountered != SURFACE_NOTHING && surface!= SURFACE_CHASM)
{
g_player.SetLocation(x2, y1);
PlayStepSound();
}

What we have here is a very simplistic colision detection system. It
basically tries to determine where the player will be when he/she
takes their next step and figures out if he/she hit a wall, fell into
a chasm, or moved safely to the new location. Does this make sense?

So if I wanted to add ledges etc to this room above all I'd have to do
Is draw them in by adding them to the array wherever I wanted them. I
might draw one in the middle of the chasm to jump/land on so the
player doesn't have to try the suicidal feet of jumping the entire
length of this chasm, or I could add ledges to either side. It really
is not that complex to create a level in this fassion.

HTH

Jim

Simple enough for a weenie; enough power for a nerd!

j...@kitchensinc.net
http://www.kitchensinc.net
(440) 286-6920
Chardon Ohio USA
---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gamers@audyssey.org.
If you have any questions or concerns regarding the management of the list,