Results 1 to 6 of 6

Thread: 2D platform game; collision detection

  1. #1

    2D platform game; collision detection

    Hello,

    I'm new to game programming and I'm trying to make a 2D platform game.

    The game loads maps that are made out of triangles. Triangles have textures and define the boundaries (walls, floor, etc.).

    I'm using DelphiX to program the game. But I don't know what's the best approach for letting the player respect the given boundaries.

    Should I make each individual triangle a sprite, so when the player collisions with a triangle, the game is automatically aware of what triangle it bumped into.

    Or should I make a sprite with the complete map as the sprite image, and then when the player bumps into a non-transparent pixel, the game calculates which triangle it bumped into, and it acts accordingly.

    Or is there a better or easier way.

    Does anyone know what's the best way to go?

  2. #2

    2D platform game; collision detection

    Have a look at the tutorial section of my heavily neglected website. There's two tuts dealing with platform games. I believe they should answer most, if not all, of your questions.

  3. #3

    2D platform game; collision detection

    Quote Originally Posted by Traveler
    Have a look at the tutorial section of my heavily neglected website. There's two tuts dealing with platform games. I believe they should answer most, if not all, of your questions.
    My game is not tile-based. It is made out of points of triangles. I could make a color map out of the triangle point information (like you do, for your tiles), but now I think just calculating it before it happens is maybe the best thing to do.

    But thanks anyway for your tutorial.

    Do you or anyone forsee any problems I might run into when calculating it? Should I use another method? The color map you use in your tutorial for example.

  4. #4

    2D platform game; collision detection

    Basicly you should do as little cacluations as possibly so:

    1. You know in what triangle your player is (or is moving onto)
    2. You know if the triangle is potentionaly collidable or not
    3. If it is not collideable the player is happy and can stay ther (or move to)
    4. If it is potentionaly collideable we need to investigate further
    5. You know your player sprite, with an transparency colour and its x,y pos and size
    6. You know your triangle sprite (background texture) with an transparency position and x,y and size
    7. now first you check if their boundaries collide (most likely) if not the player is happy and can stay there (or move to)
    8. if it collides you can invstigate further by pixel comparing the colliding boundary you got in step 7. As long as you only get transparent matches your player is happy, but if one pixel turns up to be nontransparent you realy have an collision and your player is unhappy.

    PS could you make a posting on how i should visualize a triangulated map? I gues it is something like a tilemap but not with squares but triangles instead?
    PS2 i assume the player is not larger then the triangle.
    http://3das.noeska.com - create adventure games without programming

  5. #5

    2D platform game; collision detection

    Quote Originally Posted by noeska
    Basicly you should do as little cacluations as possibly so:

    1. You know in what triangle your player is (or is moving onto)
    2. You know if the triangle is potentionaly collidable or not
    3. If it is not collideable the player is happy and can stay ther (or move to)
    4. If it is potentionaly collideable we need to investigate further
    5. You know your player sprite, with an transparency colour and its x,y pos and size
    6. You know your triangle sprite (background texture) with an transparency position and x,y and size
    7. now first you check if their boundaries collide (most likely) if not the player is happy and can stay there (or move to)
    8. if it collides you can invstigate further by pixel comparing the colliding boundary you got in step 7. As long as you only get transparent matches your player is happy, but if one pixel turns up to be nontransparent you realy have an collision and your player is unhappy.

    PS could you make a posting on how i should visualize a triangulated map? I gues it is something like a tilemap but not with squares but triangles instead?
    PS2 i assume the player is not larger then the triangle.
    This is a sketch:
    http://img159.imageshack.us/my.php?i...nglemapnh1.jpg

    A map contains a set of triangle co??rdinates (and later other information, like the texture number).

    Indeed, I would have to know which triangle we are at, or is near.

    I'm putting the triangle information in a list, with each triangle having functions to get the co??rdinates of the triangle points, and functions to get the connected triangles.

    For instance, if one moves right on a certain triangle, and it moves over the current triangle, I would have to know which triangle is connected at that side, or if there is no connected triangle.

    If the player is in the air, it will fall and there has to be a function to check how much we can go down further, or if it's moving left or right in the air, if we can move to that direction and how far.

    I'm using DelphiX by the way. And it would not be more appropriate to use DelphiX's built-in collision detection to stay on the platforms?

  6. #6

    2D platform game; collision detection

    It seems to me that the shape of the triangles make the shape of map, this changes the collsion detection as i assumed a grid of triangles(like a tilemap). You will need polygon collision.

    Have a look at: http://gpwiki.org/index.php/Polygon_Collision

    And: http://gpwiki.org/index.php/VB:Tutor...sion_Detection

    You first want to do a circle circle collision check for visible triangles
    If that collides you want to do a triangle triangle check

    If delphix has native collision components do use them!
    http://3das.noeska.com - create adventure games without programming

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
  •