Advertisement Jump to content


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

Guest Anonymous Poster

Blocking character movements

This topic is 7056 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
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 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
int oldx = playerx;
int oldy = playery;
you do your movment checks like
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!