Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Scrolling maps + collision

                  
   
  1. #1

    Default Scrolling maps + collision

    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

  2. #2
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    85

    Default

    Is this with a tiled world (e.g Super Mario World) or the currently popular single background image (e.g. Linken's Quest)?

  3. #3

    Default

    Um, single bg... But I would like to know tile also... As I might change it

  4. #4
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    85

    Default

    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.

  5. #5

    Default

    Quote Originally Posted by yaustar
    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?

  6. #6
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    85

    Default

    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.

  7. #7

    Default

    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!

  8. #8
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    85

    Default

    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 :/

  9. #9

    Default

    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

  10. #10
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    85

    Default

    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.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •