//---------------------------------------------------------------------------------------------------------------- // FILE: main.c // AUTHOR: Shaun Gibson // FILE-GROUP: Fading tutorial //---------------------------------------------------------------------------------------------------------------- #include #include "pad.h" #include "main.h" //includes all of the defines, global variables and procedure definitions //---------------------------------------------------------------------------------------------------------------- // GLOBALS //must be included here, the extern versions in the header file take these to use in init.c //---------------------------------------------------------------------------------------------------------------- GsOT WorldOT[2]; GsOT_TAG OT_TAGS[2][1< 2)) //reset back to normal if fading is finished or if //spotlight is on { fading = 0; fadebox.r = fadebox.g = fadebox.b = 0; //re-initialise fadebox's rgb values to 0 (black) } // the following if statements move the spotlight around the screen and limit it to stay fully inside the screen if (padd & PADLup) { spotsprite.y -= 3; if (spotsprite.y < 0) spotsprite.y = 0; } if (padd & PADLdown) { spotsprite.y += 3; if (spotsprite.y > (SCREEN_HEIGHT - spotsprite.h)) spotsprite.y = SCREEN_HEIGHT - spotsprite.h; } if (padd & PADLleft) { spotsprite.x -= 3; if (spotsprite.x < 0) spotsprite.x = 0; } if (padd & PADLright) { spotsprite.x += 3; if (spotsprite.x > (SCREEN_WIDTH - spotsprite.w)) spotsprite.x = SCREEN_WIDTH - spotsprite.w; } // ends the program by setting done to 1 so the main loop ends if (padd & PADselect) done = 1; } void Fade(void) { if (fadebox.r == 252) //r g and b are all the same, so only need to check one of them { fadebox.r = fadebox.g = fadebox.b = 255; //r g and b are char values, so they can't go //to 256, so this if bit intercepts the attempt //as it were fading = 4; } else { fadebox.r = fadebox.g = fadebox.b += 4; //increments rgb values by 4 } } void SpotLight(void) //updates the positions and sizes of the blocking boxes for the spotlight { spotblock[0].x = 0; //left of spotlight is blanked spotblock[0].y = 0; spotblock[0].w = spotsprite.x; spotblock[0].h = SCREEN_HEIGHT; spotblock[1].x = 0; //top of spotlight is blanked spotblock[1].y = 0; spotblock[1].w = SCREEN_WIDTH; spotblock[1].h = spotsprite.y; spotblock[2].x = spotsprite.x + spotsprite.w; //right of spotlight is blanked spotblock[2].y = 0; spotblock[2].w = SCREEN_WIDTH - spotblock[2].x; spotblock[2].h = SCREEN_HEIGHT; spotblock[3].x = 0; //bottom of spotlight is blanked spotblock[3].y = spotsprite.y + spotsprite.h; spotblock[3].w = SCREEN_WIDTH; spotblock[3].h = SCREEN_HEIGHT - spotblock[3].y; } void Update(void) { short a; output_buffer_index = GsGetActiveBuff(); //sets the output_buffer_index to handle the current OT GsSetWorkBase((PACKET*)GpuPacketArea[output_buffer_index]); //set work area GsClearOt(0, 0, &WorldOT[output_buffer_index]); //clears the ordering table of previous contents for (a = 0; a < NUM_BOXES; a++) { GsSortBoxFill(&box[a], &WorldOT[output_buffer_index], 1); //put the backgound objects //into the ordering table } if ((fading == 1) || (fading == 2) || (fading == 4)) { GsSortBoxFill(&fadebox, &WorldOT[output_buffer_index], 0); //if applicable, put fadebox into //the ordering table at the top //level (priority 0) } if (fading == 3) //if spotlight is on: { GsSortSprite(&spotsprite, &WorldOT[output_buffer_index], 0); //put spotlight sprite into OT at //priority 0 (top) for (a = 0; a < 4; a++) { GsSortBoxFill(&spotblock[a], &WorldOT[output_buffer_index], 0); //and also the blocking boxes } } FntFlush(fnt_id); //display the fonts DrawSync(0); VSync(0); //wait for syncronisation so there is no flickering GsSwapDispBuff(); //swap the display buffers so the previously drawn screen is now displayed GsSortClear(0x20, 0x30, 0x40, &WorldOT[output_buffer_index]); //set the background colour GsDrawOt(&WorldOT[output_buffer_index]); //draw the ordering table to display buffer }