Resolving Collisions for Mario Tiles: Simple Algorithm?

  • Thread starter Thread starter Alkatran
  • Start date Start date
  • Tags Tags
    Collision
Click For Summary
The discussion centers on developing a Mario game, specifically focusing on how Mario and enemies interact with bricks and blocks in a level. The blocks are organized in a 2D array, allowing for efficient collision detection by only checking blocks that Mario interacts with during a time step. The participant has created an algorithm capable of handling moving objects at various speeds, though it lacks aesthetic appeal. They are building a JavaScript tile engine where occupiable tiles are represented by integers in the array. The conversation touches on memory management, suggesting that only the active area and a buffer zone of the array should be kept in memory to optimize performance. When scrolling, the method of managing tiles—whether to shift all tiles or use a circular array—depends on the platform, with performance being a key concern in tile scrolling for engines developed in Flash and JavaScript. Collision detection is also discussed, with the use of arrays for defining hotspots.
Alkatran
Science Advisor
Homework Helper
Messages
959
Reaction score
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
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.
 
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?
 
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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 37 ·
2
Replies
37
Views
9K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
Replies
6
Views
6K
  • · Replies 21 ·
Replies
21
Views
5K