| View previous topic :: View next topic |
| Author |
Message |
cruisx
Joined: 25 Mar 2008 Posts: 8
|
Posted: Tue Mar 25, 2008 8:42 am Post subject: collision detection question using Oslib |
|
|
int()
Last edited by cruisx on Wed Apr 02, 2008 8:06 am; edited 1 time in total |
|
| Back to top |
|
 |
a_noob
Joined: 17 Sep 2006 Posts: 97 Location: _start: jr 0xDEADBEEF
|
Posted: Tue Mar 25, 2008 4:02 pm Post subject: |
|
|
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: | .øOº'ºOø.
'ºOo.oOº' |
|
|
| Back to top |
|
 |
PosX100
Joined: 15 Aug 2007 Posts: 98
|
Posted: Tue Mar 25, 2008 6:44 pm Post subject: |
|
|
Looks like its tile based.
You simply check if player's tile collides with the grass tile type.
Something like this:
| Code: |
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..
}
}
|
Simple as that :) |
|
| Back to top |
|
 |
DoE
Joined: 26 Mar 2008 Posts: 2
|
Posted: Wed Mar 26, 2008 5:20 am Post subject: |
|
|
| ^ 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. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Mar 26, 2008 5:45 am Post subject: |
|
|
| 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. |
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. |
|
| Back to top |
|
 |
cruisx
Joined: 25 Mar 2008 Posts: 8
|
Posted: Wed Mar 26, 2008 5:58 am Post subject: |
|
|
| PosX100 wrote: | Looks like its tile based.
You simply check if player's tile collides with the grass tile type.
Something like this:
| Code: |
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..
}
}
|
Simple as that :) |
yes it is tile based =). i am lookin over the coe right now, if i have any Qs ill post back. |
|
| Back to top |
|
 |
pjeff
Joined: 27 Mar 2008 Posts: 1
|
|
| Back to top |
|
 |
cruisx
Joined: 25 Mar 2008 Posts: 8
|
Posted: Sat Mar 29, 2008 11:54 am Post subject: Re: collision |
|
|
THANK YOU!!! this is what i was looking for =D. to bad its in french but i get the main idea. |
|
| Back to top |
|
 |
|