Messages récents

#61
PVSnesLib English section / Re : Sprites - X Y negative co...
Dernier message par alekmaul - 13 Juillet 2013 à 08:23:54
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 ;) !
#62
PVSnesLib English section / Re : Adding Collision?
Dernier message par alekmaul - 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 : http://en.wikipedia.org/wiki/Hit-testing

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
    else
      return false
}
#63
PVSnesLib English section / Adding Collision?
Dernier message par RonaldCoLtd - 10 Juillet 2013 à 22:28:31
I've been trying to figure out how to add collision to your game from quite awhile. I've tried, but most of the time failed. Anyone have any suggestions?
#64
PVSnesLib English section / Re : Sprites - X Y negative co...
Dernier message par faeldaniel - 09 Juillet 2013 à 04:01:46
Sorry for the delay in responding, look this video I found a way to solve this problem, I made a modification to the original code from your example for Animated Sprite I show in the current code and my new code with debug, see the differences:

http://youtu.be/U_6YaqWhKMA



#include <snes.h>

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

char messtxt[45];

#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
//---------------------------------------------------------------------
enum {SCREEN_TOP = -255, SCREEN_BOTTOM = 512, SCREEN_LEFT = -255, SCREEN_RIGHT = 512};

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

//---------------------------------------------------------------------------------
int main(void) {
unsigned short pad0,i;
Monster monster = {-30,100};

    // Initialize SNES
consoleInit();

// Init Sprites gfx and palette with default size of 16x16
oamInitGfxSet(&gfxpsrite, (&gfxpsrite_end-&gfxpsrite), &palsprite, (&palsprite_end-&palsprite), 0, 0x0000, OBJ_SIZE16);


// Define sprites parameters
//oamSet(0,  monster.x, monster.y, 0, 0, 0, 0, 0);
//oamSetEx(0, OBJ_SMALL, OBJ_SHOW);

//new
oamInitGfxAttr(0x0000, OBJ_SMALL);
oamSetXYEx(0, monster.x, monster.y);

// Now Put in 16 color mode and disable all backgrounds
setMode(BG_MODE1,0); bgSetDisable(0); bgSetDisable(1); bgSetDisable(2);

// Wait VBL 'and update sprites too ;-)
WaitForVBlank();

// Wait for nothing :P
while(1) {
// Refresh pad values
scanPads();

// Get current #0 pad
pad0 = padsCurrent(0);

if (pad0) {
// Update sprite with current pad
if(pad0 & KEY_UP) {
if(monster.y >= SCREEN_TOP) monster.y--;
monster.state = W_UP;
monster.flipx = 0;
}
if(pad0 & KEY_LEFT) {
if(monster.x >= SCREEN_LEFT) monster.x--;
monster.state = W_LEFT;
monster.flipx = 1;
}
if(pad0 & KEY_RIGHT) {
if(monster.x <= SCREEN_RIGHT) monster.x++;
monster.state = W_LEFT;
monster.flipx = 0;
}
if(pad0 & KEY_DOWN) {
if(monster.y <= SCREEN_BOTTOM) monster.y++;
monster.state = W_DOWN;
monster.flipx = 0;
}
monster.anim_frame++;
if(monster.anim_frame >= FRAMES_PER_ANIMATION){
monster.anim_frame = 0;

sprintf(messtxt,"NEW CODE:  X= %d   Y= %d\n",monster.x, monster.y);
consoleNocashMessage(messtxt);

}
}

// 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);

//new
oamSetGfxOffset(0, monster.gfx_frame);
oamSetXYEx(0, monster.x, monster.y);


// Wait VBL 'and update sprites too ;-) )
WaitForVBlank();
}
return 0;
}



This code works only if the position of the sprite start out screen but do not know if this correct :(.

Found that the position coordinate X or Y is reset when the function oamSetEx (0, OBJ_SMALL, OBJ_SHOW); runs
#65
PVSnesLib English section / Re : Sprites - X Y negative co...
Dernier message par alekmaul - 07 Juillet 2013 à 21:14:10
yep, so i thought that it was fixed ... :(
could you please post a source code to help me to investigate your problem
#66
PVSnesLib English section / Re : Sprites - X Y negative co...
Dernier message par faeldaniel - 05 Juillet 2013 à 15:14:13
i see the function oamSetXYEx what was needed, working in X but bug the sprite, however the idea that this need is.

I found this topic just talking about it and your comment http://forums.nesdev.com/viewtopic.php?p=97047
#67
PVSnesLib English section / Re : Sprites - X Y negative co...
Dernier message par alekmaul - 05 Juillet 2013 à 06:33:42
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.
#68
PVSnesLib English section / Re : Sprites - X Y negative co...
Dernier message par faeldaniel - 05 Juillet 2013 à 05:19:40
I get and now im testing in my engine, thanks for contribuition, loved the debug mode in NO$SNS is being very most useful :) .

I try to explain my problem, defined as negative values ​​less than zero or even exceeding the value 255 is reset in screen, for example:
-5 == 250
-25 == 230
325 == 70

I want the sprite gradually disappear from the screen as we see in most games, exactly the same as when you define 253, check that only part of the sprite is visible to another part of this out of the screen.

Basically I need the sprites with positions -25 and 280 where 0 and 255 are the parts visible on the screen.
#69
PVSnesLib English section / Re : Sprites - X Y negative co...
Dernier message par alekmaul - 02 Juillet 2013 à 06:20:26
take the last version from googlecode, i chnaged some things regarding sprite management.
#70
PVSnesLib English section / Re : Sprites - X Y negative co...
Dernier message par faeldaniel - 27 Juin 2013 à 20:31:18
Thank alekmaul will check and test, thanks