:: PlayerAdvance.org ::

:: PlayerAdvance.org :: (http://www.playeradvance.org/forum/index.php)
-   Aide au développement (http://www.playeradvance.org/forum/forumdisplay.php?f=185)
-   -   PSP Aide [OSLIB] Get pixel question (http://www.playeradvance.org/forum/showthread.php?t=31004)

pspmasterpro 10/02/2009 06h13

[OSLIB] Get pixel question
 
Hello I saw a few topics regarding this and I have a few questions about the get pixel, can oslib read an entire image and see if some pixels are of a specified color. I'm trying to create a collision detection using tile maps. EG: say I have blue and pink tiles I want the blue tiles to be solid and pink to be non solid. My Question is, can oslib read every pixel of the image to check if it's blue or pink and then apply it to the map for the collisions?

Thanks for your help :)

Bonjour j'ai vu que quelques matières concernant ceci et moi ont quelques questions au sujet du Pixel d'obtention, peuvent oslib lisent une image entière et voient si quelques Pixel sont d'une couleur spécifique. I' ; m essayant de créer une détection de collision utilisant la tuile trace. PAR EXEMPLE : dites j'ai les tuiles bleues et roses que je veux que les tuiles bleues soient pleines et roses pour être non plein. Ma question est, peut oslib a lu chaque Pixel de l'image pour vérifier s'it' ; s bleu ou rose et s'appliquent alors l'à la carte pour les collisions ?

Merci pour votre aide :)

Yodajr 10/02/2009 07h02

http://www.playeradvance.org/forum/s...ad.php?t=23112

PS : forget about internet translation please, it is incomprehensible ;)

Dr.Vince 10/02/2009 10h34

for collision system using tiles precision and not pixel, you can just check the index of the tile.

Example:

in your tileset, index are: blue = 1 and red = 2
so when you read your map you can know what tile it is.

Not sure to be clear....

pspmasterpro 10/02/2009 23h38

So would it be like this:

Code:

#define TILE_SOLID 1
#define TILE_NONSOLID 2

TILE_SOLID = RGB(0,0,124);
TILE_NONSOLID = RGB(255,0,244);

// and then make the collision using these variables


Dr.Vince 11/02/2009 01h21

no, if you have a map like that:

Code:


#define TILE_SOLID 1  // 0x0001
#define TILE_NONSOLID 2 // 0x0002

