#9538 - yaustar - Thu Aug 07, 2003 10:45 pm
Code: |
// Start main code int main(void) { u16 loop; u16 temp = 0; u16* temp_map; // Put the lights in the right position on screen for(int x=0; x<5; x++) { for(int y=0; y<5; y++) { allLights[x][y].y = y*32; allLights[x][y].x = x*32; allLights[x][y].activeFrame = OFF; allLights[x][y].spriteFrame[0] = 0; // 32x32 sprite uses 16 8x8 tiles allLights[x][y].spriteFrame[1] = 16; allLights[x][y].OAMSpriteNum = temp; temp++; } } // Have the selector sprite by default on the top left of the // light array selector.X = 0; selector.Y = 0; selector.x = 0; selector.y = 0; selector.OAMSpriteNum = 25; selector.spriteFrame = 32; // Set screen mode to MODE 0, enable sprites using 1D mapping SetMode(MODE_0 | OBJ_ENABLE | OBJ_MAP_1D); // Loading the palette into memory (16 colour palette) for(loop = 0; loop < 16; loop++) { OBJPaletteMem[loop] = palette[loop]; } InitialiseSprites(); // Load Sprite data into memory // The OFF state of light for(loop = 0; loop < 256; loop++) { OAMData[loop] = g_OFF[loop]; } // The ON state of light for(loop = 256; loop < 512; loop++) { OAMData[loop] = g_ON[loop - 256]; } // The SELECTOR sprite for(loop = 512; loop < 768; loop++) { OAMData[loop] = g_SELECT[loop - 512]; } // Attribute stuff for(int x = 0; x < 5; x++) { for(int y = 0; y < 5; y++) { SPRITES[allLights[x][y].OAMSpriteNum].attribute0 = COLOR_16 | SQUARE | allLights[x][y].y; SPRITES[allLights[x][y].OAMSpriteNum].attribute1 = SIZE_32 | allLights[x][y].x; SPRITES[allLights[x][y].OAMSpriteNum].attribute2 = allLights[x][y].spriteFrame[allLights[x][y].activeFrame]; } } SPRITES[selector.OAMSpriteNum].attribute0 = COLOR_16 | SQUARE | selector.y; SPRITES[selector.OAMSpriteNum].attribute1 = SIZE_32 | selector.x; SPRITES[selector.OAMSpriteNum].attribute2 = selector.spriteFrame; bg_title.number = 0; //background number 0-3 bg_title.charBaseBlock = 0; //tile start position bg_title.screenBaseBlock = 28; //map position on 2Kb boundary bg_title.colorMode = BG_COLOR_256; //colour mode of the tiles 16/256 bg_title.size = ROTBG_SIZE_256x256;//size of map bg_title.mosaic = 0; //disable mosiac property bg_title.x_scroll = 0; bg_title.y_scroll = 0; // enable background(s) EnableBackground(&bg_title); // Load all data of map into array for(loop = 0; loop < 256; loop++) BGPaletteMem[loop] = g_bg_tilesPalette[loop]; //load the background palette into memory for(loop = 0; loop < g_bg_tiles_WIDTH * g_bg_tiles_HEIGHT /2; loop++) //load tile image data bg_title.tileData[loop] = g_bg_tilesData[loop]; //load the map image data temp_map = (u16*)title1; for(loop = 0; loop < 32*32/2; loop++) //32x32 tiles /2 because 16 bit copy bg_title.mapData[loop] = temp_map[loop]; while(1) { if(!(*KEYS & KEY_START)) //if player presses start, thne exit title screen { exit_game = 0; bg_title.x_scroll = 240; //move bacground off screen bg_title.y_scroll = 160; } WaitForVSync(); UpdateBackground(&bg_title); while(exit_game == 0) { // Initialise the position of the selector selector.X = 0; selector.Y = 0; // Load the puzzle data for(int x = 0; x < 5; x++) { for(int y = 0; y < 5; y++) { // Just because the way that the array is defined allLights[x][y].activeFrame = test01[y][x]; } } UpdateDisplay(); // Update the lights display // Display loop while(CheckWin() != 25) { CheckUser(); // Check if user has pressed any buttins GetInput(); // Get input from the user UpdateDisplay(); // Update the lights display WaitForVSync(); // Wait for screen to stop drawing CopyOAM(); // Copy sprite data over counter_0++; // Increment the counter every VSync/VBlank if(counter_0 == 30) counter_0 = 0; } } } } |
Here's the code. The background is completely messed up as it uses the tiles but sometimes they flipped and in the wrong places.
There is no problem with the data, just the code.
edit: I think that the gba is reading it as a text background hence why it thinks it is 512x256 instead of 256x256 and some of the tiles are flipped. Problem is I dont know how to fix it!!
argghgh
_________________
[Blog] [Portfolio]