collision detection question using Oslib
collision detection question using Oslib
int()
Last edited by cruisx on Wed Apr 02, 2008 8:06 am, edited 1 time in total.
there are many ways to do collision detections for that, but you need to tell us more, like is that an image or a tile map. if its and image and you want pixel perfect collisions you could make a collision map which is a shilouette of the image and you just check you see that you are on the designated color that allows walking. You can do similar on a tile based map. just check is the character is on a walkable tile.
Code: Select all
.øOº'ºOø.
'ºOo.oOº'
Looks like its tile based.
You simply check if player's tile collides with the grass tile type.
Something like this:
Simple as that :)
You simply check if player's tile collides with the grass tile type.
Something like this:
Code: Select all
typedef enum
{
TILE_PLAYER=1,
TILE_GRASS=2...ETC
}
inline int getCurrentTileType(const int& x,const int& y,const map& themap)
{
return (((x>=themap.width() ||y>=themap.height() ||y<0||x<0)?-1 :themap.tiles[y][x]));
}
inline void getTilePos(const int& wanted_tile,int& px,int& py,const map& themap)
{
px=-1,py=-1;
int x=0,y=0;
for (y=0;y<themap.height();y++)
{
for (x=0;x<themap.width();x++)
{
if ( getCurrentTileType(px,py,themap) != wanted_tile ) continue;
px = x;
py = y;
return;
}
}
}
int main()
{
map themap;
while(running)
{
int player_x,player_y,current_tile;
getTilePos(TILE_PLAYER,player_x,player_y,themap);
current_tile = getCurrentTileType(player_x,player_y,themap);
if(current_tile == TILE_GRASS)
{
//COLLISON! do whatever..
}
if(timer.diff() >= 10)..cleanup render etc..
}
}
As a_noob said, there are MANY ways of doing it. I'd suggest the OP consult one of the many tutorials on the web about basic game design. You can also find many fine books in any bookstore on basic game design. It has nothing to do with the PSP specifically.DoE wrote:^ Perhaps instead of checking for a certain tile type, the tile structs/objects could have a `walkable' field that is set to either true or false.
yes it is tile based =). i am lookin over the coe right now, if i have any Qs ill post back.PosX100 wrote:Looks like its tile based.
You simply check if player's tile collides with the grass tile type.
Something like this:
Simple as that :)Code: Select all
typedef enum { TILE_PLAYER=1, TILE_GRASS=2...ETC } inline int getCurrentTileType(const int& x,const int& y,const map& themap) { return (((x>=themap.width() ||y>=themap.height() ||y<0||x<0)?-1 :themap.tiles[y][x])); } inline void getTilePos(const int& wanted_tile,int& px,int& py,const map& themap) { px=-1,py=-1; int x=0,y=0; for (y=0;y<themap.height();y++) { for (x=0;x<themap.width();x++) { if ( getCurrentTileType(px,py,themap) != wanted_tile ) continue; px = x; py = y; return; } } } int main() { map themap; while(running) { int player_x,player_y,current_tile; getTilePos(TILE_PLAYER,player_x,player_y,themap); current_tile = getCurrentTileType(player_x,player_y,themap); if(current_tile == TILE_GRASS) { //COLLISON! do whatever.. } if(timer.diff() >= 10)..cleanup render etc.. } }
Re: collision
THANK YOU!!! this is what i was looking for =D. to bad its in french but i get the main idea.