Resolving Collisions for Mario Tiles: Simple Algorithm?

  • Thread starter Alkatran
  • Start date
  • Tags
    Collision
In summary, Mario can pass through any block he crosses as long as he doesn't hit any other blocks. Mario can move through the blocks at any speed, but the faster he moves, the more damage he does to the blocks. The algorithm the author created to handle collisions is fast, but not beautiful.
  • #1
Alkatran
Science Advisor
Homework Helper
959
0
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.
 
Technology news on Phys.org
  • #2
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.
 
  • #3
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 :smile: .

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?
 
  • #4
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.
 

FAQ: Resolving Collisions for Mario Tiles: Simple Algorithm?

How does the simple algorithm for resolving collisions in Mario Tiles work?

The simple algorithm works by checking for any overlaps between the moving object (such as Mario) and the stationary tiles on the game board. If an overlap is detected, the algorithm will determine which side of the tile the object is colliding with and adjust its position accordingly to prevent it from passing through the tile.

Can the simple algorithm handle multiple collisions at once?

Yes, the simple algorithm is designed to handle multiple collisions at once. It checks for overlaps and resolves collisions for each tile individually, ensuring that the moving object is able to navigate through the game board without getting stuck or passing through any obstacles.

How does the simple algorithm prevent objects from getting stuck in walls or other obstacles?

The algorithm uses a technique called "continuous collision detection" to prevent objects from getting stuck in walls or other obstacles. This means that it constantly checks for overlaps between the object and the tiles, even during movement, and adjusts the object's position accordingly to avoid any potential collisions.

Is the simple algorithm efficient in terms of processing power?

The simple algorithm is relatively efficient in terms of processing power because it only checks for collisions with stationary tiles, rather than every single object on the game board. This allows for smoother gameplay and less strain on the computer or gaming system.

Can the simple algorithm be customized for different types of games?

Yes, the simple algorithm can be customized to fit the specific needs of different types of games. For example, it can be modified to handle different types of obstacles or to include special features such as jumping or sliding movements for the moving object.

Back
Top