My map si flat and solid now. I want help to understand this class function and how i should call it because i am pretty confused now.....
bool HGETileMap::RectCollide(hgeRect r, CTile *plats[9], int *nCols)
{
int cPlat = 0;
if (r.x1 < 0 || r.x2 < 0 || r.y1 < 0 || r.y2 < 0) return false;
// calculate which tiles this affects
int tx1 = int(r.x1 / TILE_W); // start tile x
int ty1 = int(r.y1 / TILE_H); // start tile y
int tx2 = int(r.x2 / TILE_W)+1; // end tile x
int ty2 = int(r.y2 / TILE_H)+1; // end tile y
// build a list of rects to test collision with
std::vector<hgeRect> cols;
std::vector<int> colidx;
for (int iy=ty1; iy<ty2; iy++)
for (int ix=tx1; ix<tx2; ix++)
if (tiles[ix+(iy*info.mapwidth)])
if (tiles[ix+(iy*info.mapwidth)]->collide || tiles[ix+(iy*info.mapwidth)]->collide2 || tiles[ix+(iy*info.mapwidth)]->collide3 || tiles[ix+(iy*info.mapwidth)]->collide4)
{
if (tiles[ix+(iy*info.mapwidth)]->collide3 || tiles[ix+(iy*info.mapwidth)]->collide4)
{
// if its an upwards slope
hgeVector player_pos = hgeVector( r.x1 + ((r.x2 - r.x1)/2) , r.y2 );
hgeRect tile_pos = hgeRect(ix*TILE_W, iy*TILE_H, (ix*TILE_W)+TILE_W, (iy*TILE_H)+TILE_H);
if (tiles[ix+(iy*info.mapwidth)]->collide3)
{
if ( (player_pos.x - tile_pos.x1) > 40-(player_pos.y - tile_pos.y1) )
{
cols.push_back(hgeRect(ix*TILE_W, iy*TILE_H, (ix*TILE_W)+TILE_W, (iy*TILE_H)+TILE_H));
colidx.push_back(ix+(iy*info.mapwidth));
}
}
else
{
if ( (player_pos.x - tile_pos.x1) < (player_pos.y - tile_pos.y1) )
{
cols.push_back(hgeRect(ix*TILE_W, iy*TILE_H, (ix*TILE_W)+TILE_W, (iy*TILE_H)+TILE_H));
colidx.push_back(ix+(iy*info.mapwidth));
}
}
}
else
{
cols.push_back(hgeRect(ix*TILE_W, iy*TILE_H, (ix*TILE_W)+TILE_W, (iy*TILE_H)+TILE_H));
colidx.push_back(ix+(iy*info.mapwidth));
}
}
// test for collisions
for (int i=0; i<cols.size(); i++)
if (cols[i].Intersect(&r))
{
plats[cPlat] = tiles[colidx[i]];
cPlat ++;
}
*nCols = cPlat;
// no collision was found
return false;
}
i understand that this function:
bool HGETileMap::PointCollide(float x, float y)
{
if (x<0 || y<0) return false;
// calculate which tile this is
int tx = int(x / TILE_W);
int ty = int(y / TILE_H);
// tile index
int idx = (tx)+((ty)*info.mapwidth);
if (tiles[idx])
return tiles[idx]->collide;
return false;
}
is callled like this: tilemap->PointCollide(spriteX + mapX, spriteY + mapY)
But i dont understand what parameter are this: CTile *plats[9], int *nCols