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
}
#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;
}
-5 == 250
-25 == 230
325 == 70