#include // PAGfxConverter Include #include "gfx\all_gfx.c" #include "gfx\all_gfx.h" typedef struct{ s32 x, y; s32 flip; } linktype; linktype link; void Movelink(void); void CheckCollisions(void); u8 GetTile(s16 x, s16 y); u8 LeftCollision(void); u8 RightCollision(void); u8 DownCollision(void); u8 TouchingGround(void); int main(void){ PA_Init(); //PAlib inits PA_InitVBL(); PA_InitText(1,0); // init text screen 1 // Load a large scrolling background converted with PAGfx... PA_LoadPAGfxLargeBg(1, //screen 2, //background number (0-3) Main); // Name PA_LoadPAGfxLargeBg(1, 1, Mainhard); // Next we'll scroll, here are the variables... s32 scrollx = 0; s32 scrolly = 0; PA_LoadSpritePal(1, 0, (void*)link_Pal); // Palette.... s32 x = 120; s32 y = 64; s32 xx = 0; s32 yy = 0; PA_CreateSprite(1, 0,(void*)link_Sprite, OBJ_SIZE_32X32,1, 0, x, y); // Sprite link.x = 1<<8; link.y = (128-32)<<8; // bottom of the screen... fixed point link.flip = 0; PA_CreateSprite(1, 0,(void*)link_Sprite, OBJ_SIZE_32X32,1, 0, link.x>>8, link.y>>8); // Sprite while(1) // Infinite loops { // We need to change the scroll according to the held keys... scrollx += (Pad.Held.Right - Pad.Held.Left)*4; // scroll 4 pixels at a time scrolly += (Pad.Held.Down - Pad.Held.Up)*4; // Same thing PA_LargeScrollXY(1, // screen 2, // background number scrollx, // X scroll scrolly); // and Y scroll PA_LargeScrollXY(1, 1, scrollx, scrolly); // Animation code... if(Pad.Newpress.Up) PA_StartSpriteAnim(0, 0, 0, 8, 9); if(Pad.Newpress.Down) PA_StartSpriteAnim(0, 0, 18, 26, 9); if(Pad.Newpress.Right) { PA_StartSpriteAnim(0, 0, 9, 17, 9); PA_SetSpriteHflip(0, 0, 0); } if(Pad.Newpress.Left) { PA_StartSpriteAnim(0, 0, 9, 17, 9); PA_SetSpriteHflip(0, 0, 1); } if(!((Pad.Held.Left)||(Pad.Held.Up)||(Pad.Held.Down)||(Pad.Held.Right))) PA_SpriteAnimPause(0, 0, 1); yy += Pad.Newpress.X - Pad.Newpress.B; xx += Pad.Newpress.A - Pad.Newpress.Y; // Moving Code y += (Pad.Held.Down - Pad.Held.Up) * yy; x += (Pad.Held.Right - Pad.Held.Left) * xx; PA_SetSpriteXY(0, 0, x, y); CheckCollisions(); PA_WaitForVBL(); } return 0; } u8 GetTile(s16 x, s16 y){ if (x < 0 || x > 256) return 1; //Say it was a collision if the sprite tries //to move out of the map horizontal boundaries return Mainhard_Map[((y>>3)*32) + (x>>3)]; } u8 LeftCollision(void){ return GetTile((link.x>>8)+2, (link.y>>8)+8+(link.flip*13)); } u8 RightCollision(void){ return (GetTile((link.x>>8)+29, (link.y>>8)+8 + ((!link.flip)*13))); } u8 DownCollision(void){ return (GetTile((link.x>>8)+10 + (link.flip*11), (link.y>>8)+31)); } u8 TouchingGround(void){ return GetTile((link.x>>8)+10 + (link.flip*11), (link.y>>8)+32); } void CheckCollisions(void){ while(LeftCollision()){ // Collision on the left of the sprite... link.x+= 256; // Move by 1 pixel... } while(RightCollision()){ // Collision on the right of the sprite... link.x-= 256; // Move by 1 pixel... } while(DownCollision()){ // Collision on the bottom of the sprite... link.y -= 128; // Move by 1/2 pixel... } }