Jump to content
  • Advertisement

Archived

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

Guest Anonymous Poster

Blocking character movements

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

Not sure what you mean by top down game...but i think ill be able to help you out a bit hopefully. All most all 2d games (metroid,megaman,rpg's,zelda,ect) use tiles to make up the worlds.
With tiles its real easy to do collision detection. All you do is in your tile structure you have something like a int terran modification;

then when you move you can do something bout like this.

if(map[playerx][playery].type=1)playerx = old.x,playery=old.y;

Hope this helps some if you need more info i can send you some examples.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
COuld you show me some examples...I got basic collision detection but its not that good

Share this post


Link to post
Share on other sites
ok here is somewhat of a example if you need more email me at lordvar@in-tch.com and ill see what i can do.

typedef struct map{
char tile; //tile id(pic of tile to draw)
char type; // any flags for the tile.(up to 255)
}

map CurMap[200][200]; //array of struct map.

Now what you do for collision detection is like this
logic(){
int oldx = playerx;
int oldy = playery;
now
you do your movment checks like
if(key_up)playerx--;
and so on.
now after that we go
if(CurMap[playerx/tilesize][playery/tilesize].type = 1){playerx = oldx,playery=oldy;}

Hope this helps. You might have to add some stuff if your player sprite is bigger or smaller than your tile size.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I'm creating a 2D top down game, and I was wondering what is the best way to block the character from moving through walls, and help or links is appreciated

Share this post


Link to post
Share on other sites

  • 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!