Discussion: [PSP][Aide] [OSLIB] Get pixel question
Afficher un message
Vieux 15/02/2009, 06h33   #10
pspmasterpro
Membre
 
Date d'inscription: 22/01/2009
Messages: 17
Par défaut

O.K. I used tile precision and I re-did my map so it only has 2 tiles in the tileset and it works

my question is: is it possible to create platformer physics like Jumping with this method of collision.

In a platformer you can jump and gravity acts on the faller so the player falls and it's fall increases and stops when the player hits the tile

I know that Super Patrick II has this but it's in french so is their another method to do this?

Here is my collision code so far:
*I used tutorial 10 for help*

Code:
{......}
void newGame()
{
 int RLimit = 250;
 int LLimit = 50;
 oslReadKeys();
 oslCls();

 // Draw map and player
 oslDrawMap(mapCollision1);
 oslDrawImage(player);

 // Character movement with camera and collision detection
 if(osl_keys->held.right && !collisionMgr(mapCollision1,player,0,1,0,0))
 {
  if (player->x >= RLimit)
  {
    map1->scrollX += 1.3;
    mapCollision1->scrollX += 1.3;
  }
  else
  {
    player->x += 1.3;
  }
 }

 if(osl_keys->held.left && !collisionMgr(mapCollision1,player,1,0,0,0))
 {
  if (player->x <= LLimit)
  {
    map1->scrollX -= 1.3;
    mapCollision1->scrollX -= 1.3;
  }
  else
  {
    player->x -= 1.3;
  }
 }
}

{......}

short GetTile(OSL_MAP *m,int col, int row)
{
 u16 *map = (u16*)m->map;
 return map[row*m->mapSizeX + col];
}

{......}

int collisionMgr(OSL_MAP *m, OSL_IMAGE *Collision, int left, int right, int top, int bottem)
{
 #define TILE_NONSOLID 0x0000
 #define TILE_SOLID 0x0001

 int tile;

 if(left)
 {
  tile = GetTile(m,((m->scrollX + Collision->x - 0))/ m->tileX, (m->scrollY + Collision->y + Collision->stretchY)/ m->tileY);
  if (!tile)
  {
  tile = GetTile(m,((m->scrollX + Collision->x - 0))/ m->tileX, (m->scrollY + Collision->y)/ m->tileY);
  }
 }

 if(right)
 {
   tile = GetTile(m,((m->scrollX + Collision->x +Collision->stretchX + 0))/ m->tileX, (m->scrollY + Collision->y + Collision->stretchY)/ m->tileY);
   if (!tile)
  {
  tile = GetTile(m,((m->scrollX + Collision->x +Collision->stretchX + 0))/ m->tileX, (m->scrollY + Collision->y)/ m->tileY);
  }
 }

 if(top)
 {
  tile = GetTile(m,((m->scrollX + Collision->x +Collision->stretchX ))/ m->tileX, (m->scrollY + Collision->y - 0)/ m->tileY);
  if (!tile)
  {
  tile = GetTile(m,((m->scrollX + Collision->x))/ m->tileX, (m->scrollY + Collision->y - 0)/ m->tileY);
  }
 }

 if(bottem)
 {
  tile = GetTile(m,((m->scrollX + Collision->x +Collision->stretchX ))/ m->tileX, (m->scrollY + Collision->y + Collision->stretchY + 0)/ m->tileY);
  if (!tile)
  {
  tile = GetTile(m,((m->scrollX + Collision->x))/ m->tileX, (m->scrollY + Collision->y + Collision->stretchY + 0)/ m->tileY);
  }
 }

 switch(tile)
 {
    case TILE_NONSOLID:
	return 0;
	break;

    case TILE_SOLID:
	return 1;
	break;
 }

return 0;
}
{......}
The only problem I had is the player is 32 by 32 so it would often get stuck and when I scroll left my collision gets displaced, but when I scroll to the right everything is fine.
pspmasterpro est déconnecté   Réponse avec citation