PDA

View Full Version : Scrolling maps + collision



bronxbomber92
August 8th, 2006, 19:01
I was wondering how todo scrolling bg's with collision. So if you have a "floating platform" and you want your AI or charactr to jump onto it, how would you go about implemting this? I'm thinking along the lines of where you have world1 = {}
{22222222
454545
3434
3434333} as your level. I know that won't work ^^ but you get the idea.

Thanks

yaustar
August 9th, 2006, 03:10
Is this with a tiled world (e.g Super Mario World) or the currently popular single background image (e.g. Linken's Quest)?

bronxbomber92
August 9th, 2006, 03:43
Um, single bg... But I would like to know tile also... As I might change it

yaustar
August 9th, 2006, 08:33
If it is single bg, you may as well define the collision areas in the script as is done in Linken's quest but in a table so you can do a simple for loop rather then writing the functions calls dozens of times.

If it is tiled then depending on how you store the map data (eg table/array of tile numbers), you have another structure the same size as the map data and have your collidable areas defined as one value, and non-collidable areas as another.

bronxbomber92
August 9th, 2006, 15:51
If it is single bg, you may as well define the collision areas in the script as is done in Linken's quest but in a table so you can do a simple for loop rather then writing the functions calls dozens of times.

If it is tiled then depending on how you store the map data (eg table/array of tile numbers), you have another structure the same size as the map data and have your collidable areas defined as one value, and non-collidable areas as another.
Thats where I'm a little grey with. Could you explain it, maybe a small example?

yaustar
August 10th, 2006, 00:10
I can't since I don't have a tiling engine in Lua but I can give you a C/C++ example:


// Note: this won't compile and is coded straight from the hip so design errors all over the place but
// should give you the general idea

// Each tile is 8x8 pixels
#define SIZE_OF_TILE 8

// A map array of arranged tiles used from a tileset
int MapData[] =
{
1, 2, 4, 7, 1, 3, 4,
4, 2, 2, 2, 6, 4, 5
};

// Overlapping collision data
int CollisionData[] =
{
1, 1, 0, 0, 1, 0, 0,
0, 1, 1, 1, 0, 0, 0
};

// The width and height in tiles of the map
#define WIDTH_OF_MAP 7
#define HEIGHT_OF_MAP 2

// Players position in the world
int OldPositionX = 20, CurrentPositionX = 20;
int OldPositionY = 20, CurrentPositionY = 20;

// Move the player
if (JOYPADINPUT == RIGHT) // Check pad input
{
// Store the old position
OldPositionX = CurrentPositionX;

// Move the player
CurrentPositionX++;

// Check for collision
// Find where the player is on the map
int MapPositionX = CurrentPositionX / SIZE_OF_TILE;
int MapPositionY = CurrentPositionY / SIZE_OF_TILE;

// Check the tile
if (CollisionData[ (MapPositionY * WIDTH_OF_MAP) + MapPositionX ] == 1 )
{
// If there is a collision, then revert to the old position
CurrentPositionX = OldPositionX;
}
}

Do you have a tiling engine or know how one works? If you don't, it becomes extremely difficult to explain how the collision works.

bronxbomber92
August 10th, 2006, 00:20
No I do not... Havent had to use one. But I think a scrolling bg will work fine for my current project. And that c++ tile engine will come in handy also :), Thanks!

yaustar
August 10th, 2006, 00:45
Basicaly, when you have a tiling engine working, you see how the collisions will work much more easily. Not sure if luaplayer is up to the job though :/

bronxbomber92
August 10th, 2006, 01:02
Well Charlie is working on a tile engine in lua, but Its quite confusing... many loops and variables depending on vaiables.... I think I'll stick with the scrolling bg :p

yaustar
August 10th, 2006, 01:56
That sounds about right, I be interested to see the performence that Charlie gets when it is finished as I can imagine it being rather slow. If he/she needs any help, just tell him/her to drop me a line.

bronxbomber92
August 10th, 2006, 03:54
I believe he has it almost finished, he has released three version of it soo far. Go check out forums.evilmana.com and find it ;)