Jump to content

  • Log In with Google      Sign In   
  • Create Account


Blocking character movements


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 25 September 1999 - 09:52 PM

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

Sponsor:

#2 Zenroth   Members   -  Reputation: 127

Like
Likes
Like

Posted 25 September 1999 - 04:02 PM

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.


#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 25 September 1999 - 06:30 PM

COuld you show me some examples...I got basic collision detection but its not that good

#4 Zenroth   Members   -  Reputation: 127

Like
Likes
Like

Posted 25 September 1999 - 09:52 PM

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.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS