Archived

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

[SDL]Colision with multiple objects. How?

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

I have a player on screen and the map is drawn with this function:
void DrawMap() {
	for (int x=0; x<20; x++) {
		for (int y=0; y<15; y++) {
			if (map[y][x]==OPEN) {
				Draw(Etile, x*40, y*40);
			}
			else if (map[y][x]==BLUE) {
				Draw(Btile, x*40, y*40);
			}
			else if (map[y][x]==GREEN) {
				Draw(Gtile, x*40, y*40);
			}
		}
	}
}
(Every tile is 40x40 size). The player moves around the screen, but how do i check collision,i could do it if there would be only few objects drawn separetly (like in ping-pong) But how do i check it if lots of tiles are drawn this way? Thanks!

Share this post


Link to post
Share on other sites
quote:
Original post by vaneger
are your tiles a seperate class with their own attributes or are they just simply drawn?

Theyre simply drawn. If they shouldn't be, just say it


[edited by - ZadrraS on April 6, 2004 2:06:45 AM]

Share this post


Link to post
Share on other sites
Like ive said, i don''t have any classes for keeping info about each tile. I have 5 surface, the screen, the player, Empty Tile(ETile), Blue Tile(BTile) and Green Tile (GTile). I have an array called map which stores either OPEN, BLUE or GREEN. My functions loops through each of the maps integers and if the current one is OPEN, it draws Etile (maps[y][x]) on current y*40 and current x*40 (each tile is 40 pixels) and etc.

Share this post


Link to post
Share on other sites
Ok, suppose your player is at location (230.0f, 112.0f).

Divide those values by your tilesize and you can determine which tile the player is inside at that moment. Then you can ensure you only collision check the ones surrounding it.

230 / 40 = 5.75
112 / 40 = 2.8

Round them down and you''ve got map[5][2].

hope that helps.

Share this post


Link to post
Share on other sites