Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Collision with Tiles

  1. Mar 25, 2007 #1

    Alkatran

    User Avatar
    Science Advisor
    Homework Helper

    I found an old Mario game I was writing a long time ago the other day, and I've been working on how Mario and enemies interact with the various bricks and blocks in the level. The blocks are stored in a 2-dimensional array, which gives the obvious advantage of only having to check the blocks Mario passes through during one time step instead of all blocks.

    My question is: is there a simple, well-known way to do this? I've banged out an algorithm today which handles arbitrary sized moving objects at arbitrary speeds. The thing works FANTASTIC (I tested it a bit excessively) but isn't very pretty.
     
  2. jcsd
  3. Mar 25, 2007 #2

    -Job-

    User Avatar
    Science Advisor

    I've done some engines in the past and i'm actually working on a javascript tile engine. I use 2D arrays of ints, each int representing a tile. Occupiable tiles are < X and the rest > X, where X is 2000 for instance.
    For moving characters you do a transformation of the 2D array on some time interval.

    Only the active area of the array plus a buffer zone should be in memory. When scrolling left, for example i add a column of tiles to the left, remove the right most column and move the screen by the tile width.
     
  4. Mar 26, 2007 #3

    Alkatran

    User Avatar
    Science Advisor
    Homework Helper

    I'm talking more about the algorithm to do the collision, not how the tiles are actually stored or used. Obviously mario maps are so small worrying about the memory size is a bit overdoing it :rofl: .

    But, interesting question: when you read your tiles in, do you shift all the other tiles over to make room or do you just use a circular array to write over a single column/row?
     
  5. Mar 26, 2007 #4

    -Job-

    User Avatar
    Science Advisor

    Depends on the platform. I've had to do engines in Flash and JS and getting good performance in tile scrolling can be an issue.

    The collisions would also be done with arrays, for hotspots for example.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Collision with Tiles
  1. Collision Program (Replies: 9)

Loading...