Jump to content
  • Advertisement
Sign in to follow this  
Joshnathan

Colission & SDL_Surface

This topic is 4972 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

Hi all, I have a simple question(maybe a hard answer): I want to assign some value to an SDL_Surface*, so that I can check for collision. Example:
SDL_Surface *tree;
SDL_Surface *world[64];

tree = IMG_Load("tree.jpg");
tree = 1; // I know this is impossible, it is just to show the idea

////////////////
// ifstream TheWorld 
//   etc..
///////////////

while(!TheWorld.EOF())
{
//reading in char piece
 world = piece
}

bool running = true;

while(running)
{
 ....
 //main game loop

 switch(event.keyevent.keysym)
 {
  case SDLK_DOWN:
  if(world[position] == 0)
  Move()
 }
}

I hope this explains my problem somehow. I guess all I am asking for is a collision detection way that is easy to handle using SDL... If anyone knows of a good tutorial I am fine with it too (especialy a map editor tutorial for SDL which I am looking for some time already). Joshua

Share this post


Link to post
Share on other sites
Advertisement
If you want to assign a value to your surface you are going to have to make a struct or class containing the extra information you need.
Something like:

struct MySurface
{
SDL_Surface *surface;
int value;
};

Now do:

MySurface tree;
tree.surface = IMG_Load(...);
tree.value = 1;

As for collision detection:
You just need the position, width and height of the surfaces and then check these values against eachother.

Hope that helps.

-CProgrammer

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!