Discord
Community
DARK THEME

# Problems with collisions

Hello, I'm new to microStudio and it's really getting on my nervers because of collisions. It seems that the map and the player use two different kinds of coordinate systems: the map has 0,0 on the bottom left, while the player has 0,0 in the middle of the screen. Both are really odd, but how can I convert one into the other? If a player is at 0,0 and I use:

maps["level01"].get(player.x, player.y)

I don't get anything unless there's a tile in the bottom left of the map! I don't want to use libraries (also because I don't understand the code). Can anyone explain the logic of this???

These are my projects:

but they're really messy. Thank you in advance.

Aldo

I found a few other posts about this and I'll read them as soon as I have time, if I have time. But I really wish that someone writes something about this in the documentation. I don't want to use libraries that I don't understand. I want to understand the logic!

It's a bit complicated, so strap in :)

Traditionally, image coordinates in computer graphic are as follows:

• Point (0,0) is located in upper-left corner.
• X axis is horizontal axis, with values increasing to the right.
• Y axis is vertical axis, with values increasing downwards.

This applies to image files, as well as the screen itself, and is directly related with how image data is stored in computer's memory. This is also notoriously confusing for people, that come from mathematical background, who are used to Cartesian coordinate system - point (0,0) in the middle and Y axis pointing upwards. MicroStudio, to help people not used to game development, uses Cartesian coordinate to manage position on the screen.

In microStudio, screen coordinates are in range of (-120,120) on X axis and (-100,100) on Y axis with point (0,0) in the middle of the screen. Screen resolution is always 320x200 measured in microStudio Units (not Pixels!).

MicroStudio Unit is used to measure coordinates and size of displayed sprites. They are underneath translated to actual pixels for you automatically, when microStudio does actual rendering. Important difference is that Units are a decimal value, while Pixels are an integer values - you can't operate in Pixel's fractions, while you can use fractions while working with Units. In Units, point (42.67, 69.127) is valid.

Regarding Maps - your confusion steams from the idea that Maps use Cartesian coordinate systems. They do not. Maps are actually a table, with rows and columns, like a chessboard. You provide the number of a row and a number of a column you're interested in and get() method will return whatever is located there. This difference is required, because Maps, depending on a game, don't need to be limited to a screen - Map can be far bigger, with only a fragment being visible to the player at any given time. There's no universal screen-to-map translation method, and is uniquely depending on how your specific game utilizes Maps.

As an example, assuming you want to display a whole map as a single screen (no scrolling, no borders):

``````block_width = maps["level01"].block_width
block_height = maps["level01"].block_height

screenX = mapX * block_width  - 160 + (block_width / 2)
screenY = mapY * block_height - 84 + (block_height / 2)
``````

Take that example very loosely, because it's very situational.

Edit: I should add, that all this has nothing to do with collisions. It's only about rendering coordinates and Map data structure. Collision is separate, even more complex topic ;)

Thank you very much for the quick and very detailed reply. I know how coordinates work in videogames, since I made a game and a few demos with love2d (including a platform game engine with physics and camera without any external library) and experimented something with Godot and Unity. I know that the ones I see in the map screens are not the coordinates of the map and that I should multiply them by the tiles' width and height: I did it in the attempts I linked.

About collisions, I think I know how to handle them, since I have already done it with other engines/languages. The problems is making the screen and map coordinates match.

This sentence: "There's no universal screen-to-map translation method, and is uniquely depending on how your specific game utilizes Maps" made me think that I should quit microStudio for good.