:: PlayerAdvance.org ::  

Précédent   :: PlayerAdvance.org :: > :: Forums Hébergés :: > OldSchool Library > Aide au développement

Aide au développement Aide sur l'utilisation d'OSLib

Publicité

Réponse
 
Outils de la discussion Modes d'affichage
Vieux 10/02/2009, 06h13   #1
pspmasterpro
Membre
 
Date d'inscription: 22/01/2009
Messages: 17
Par défaut [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
pspmasterpro est déconnecté   Réponse avec citation

Publicité

Vieux 10/02/2009, 07h02   #2
Yodajr
Administrateur
 
Date d'inscription: 09/11/2005
Messages: 3 750
Par défaut

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

PS : forget about internet translation please, it is incomprehensible
Yodajr est déconnecté   Réponse avec citation
Vieux 10/02/2009, 10h34   #3
Dr.Vince
Administrateur
 
Date d'inscription: 10/11/2005
Messages: 4 965
Voir les codes amis Nintendo DS Voir les codes amis Wii
Par défaut

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....
__________________
Projets Abandonnés: [Arcomage Advance] [Puzznic] [PA Card Games] [Blob Runner]
Projet en cours: [Ne plus abandonner de projet...]
Dr.Vince est déconnecté   Réponse avec citation
Vieux 10/02/2009, 23h38   #4
pspmasterpro
Membre
 
Date d'inscription: 22/01/2009
Messages: 17
Par défaut

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
pspmasterpro est déconnecté   Réponse avec citation
Vieux 11/02/2009, 01h21   #5
Dr.Vince
Administrateur
 
Date d'inscription: 10/11/2005
Messages: 4 965
Voir les codes amis Nintendo DS Voir les codes amis Wii
Par défaut

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
__________________
Projets Abandonnés: [Arcomage Advance] [Puzznic] [PA Card Games] [Blob Runner]
Projet en cours: [Ne plus abandonner de projet...]
Dr.Vince est déconnecté   Réponse avec citation
Vieux 11/02/2009, 01h46   #6
pspmasterpro
Membre
 
Date d'inscription: 22/01/2009
Messages: 17
Par défaut

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


Map


Oh and I convert my maps using GBA graphics
pspmasterpro est déconnecté   Réponse avec citation
Vieux 11/02/2009, 11h08   #7
Dr.Vince
Administrateur
 
Date d'inscription: 10/11/2005
Messages: 4 965
Voir les codes amis Nintendo DS Voir les codes amis Wii
Par défaut

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
__________________
Projets Abandonnés: [Arcomage Advance] [Puzznic] [PA Card Games] [Blob Runner]
Projet en cours: [Ne plus abandonner de projet...]
Dr.Vince est déconnecté   Réponse avec citation
Vieux 13/02/2009, 05h56   #8
pspmasterpro
Membre
 
Date d'inscription: 22/01/2009
Messages: 17
Par défaut

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.
Miniatures attachées
Cliquez sur l'image pour la voir en taille réelle

Nom : lv1_collsions.jpg
Affichages : 665
Taille : 10,4 Ko
ID : 1304  Cliquez sur l'image pour la voir en taille réelle

Nom : lv1Collision_tileset.png
Affichages : 665
Taille : 1,8 Ko
ID : 1305  
pspmasterpro est déconnecté   Réponse avec citation
Vieux 13/02/2009, 11h38   #9
Dr.Vince
Administrateur
 
Date d'inscription: 10/11/2005
Messages: 4 965
Voir les codes amis Nintendo DS Voir les codes amis Wii
Par défaut

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
__________________
Projets Abandonnés: [Arcomage Advance] [Puzznic] [PA Card Games] [Blob Runner]
Projet en cours: [Ne plus abandonner de projet...]
Dr.Vince est déconnecté   Réponse avec citation
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
Vieux 15/02/2009, 19h06   #11
Dr.Vince
Administrateur
 
Date d'inscription: 10/11/2005
Messages: 4 965
Voir les codes amis Nintendo DS Voir les codes amis Wii
Par défaut

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...
__________________
Projets Abandonnés: [Arcomage Advance] [Puzznic] [PA Card Games] [Blob Runner]
Projet en cours: [Ne plus abandonner de projet...]
Dr.Vince est déconnecté   Réponse avec citation
Vieux 21/02/2009, 02h13   #12
pspmasterpro
Membre
 
Date d'inscription: 22/01/2009
Messages: 17
Par défaut

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.

Dernière modification par pspmasterpro ; 21/02/2009 à 02h28.
pspmasterpro est déconnecté   Réponse avec citation
Vieux 21/02/2009, 12h18   #13
Dr.Vince
Administrateur
 
Date d'inscription: 10/11/2005
Messages: 4 965
Voir les codes amis Nintendo DS Voir les codes amis Wii
Par défaut

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
__________________
Projets Abandonnés: [Arcomage Advance] [Puzznic] [PA Card Games] [Blob Runner]
Projet en cours: [Ne plus abandonner de projet...]
Dr.Vince est déconnecté   Réponse avec citation
Vieux 21/02/2009, 23h24   #14
pspmasterpro
Membre
 
Date d'inscription: 22/01/2009
Messages: 17
Par défaut

Thanks I removed oslReadKeys(); from newGame and pressed works. O.K. for my next question I'll make a new thread.
pspmasterpro est déconnecté   Réponse avec citation
Réponse

Liens sociaux

Publicité



Utilisateurs regardant la discussion actuelle : 1 (0 membre(s) et 1 invité(s))
 
Outils de la discussion
Modes d'affichage

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Navigation rapide

Discussions similaires
Discussion Auteur Forum Réponses Dernier message
PSP Aide Get pixel Albandu51 Aide au développement 1 17/12/2008 12h05
µLibrary Aide Récuperer un pixel sur une map et question sur la Vram morukutsu µLibrary 7 09/04/2008 02h45
PSP Aide [oslib] Question performance des maps dragfly Aide au développement 1 13/02/2008 22h03
[oslib] petite question: collisions norfair Aide au développement 13 20/01/2007 20h19
Pixel mort... ou pas ? katrinien [NDS] Divers 33 15/08/2006 20h40


Fuseau horaire GMT +2. Il est actuellement 20h00.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd. Tous droits réservés.
Version française #16 par l'association vBulletin francophone
Design par Ass-Itch, DJP et Dr.Vince