const unsigned short example_map[8][13]=        {
        {0x0001, 0x0002, 0x0002, 0x0001, 0x0001,...
....

you can check :

Code:

example_map[x][y] == TILE_SOLID
where x,y are tile coordonates, not pixel, but this work only if you make tile collision precision, not pixel

pspmasterpro 11/02/2009 01h46

O.K. But my tile set and map are like this so do I have to create multipal example_map[x][y] == TILE_SOLID collision checks for each section of my map? Or can I replace X and Y with the entire map size and it will check the entire map?

Tileset
http://i208.photobucket.com/albums/b...on_tileset.png

Map
http://i208.photobucket.com/albums/b..._collsions.png

Oh and I convert my maps using GBA graphics

Dr.Vince 11/02/2009 11h08

hum sorry I can see your screenshot cause of a fucking proxy...... will see it at home

but if you want to check the position of a sprite, you take its coordonates (at pixel precision) and make a function to get the position on the map (something like x/8...)

and when you have the map position of the sprite you can check the type of tile at this position and do your stuff

pspmasterpro 13/02/2009 05h56

2 pièce(s) jointe(s)
O.K. here is my collisions_map.h
Code:

//C:\Users\Pspmasterpro\Desktop\lv1_collsions.png
//Converti avec GBA Graphics par Brünni
//Map ("","C:\Users\Pspmasterpro\Desktop\lv1_collsions.til.c",0,ffffffff)
//Taille: 32*32 * 60*9
//Mémoire: 1080 octets

const unsigned short LVCollision1_map[9][60]=        {
        {0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0001, 0x0004, 0x0005, 0x0006, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0003},
        {0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0001, 0x0007, 0x0005, 0x0006, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0003},
        {0x0000, 0x0000, 0x0000, 0x0000, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0001, 0x0009, 0x0005, 0x0006, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0003},
        {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x000a, 0x0005, 0x0006, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x000b, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0003},
        {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000b, 0x000c, 0x000d,
0x000a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000e, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x000f, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0003},
        {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0010, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0011, 0x000b, 0x0008, 0x000c, 0x000d,
0x0008, 0x000a, 0x0000, 0x0010, 0x0003, 0x0003, 0x0003, 0x0003,
0x0011, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000b, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x000a, 0x0000,
0x0000, 0x0000, 0x0000, 0x0003},
        {0x0000, 0x0010, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0005, 0x0006,
0x0000, 0x0000, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0012, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003},
        {0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0005, 0x0006,
0x0000, 0x0000, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0013, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003},
        {0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0005, 0x0006,
0x0000, 0x0000, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0014, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003}
};

So I think this method:
Code:

#define TILE_SOLID 1  // 0x0001
#define TILE_NONSOLID 2 // 0x0002

const unsigned short example_map[8][13]=       
{
        {0x0001, 0x0002, 0x0002, 0x0001, 0x0001,...
....

won't work since I have many different offsets.

I've attatched both the tileset and map images in case you can't see them.

Dr.Vince 13/02/2009 11h38

yes, again I ask the question: do you want pixel precision or tile precision ??

if it is tile, yes you need to add more define, not just solid/nonsolid

if it is pixel, you can by example (not sure if it is the best method) get the tile index from the map and then take the tile from your tileset and then check the pixel in the tile

pspmasterpro 15/02/2009 06h33

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

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.

Dr.Vince 15/02/2009 19h06

hum it's difficult to help you like that, but maybe you must replace - 0 by some value, cause perhaps you are testing the tile where you are instead of the tile at the left of the player

I think you must add some debug trace (oslPrintf etc...) to check that your code do the right stuff

and the last thing, the value 1.3 do nothing because it is int type...

pspmasterpro 21/02/2009 02h13

Thanks, I changed the 1.3 value to 1 and replaced -0 with -1 and I resized my character to 30 by 30 and it works well. I have another problem, in my game function I can't seam to use osl_keys->pressed I can only use osl_keys->held. Example here is my newGame function:
Code:

void newGame()
{
 int RLimit = 250;
 int LLimit = 50;
 int canJump = 1;
 oslReadKeys();
 oslCls();

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

 // Active gravity
 if(!collisionMgr(mapCollision1,player,0,0,0,1) && canJump == 1)
 {
  player->y += 1;
 }
 else if(collisionMgr(mapCollision1,player,0,0,0,1))
 {
  canJump = 1;
 }

 // 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;
    mapCollision1->scrollX += 1;
  }
  else
  {
    player->x += 1;
  }
 }

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

 if(osl_keys->pressed.cross && !collisionMgr(mapCollision1,player,0,0,1,0))
 {
  if(canJump == 1)
  canJump = 0;
  player->y -= 3;
 }
}

The pressed.cross doesn't work, when I press (X) button nothing happens, but when I replace "pressed" with "held" it works fine but the player continously assends so I have to use pressed but it doesn't respond. :hmm:

Dr.Vince 21/02/2009 12h18

First thing, it is better to open different threads on the forum if it is different problem for helping other member in the future

Then add else if for your key input, it is always better to use else if if it is exclusive cases.

And for your problem maybe canJump = 0, so press X do nothing... add oslDebug to be sure X pressed is detect

pspmasterpro 21/02/2009 23h24

Thanks I removed oslReadKeys(); from newGame and pressed works. O.K. for my next question I'll make a new thread.


Fuseau horaire GMT +2. Il est actuellement 04h40.

Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd. Tous droits réservés.
Version française #16 par l'association vBulletin francophone