Fandom

Petit Computer Wiki

Simple Map Collision Detection (Array Based)

914pages on
this wiki
Add New Page
Comments23 Share

This is an example program which shows one way to do collision detection between a player and the map when the map data is stored in an array. In order to keep it simple, the map does not scroll, and the player is strictly smaller than the obstacles. Extra code would need to be added if the player was larger than the walls, but it was not included to keep the example as simple as possible.

The program is heavily commented, so look inside the code to see how it works. If you have any questions, please post them in the comments section! If they're not too broad (like how do I make a game out of this), I'll try to answer them! Also, feel free to use this code directly in anything you like. You don't have to give me credit if you don't want since it's just a tutorial.

Colitest

Here's a more complicated version that lets you slide on the walls. If you're just learning, the extra code might make things more complicated, so try the first one first.

Colitest2

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.