#50525 - biubid_boy - Wed Aug 10, 2005 12:26 pm
I'm using Dovoto's PCX2SPRITE and a 256 colour .pcx file (8x32), but whenever I use it in my game, it comes up scrambled and weird coloured. My code is:
Anyone know why it keeps happening and how to fix it?
Thanks for any help,
Biubid_boy.
Code: |
#include "gba.h"
#include "paddlersbg.h" #include "ball.h" #include "xxx.h" void InitializeSprites(void); void CopyOAM(void); void MoveSprite(OAMEntry* sp, int x, int y); void MoveBall(void); void Movepaddleyellow(void); OAMEntry sprites[128]; u16 xball = 30; u16 yball = 50; u16 xpaddleyellow = 10; u16 ypaddleyellow = 10; u8 ballDirection = 0; u8 xMax = 148; u8 yMax = 144; u8 xMin = 8; u8 yMin = 8; int main() { u16 loop; SetMode(MODE_4 | BG2_ENABLE | OBJ_ENABLE | OBJ_MAP_1D); for(loop = 0; loop < 256; loop++) { OBJ_PaletteMem[loop] = ballPalette[loop]; } for (loop = 0; loop < 256; loop++) { BG_PaletteMem[loop]=paddlersbgPalette[loop]; } for (loop = 0; loop < (120*160); loop++) { FrontBuffer[loop] = paddlersbgData[loop] ; } memcpy( (u16 *)0x06014000, &ballData, sizeof(ballData) ); memcpy( (u16 *)0x06014100, &paddleyellowData, sizeof(paddleyellowData) ); sprites[0].attribute0 = COLOR_256 | SQUARE | yball; sprites[0].attribute1 = SIZE_8 | xball; sprites[0].attribute2 = 512; sprites[1].attribute0 = COLOR_256 | TALL | ypaddleyellow; sprites[1].attribute1 = SIZE_32 | xpaddleyellow; sprites[1].attribute2 = 512 + 8; while(1) { MoveBall(); Movepaddleyellow(); MoveSprite(&sprites[0],xball,yball); MoveSprite(&sprites[1],xpaddleyellow,ypaddleyellow); WaitForVsync(); CopyOAM(); } return 0; } void InitializeSprites(void) { u16 loop; for(loop = 0; loop < 128; loop++) { sprites[loop].attribute0 = 160; sprites[loop].attribute1 = 240; } } void CopyOAM(void) { u16 loop; u16* temp; temp = (u16*)sprites; for(loop = 0; loop < 128*4; loop++) { OAM_Mem[loop] = temp[loop]; } } void MoveSprite(OAMEntry* sp, int x, int y) { sp->attribute1 = sp->attribute1 & 0xFE00; sp->attribute1 = sp->attribute1 | x; sp->attribute0 = sp->attribute0 & 0xFF00; sp->attribute0 = sp->attribute0 | y; } void MoveBall(void) { if (ballDirection == 0 && xball < xMax && yball < yMax) { xball++;xball++;xball++; yball++;yball++; } if (ballDirection == 0 && (xball >= xMax || yball >= yMax )) { if (xball >= xMax) { ballDirection = 3; } else { ballDirection = 1; } } if (ballDirection == 1 && xball < xMax && yball > yMin) { xball++;xball++;xball++; yball--;yball--; } if (ballDirection == 1 && (xball >= xMax || yball <= yMin )) { if (xball >= xMax) { ballDirection = 2; } else { ballDirection = 0; } } if (ballDirection == 2 && xball > xMin && yball > yMin) { xball--;xball--;xball--; yball--;yball--; } if (ballDirection == 2 && (xball <= xMin || yball <= yMin )) { if (xball <= xMin) { ballDirection = 1; } else { ballDirection = 3; } } if (ballDirection == 3 && xball > xMin && yball < yMax) { xball--;xball--;xball--; yball++;yball++; } if (ballDirection == 3 && (xball <= xMin || yball >= yMax)) { if (xball <= xMin) { ballDirection = 0; } else { ballDirection = 2; } } } void Movepaddleyellow(void) { if(keyDown(KEY_DOWN) && ypaddleyellow < yMax - 24) { ypaddleyellow++;ypaddleyellow++;ypaddleyellow++; } if(keyDown(KEY_UP) && ypaddleyellow > yMin) { ypaddleyellow--;ypaddleyellow--;ypaddleyellow--; } } |
Anyone know why it keeps happening and how to fix it?
Thanks for any help,
Biubid_boy.