# Thread: Precision in a tile map grid?

1. ## Precision in a tile map grid?

I'm not sure if the title is completely accurate, so please let me know if I should change it.

I'm trying to get into game programming, so I'm creating really basic games (the one I'm currently working on, which is also the first, is a 2D game in only one room, so I can get used to writing characters, enemies, and other objects, along with movement and combat, without having to worry about implementing other rooms and the transition between them.) and working my way up.

My current problem is this:
The only way that I can think of to make a map grid is to have a two-dimensional array, for example, *datatype* mapcoord[400][200], if I wanted to have a map 400 tiles wide and 200 tiles high. Then, I could set the value of each position to a number, for example, the boundaries of the map and the walls could be set to -1, open space could be 0, enemies are set to 1, etc.

The problem is that I'd also like to have precision and smooth movement, using floating point numbers, so an object could be located at point 32.0416912, 4.194002, instead of just being at 32, 4.
How would I implement this?

Thank you.

2. Dynamic (read: moving) objects are not part of the tile map. They are sprites on the map.

Code:
```int spriteRow = spriteWorldCoords.y / map.cellsize.y;
int spriteColumn = spriteWorldCoords.x / map.cellsize.x;
int spriteMapOffset = spriteRow * map.cellsPerColumn + spriteColumn```

3. Originally Posted by VirtualAce
Dynamic (read: moving) objects are not part of the tile map. They are sprites on the map.

Code:
```int spriteRow = spriteWorldCoords.y / map.cellsize.y;
int spriteColumn = spriteWorldCoords.x / map.cellsize.x;
int spriteMapOffset = spriteRow * map.cellsPerColumn + spriteColumn```
I know that they are not part of the tile map, but I thought that I would add different things like enemies and other interactable (can't think of a real word to use there) objects to the map so that other objects can know that they're there (for example, if I was increasing the player's X value because they were moving to the right, and the function found out that the value of the X coordinate that the player is trying to reach held the value of 1, meaning that there was an enemy occupying that spot, then the player would not be able to move there, and would take damage).

I'm assuming that the 3 lines you provided were for getting the width and height of the sprite on the map grid? If you could please elaborate more on that I'd appreciate it.

4. Sprite collisions can be map based but they don't have to be and IMO should not be. The code I provided allows you to translate from world coords to map or array coords so that you can check the sprite location in the map.