Jump to content
  • Advertisement
Sign in to follow this  
Aqua Costa

help with 2d game (Directx 9/C++)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive made a little 2D game using Directx 9 The game contains 2 layers: background sprite and terrain sprite , and the player sprite Full Game: http://img249.imageshack.us/i/gamea.png/ Background Sprite: http://img217.imageshack.us/i/backgroundo.png/ Terrain Sprite: http://img109.imageshack.us/i/terrain.png/ Player Sprite: http://img513.imageshack.us/i/playerk.png/ My question is how can I know playerY based on the terrainY in playerX position Like when player clicks right button, player sprite moves x = x+1 and y = terrain.getY(player.x) Can someone tell me how can I do that? I think i need to get the pixel data of terrain but i dont know how to do that...

Share this post

Link to post
Share on other sites
here how you can get the color of a certain pixel in a texture.


first find the height of the terrain for each x value.

int terrainheight[terrainwidth];

for(int i=0; i<terrainwidth; i++){
int j=0;

while( [pixel at i,j] is white ){
terrainheight = j;

I assumed that 0,0 is the top left of the screen. It first starts scanning from top of the screen and move down until it finds a green spot. It could be better if you start searching from nearby pixels of terrainheight[i-1] but since this is a one time job it is not that important.

after that you can use this array to adjust y position

x++; //or x--
y = terrainheight[x] - radiusofcircle;

I hope that helps

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!