Who wants a challenge?! <SDL/C++>
Posted: Wed Apr 28, 2010 5:39 am
Hiyah its that noob thats annoying and cant really use english good. That was a fail attempt at being funny. But yes, i am a noob and to some maybe annoying and sometimes i type inunderstandable things.
The challenge to you if you chose to take it is tile cillision! Yep, its pretty much the same as my last post! See how im prolly annoying!!!!!!
This is the drawng function:
This is the collision function:
And here's the tile drawing method:
Youre challenge is not to think im a idiot and to see if you can make a tile collision system, using these things or adding stuff. Sorry ifim a pest though. I have an idea, and if it works ill celebrate abuot it for a long time on this topic and then yerr...ask for t to be deleted. Havefun and take care.
The challenge to you if you chose to take it is tile cillision! Yep, its pretty much the same as my last post! See how im prolly annoying!!!!!!
This is the drawng function:
Code: Select all
void draw_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect clip = NULL ) //same as Lazy Foo's function
{
SDL_Rect pos
{
pos.x = x;
pos.y = y;
}
SDL_BlitSurface( source, clip, destination, &pos );
}
Code: Select all
bool check_collision( SDL_Rect A, SDL_Rect B ) //yup again, same as Lazy Foo's bounding box collision
{
//The sides of the rectangles
int leftA, leftB;
int rightA, rightB;
int topA, topB;
int bottomA, bottomB;
//Calculate the sides of rect A
leftA = A.x;
rightA = A.x + A.w;
topA = A.y;
bottomA = A.y + A.h;
//Calculate the sides of rect B
leftB = B.x;
rightB = B.x + B.w;
topB = B.y;
bottomB = B.y + B.h;
//If any of the sides from A are outside of B
if( bottomA <= topB )
{
return false;
}
if( topA >= bottomB )
{
return false;
}
if( rightA <= leftB )
{
return false;
}
if( leftA >= rightB )
{
return false;
}
//If none of the sides from A are outside B
return true;
}
Code: Select all
int map[5][5] = {
{ 0, 0, 0, 1, 0 }
{ 0, 1, 2, 1, 1 }
{ 0, 0, 0, 0, 0 }
{ 0, 1, 1, 1, 1 }
{ 0, 0, 0, 2, 0 }
}
for( int x = 0; x < 5; x++ )
{
for( int y = 0; y < 5; y++ )
{
if( map[x][y] == 0 )
{
draw_surface( x * 32, y * 32, grass, screen );
}
else if( map[x][y] == 1 )
{
draw_surface( x * 32, y * 32, water, screen );
}
}
}
//same for each number in array