Voir les contributions

Cette section vous permet de consulter les contributions (messages, sujets et fichiers joints) d'un utilisateur. Vous ne pourrez voir que les contributions des zones auxquelles vous avez accès.

Voir les contributions Menu

Messages - alekmaul

Well, your problem is with the coordinates.
I think you must only have
  //512 pixel width 512/8 = 64
   u16 *ptrMap = (u16 *) &mapCol +  (OBJY>>3)*64 + (OBJX>>3);
X does not need to be multiply by height

Also, try to use u16 instead of short, short is signed and is bad for SNES (your u8 for mapcol is correct).
I don't understand what you want to do.
If you need value of 14° tile of your 1 line, you just need to do valueOfTile=mapcol[14], why are you usigned & for address of mapcol ?
If it is value of 14° tile of 2nd line, it's mapcol[14*256] if you have a short type for mapcol, and so on ...
c'est clair, plus de mise à jour. Mais tu sais, sur certains projets, je reprends après plus de 6 mois ;)
And sorry for the lack of reply, I was very busy last weeks :(.
Nice to see that you solved your problem.
Don't hesitate to query some new feature for gfx2snes !
ouep, j'ai vu, à suivre, mais hélas compatible avec uniquement les anciennes versions du firmware si j'ai bonne mémoire (4.5 max) ....
Well, the collision map uses 8x8 pixel for each tile, so you need to devide coordinate by the size of your collide box.
Also, to have the correct tile, you must add map size * y , not only y.

Citationu16 getCollisionTile(u16 x, u16 y) {
   u16 *ptrMap = (u16 *) &col + (y>>3)*32+ (x>>3);
   return (*ptrMap);

But, you also need to take care of sprite size and where is the point that you need to use to check the collide box.
Here is an example, "not so good" but that uses a point near middle of sprite to test hit box with back ground (so I use x+8, y+8).


   Animated Sprite demo
   -- alekmaul

Sprite from Stephen "Redshrike" Challener),

#include <snes.h>

extern char gfxpsrite, gfxpsrite_end;
extern char palsprite, palsprite_end;

extern char patterns, patterns_end;
extern char palette, palette_end;
extern char map, map_end;

extern char col, col_e;

#define FRAMES_PER_ANIMATION 3 // 3 sprites per direction

// The Monster sprite
typedef struct
   short x, y;
   int gfx_frame;
   int state;
   int anim_frame;
   int flipx;
} Monster;

// The state of the sprite (which way it is walking)
enum SpriteState {W_DOWN = 0, W_UP = 1, W_RIGHT = 2,  W_LEFT = 2};

// Screen dimentions

char sprTiles[9]={0,2,4, 6,8,10, 12,14,32};  // Remeber that sprites are interleave with 128 pix width,

