Is this with a tiled world (e.g Super Mario World) or the currently popular single background image (e.g. Linken's Quest)?
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
Is this with a tiled world (e.g Super Mario World) or the currently popular single background image (e.g. Linken's Quest)?
Um, single bg... But I would like to know tile also... As I might change it
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?Originally Posted by yaustar
I can't since I don't have a tiling engine in Lua but I can give you a C/C++ example:
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.// 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;
}
}
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!
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 :/
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![]()
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks