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.


Messages - zenac

Pages: [1]
1
I think ">=" is correct!

The original image has 9 sprites: 3 for down, 3 for up and 3 for right or left. So, the indexes of "sprTiles" array are:

> 0, 1, 2 for down
> 3, 4, 5 for up
> 6, 7, 8 for right/left

if(monster.anim_frame >= FRAMES_PER_ANIMATION) monster.anim_frame = 0;
When "monster.anim_frame" has the value 3, it must be set to zero because we do not use "monster.anim_frame" equals to 3.

2
My project using sprites with 8x8 pixels is fine. But my project using sprites with 32x32 still has a small problem.

The last picture of the character moving to the left or to the right (sprTiles[8]) is now showed.

Maybe the last value of "sprTiles" array is wrong...

char sprTiles[9]={0,4,8, 12,64,68, 72,76,128};

What's the correct last value of this array? I say it again: each sprite has 32 x 32 pixels.

Complete code of "AnimatedSprite32x32.c" above:

#include <snes.h>

extern char gfxpsrite, gfxpsrite_end;
extern char palsprite;

#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 = 0, SCREEN_BOTTOM = 224, SCREEN_LEFT = 0, SCREEN_RIGHT = 256};

char sprTiles[9]={0,4,8, 12,64,68, 72,76,128};

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

    // Initialize SNES
consoleInit();

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

// 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(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;
}

// 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 ;-) )
WaitForVBlank();
}
return 0;
}


3
Thank you, Alekmaul!

4
I am trying it, but my program doesn't work.

I am changing "AnimatedSprite" project to "TwoAnimatedSprites". In the image "sprites.bmp", I have set new colors in the palette: color #16 is magenta (equal to color #0) and I have added new colors from #17 to #31.

Lines 63 to 65 in Makefile changed (I have changed "pc16 -po16" to "pc256 -po256" in line 65):

sprites.pic: sprites.bmp
@echo convert bitmap ... $(notdir $@)
$(GFXCONV) -gs16 -pc256 -po256 -n $<

And my complete "TwoAnimatedSprites.c" below:

/*---------------------------------------------------------------------------------


Animated Sprite demo
-- alekmaul

 Sprite from Stephen "Redshrike" Challener), http://opengameart.org

---------------------------------------------------------------------------------*/
#include <snes.h>

extern char gfxpsrite, gfxpsrite_end;
extern char palsprite;

#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 = 0, SCREEN_BOTTOM = 224, SCREEN_LEFT = 0, SCREEN_RIGHT = 256};

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 = {100,100};
Monster monster2 = {150,150}; // NEW LINE

    // Initialize SNES
consoleInit();

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

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

oamSet(16,  monster2.x, monster2.y, 0, 0, 0, 0, 16);  // NEW LINE
oamSetEx(16, OBJ_SMALL, OBJ_SHOW);  // NEW LINE

// 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(monster2.y >= SCREEN_TOP) monster2.y--;  // NEW LINE
monster2.state = W_UP;  // NEW LINE
monster2.flipx = 0;  // NEW LINE
}
if(pad0 & KEY_LEFT) {
if(monster.x >= SCREEN_LEFT) monster.x--;
monster.state = W_LEFT;
monster.flipx = 1;
if(monster2.x >= SCREEN_LEFT) monster2.x--;  // NEW LINE
monster2.state = W_LEFT;  // NEW LINE
monster2.flipx = 1;  // NEW LINE
}
if(pad0 & KEY_RIGHT) {
if(monster.x <= SCREEN_RIGHT) monster.x++;
monster.state = W_LEFT;
monster.flipx = 0;
if(monster2.x <= SCREEN_RIGHT) monster2.x++;  // NEW LINE
monster2.state = W_LEFT;  // NEW LINE
monster2.flipx = 0;  // NEW LINE
}
if(pad0 & KEY_DOWN) {
if(monster.y <= SCREEN_BOTTOM) monster.y++;
monster.state = W_DOWN;
monster.flipx = 0;
if(monster2.y <= SCREEN_BOTTOM) monster2.y++;  // NEW LINE
monster2.state = W_DOWN;  // NEW LINE
monster2.flipx = 0;  // NEW LINE
}
monster.anim_frame++;
if(monster.anim_frame >= FRAMES_PER_ANIMATION) monster.anim_frame = 0;
monster2.anim_frame++;  // NEW LINE
if(monster2.anim_frame >= FRAMES_PER_ANIMATION) monster2.anim_frame = 0;  // NEW LINE
}

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