u16 getCollisionTile(u16 x, u16 y) {
   u16 *ptrMap = (u16 *) &col + (y>>3)*32 + (x>>3);
   return (*ptrMap);

int main(void) {
   unsigned short pad0,i;
   Monster monster = {10,10};
    // Initialize SNES
   // Init Sprites gfx and palette with default size of 16x16
   oamInitGfxSet(&gfxpsrite, (&gfxpsrite_end-&gfxpsrite), &palsprite, (&palsprite_end-&palsprite), 0, 0x0000, OBJ_SIZE16);
   // Copy tiles to VRAM
   bgInitTileSet(0, &patterns, &palette, 0, (&patterns_end - &patterns), (&palette_end - &palette), BG_16COLORS, 0x4000);

   // Copy Map to VRAM
   bgInitMapSet(0, &map, (&map_end - &map),SC_32x32, 0x1000);
   // Define sprites parameters
   oamSet(0,  monster.x, monster.y, 0, 0, 0, 0, 0);
   oamSetEx(0, OBJ_SMALL, OBJ_SHOW);

   // Now Put in 16 color mode and disable all backgrounds
   setMode(BG_MODE1,0); bgSetDisable(1); bgSetDisable(2);
   // Wait VBL 'and update sprites too ;-)
   // Wait for nothing :P
   while(1) {
      // Refresh pad values
      // no more need with last lib scanPads();
      // Get current #0 pad
      pad0 = padsCurrent(0);
      if (pad0) {
         // Update sprite with current pad
         if(pad0 & KEY_UP) {
            if (getCollisionTile((monster.x+8), ((monster.y) - 1)) == 0) {
               if(monster.y >= SCREEN_TOP) monster.y--;
            monster.state = W_UP;
            monster.flipx = 0;
         if(pad0 & KEY_LEFT) {
            if (getCollisionTile(((monster.x) - 1), (monster.y+8)) == 0) {
               if(monster.x >= SCREEN_LEFT) monster.x--;
            monster.state = W_LEFT;
            monster.flipx = 1;
         if(pad0 & KEY_RIGHT) {
            if (getCollisionTile(((monster.x +16) +1), (monster.y+8)) == 0) {
               if(monster.x <= SCREEN_RIGHT) monster.x++;
            monster.state = W_LEFT;
            monster.flipx = 0;
         if(pad0 & KEY_DOWN) {
            if (getCollisionTile((monster.x+8), ((monster.y+16) + 1)) == 0) {
               if(monster.y <= SCREEN_BOTTOM) monster.y++;
            monster.state = W_DOWN;
            monster.flipx = 0;
         if(monster.anim_frame >= FRAMES_PER_ANIMATION){
            monster.anim_frame = 0;
      // Now, get current sprite in current animation
      monster.gfx_frame = sprTiles[monster.anim_frame + monster.state*FRAMES_PER_ANIMATION ];
      oamSet(0,  monster.x, monster.y, 3, monster.flipx, 0, monster.gfx_frame, 0);
      // Wait VBL 'and update sprites too ;-) )
   return 0;
OK, I did the 1st fix in ASM. It is in google code. Need to work now on SetXYEx ...
PVSnesLib English section / Re : Adding Collision?
15 Juillet 2013 à 07:35:39
You can't use this function, it is only for map , when you want to know which tile is under or near something.
For sprite, you must use hitbox algo with x/y coordinates of each sprite.
Take a look at my previous posts, and adapt it for your sprite (Rectangle r1 is sprite #1 and r2 sprite #2)
OK, I See the problem but I think I will update pvsneslib with ASM functions to solve the speed issue we will have if you call all the time SetXYEx.
Need to code now ;) !
PVSnesLib English section / Re : Adding Collision?
12 Juillet 2013 à 06:10:15
The best way is to use an hixbox algorythm.
It is not really strict (regarding each sprite look) but really fast. Pixel perfect collision will be too slow for PVSnesLib.
Take a look here :

Citationfunction HitTest(Rectangle r1, Rectangle r2) returns boolean
    if ((r1.X + r1.Width >= r2.X) and (r1.X <= r2.X + r2.Width))
    and ((r1.Y + r1.Height >= r2.Y) and (r1.Y <= r2.Y + r2.Height)) then
      return true
      return false
yep, so i thought that it was fixed ... :(
could you please post a source code to help me to investigate your problem
OK, i understand but I do not have this problem with my current test.
When my x coordinate is more than 240, for a 16x16 sprite, i see only the part on screen.
Could you post a bit of code ?
Perhaps you need to set the high x bit with oamSetXYEx, but it will be slow, the function is not optimized.
take the last version from googlecode, i chnaged some things regarding sprite management.
Well, you can put something negative. You must set the hide flash with oamHide that do such thing.
I updated googlecode entries with last version of pvsneslib.
Hope it will help you.
Oui, j'ai vu sur gbatemp, mais il semble que le dernier update 3DS bloque ce linker.
De totue façon, on peut pas développer sur 3DS, donc cela ne m'intéresse pas trop ...