#### Archived

This topic is now archived and is closed to further replies.

# "Map" to screen coordinates

This topic is 5914 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay I''m making this semi-3D flying game where you and enemy ships have two main variables, that is your altitude which is a simple number between 30 and 250, and your horizontal (in this imaginary world) position which is a number between 1 and 1000. Both numbers are in pixels. The screen width is 304 and the screen height is 145, in pixels.
if (x >= Player.x && x <= (Player.x + 304) && alt >= Player.alt
&& alt <= (Player.alt + 145))
{
// He''s visible...
}

What is confusing me here, and has confused me when I tried to make a different sort of game in the past, is how to calculate where to draw on the screen in a simple manner. If you are at an x-position of 500 and an altitude of 40, you can see a portion, or the full sprite, of an object that has an x-value between 500 and 804 and an altitude between 40 and 185. How do I use these "map" coordinates to calculate where to draw on the screen if the object is visible to you? I''m sorry if this is a vague question, but I would greatly appreciate some help!

##### Share on other sites
Your screen will have a position, often called the ''camera'' position or something similar. Subtract the camera position from the player position to get where to draw it. eg. If your screen''s camera position is at (100, 200) and the player is at (120, 260) then you draw the player onscreen at (20, 60). Just as long as everything uses the same coordinate system (for example, I measure everything from the top left) then it should be fine. Finally, the camera position is often centred on a player. As I said in another thread just now, to centre the screen on something, you move it half a screen left and up (assuming you''re working from the top left) relative to the player.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

1. 1
Rutin
31
2. 2
3. 3
4. 4
5. 5

• 13
• 40
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632963
• Total Posts
3009533
• ### Who's Online (See full list)

There are no registered users currently online

×