monster2.gfx_frame = sprTiles[monster2.anim_frame + monster2.state*FRAMES_PER_ANIMATION ];  // NEW LINE
oamSet(16,  monster2.x, monster2.y, 3, monster2.flipx, 0, monster2.gfx_frame, 16);  // NEW LINE

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


I have NOT changed "date.asm" and "hdr.asm".

5
How can I draw the same sprite two times in the same screen but using different colors? For example, in a fight "Ryu (white clothes) vs. Ryu (dark clothes)" in "Street Fighter II" or in a sport game (Lakers with yellow uniform and Celtics with green uniform). Considering that two objects have the same sprite, can I associate the first object to a palette and the second object to another different palette?

6
Alekmaul, thank you very much!

7
My both picture files have the name "sprites.bmp". Here I changed the name to "sprites8x8" and "sprites32x32". The forum doesn't accept "bmp" files, so I have converted them to "png".

8
In fact, all the colors of my pictures are wrong.

I think I don't know how to change the line 65 of Makefile to make the right conversion of images of 8x8 pixels and 32x32 pixels...

Original "Makefile" (line 65)
$(GFXCONV) -gs16 -pc16 -po16 -n $<

As I have written before, I have only changed the first argument (-gs16 changed to -gs8 and -gs32) of $(GFXCONV) in Makefile.

Please, what should I do? Should I make other changes besides Makefile?

9
I'm trying to convert "AnimatedSprite" project. The original project uses sprites with 16x16 pixels. I would like to make a new version using sprites with 8x8 (project "AnimatedSprite8x8") and another new version using sprites with 32x32 (project "AnimatedSprite32x32").

The original file "AnimatedSprite.c" can be seen at:
http://www.portabledev.com/media/SNES/PVSnesLib/doc/a00010.html

I have copied all the files of the original project to the other two new projects.

But there are some differences:

- The file "AnimatedSprite.c" was renamed: "AnimatedSprite8x8.c" and "AnimatedSprite32x32.c"

- The dimensions of the original file image ("sprites.bmp") are: 16x144 pixels. The new versions of this files have the following dimensions: 8x72 pixels (for AnimatedSprite8x8) and 32x288 (for AnimatedSprite32x32).

Then, I have changed some lines of the code:

AnimatedSprite.c (line 39)
char sprTiles[9]={0,2,4, 6,8,10, 12,14,32};  // Remeber that sprites are interleave with 128 pix width,
AnimatedSprite8x8.c (line 39)
char sprTiles[9]={0,1,2, 3,4,5, 6,7,8};
AnimatedSprite32x32.c (line 39)
char sprTiles[9]={0,4,8, 12,64,68, 72,76,128};

AnimatedSprite.c (line 50)
oamInitGfxSet(&gfxpsrite, (&gfxpsrite_end-&gfxpsrite), &palsprite, 0, 0x4000, OBJ_SIZE16);
AnimatedSprite8x8.c (line 50)
oamInitGfxSet(&gfxpsrite, (&gfxpsrite_end-&gfxpsrite), &palsprite, 0, 0x4000, OBJ_SIZE8);
AnimatedSprite32x32.c (line 50)
oamInitGfxSet(&gfxpsrite, (&gfxpsrite_end-&gfxpsrite), &palsprite, 0, 0x4000, OBJ_SIZE32);

More changes in Makefile...

Makefile - AnimatedSprite (lines 63 to 65)
sprites.pic: sprites.bmp
@echo convert bitmap ... $(notdir $@)
$(GFXCONV) -gs16 -pc16 -po16 -n $<


Makefile - AnimatedSprite8x8 (lines 63 to 65)
sprites.pic: sprites.bmp
@echo convert bitmap ... $(notdir $@)
$(GFXCONV) -gs8 -pc16 -po16 -n $<


Makefile - AnimatedSprite32x32 (lines 63 to 65)
sprites.pic: sprites.bmp
@echo convert bitmap ... $(notdir $@)
$(GFXCONV) -gs32 -pc16 -po16 -n $<

When I run "AnimatedSprite8x8" and "AnimatedSprite32x32" the joystick moves the character, but the transparency effect does NOT work. The character is inside a visible square area.

Please, what have I forgotten?

Pages: [1]