forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

collision detection question using Oslib

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
cruisx



Joined: 25 Mar 2008
Posts: 8

PostPosted: Tue Mar 25, 2008 8:42 am    Post subject: collision detection question using Oslib Reply with quote

int()

Last edited by cruisx on Wed Apr 02, 2008 8:06 am; edited 1 time in total
Back to top
View user's profile Send private message
a_noob



Joined: 17 Sep 2006
Posts: 97
Location: _start: jr 0xDEADBEEF

PostPosted: Tue Mar 25, 2008 4:02 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address MSN Messenger
PosX100



Joined: 15 Aug 2007
Posts: 98

PostPosted: Tue Mar 25, 2008 6:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
DoE



Joined: 26 Mar 2008
Posts: 2

PostPosted: Wed Mar 26, 2008 5:20 am    Post subject: Reply with quote

^ 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
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Mar 26, 2008 5:45 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
cruisx



Joined: 25 Mar 2008
Posts: 8

PostPosted: Wed Mar 26, 2008 5:58 am    Post subject: Reply with quote

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
View user's profile Send private message
pjeff



Joined: 27 Mar 2008
Posts: 1

PostPosted: Thu Mar 27, 2008 11:22 pm    Post subject: collision Reply with quote

look this and try :

http://www.playeradvance.org/forum/showthread.php?t=18727
Back to top
View user's profile Send private message
cruisx



Joined: 25 Mar 2008
Posts: 8

PostPosted: Sat Mar 29, 2008 11:54 am    Post subject: Re: collision Reply with quote

pjeff wrote:
look this and try :

http://www.playeradvance.org/forum/showthread.php?t=18727


THANK YOU!!! this is what i was looking for =D. to bad its in french but i get the main idea.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group