// ****************** // Initialise program // ****************** void Initialise() { u_short t1, t2; u_char *t3; PadInit(); // Set up pads to work correctly FntLoad(320, 256); // load the standard font into memory FntOne = FntOpen(32, 228, 256, 8, 1, 256); // give display window info for font LoadTIMData(BACK01_TIM); // Load graphics into video ram LoadTIMData(BACK02_TIM); LoadTIMData(FRONT01_TIM); LoadTIMData(FRONT02_TIM); LoadTIMData(HERORUN_TIM); LoadTIMData(TREETOPS_TIM); // Set up player for (t1 = 0; t1 < 30; t1++) // Chop up player running graphics into sprites { SetBlocksInfo(&PRun[t1], 576, 256, (t1 % 9) * 53, (t1 / 9) * 58, 53, 58, 320, 5, 8); PRun[t1].attribute += (2 << 27) + (1 << 30); } // Set up background for (t1 = 0; t1 < 4; t1++) // Chop up background graphics into sprites { for (t2 = 0; t2 < 20; t2++) { SetBlocksInfo(&MountainsSprite[t1 * 20 + t2], 704, 0, t2 * 16, t1 * 16, 16, 16, 320, 0, 8); MountainsSprite[t1 * 20 + t2].mx = 0; // For reflection, since non-reflection uses MountainsSprite[t1 * 20 + t2].my = 8; // fast sort and therefore ignores these value Mountains[t2][t1] = t1 * 20 + t2; // Set background array } } // Set up clouds for (t1 = 0; t1 < 13; t1++) // Chop up cloud graphics into sprites { for (t2 = 0; t2 < 16; t2++) { SetBlocksInfo(&CloudSprite[t1 * 16 + t2], 832, 256, t2 * 16, t1 * 16, 16, 16, 320, 3, 4); } } for (t1 = 0; t1 < 12; t1++) // Set up clouds layer { for (t2 = 0; t2 < 16; t2++) { if (t1 < 11) { Clouds[t2][t1] = t1 * 16 + t2; // Set cloud array } else { Clouds[t2][t1] = 12 * 16 + t2; // Set cloud array } } } // Set up treetops for (t1 = 0; t1 < 2; t1++) // Chop up treetop graphics into sprites { for (t2 = 0; t2 < 2; t2++) { SetBlocksInfo(&TreeTopSprite[t1 * 2 + t2], 864, 0, t2 * 16, t1 * 16, 16, 16, 320, 4, 4); } } // Set up foreground for (t1 = 0; t1 < 16; t1++) // Chop up foreground grpahics into sprites { for (t2 = 0; t2 < 16; t2++) { SetBlocksInfo(&ForegroundSprite[t1 * 16 + t2], 896, 0, t2 * 16, t1 * 16, 16, 16, 320, 2, 8); } } for (t1 = 0; t1<100; t1++) // Load foreground data from memory { for (t2 = 0; t2<100; t2++) { t3 = (u_char*)(LEVEL_DAT + t1 * 100 + t2); Foreground[t2][t1] = *t3; } } // Set up middle ground for (t1 = 0; t1 < 16; t1++) // Chop up into cell graphics { for (t2 = 0; t2 < 16; t2++) { MiddlegroundCELL[t1 * 16 + t2].u = t2 * 16; MiddlegroundCELL[t1 * 16 + t2].v = t1 * 16; MiddlegroundCELL[t1 * 16 + t2].cba = GetClut(320, 1); MiddlegroundCELL[t1 * 16 + t2].tpage = GetTPage(1, 0, 896, 256); } } MiddlegroundMAP.cellw = MiddlegroundMAP.cellh = 16; MiddlegroundMAP.ncellw = 100; MiddlegroundMAP.ncellh = 100; MiddlegroundMAP.base = &MiddlegroundCELL[0]; MiddlegroundMAP.index = &Middleground[0][0]; MiddlegroundBG.attribute += (1 << 24); MiddlegroundBG.x = MiddlegroundBG.y = 0; MiddlegroundBG.w = SCREEN_WIDTH; MiddlegroundBG.h = SCREEN_HEIGHT; MiddlegroundBG.scrollx = MiddlegroundBG.scrolly = 0; MiddlegroundBG.r = MiddlegroundBG.g = MiddlegroundBG.b = 128; MiddlegroundBG.map = &MiddlegroundMAP; GsInitFixBg16(&MiddlegroundBG, &MiddlegroundBGWork[0]); for (t1 = 0; t1<100; t1++) // Load foreground data from memory { for (t2 = 0; t2<100; t2++) { t3 = (u_char*)(MIDDLE_DAT + t1 * 100 + t2); Middleground[t1][t2] = *t3, 6; if (Middleground[t1][t2] == 0) Middleground[t1][t2] = 0xffff; } } // Set up objects for (t1 = 0; t1<200; t1++) { if (t1 < 40) { Objects[t1].type = WALKER; Objects[t1].x = (300 + rand() % 1000) << 2; Objects[t1].y = 336 << 2; Objects[t1].WALKERHEALTH = 50; Objects[t1].WALKERVELOCITY = rand() % 41 - 20; } else { Objects[t1].type = GEM; Objects[t1].x = ((t1 - 20) * 20 + 250) << 2; Objects[t1].y = (300 + rand() % 10) << 2; Objects[t1].GEMVALUE = rand() % 10 + 10; } } // Set up screen InitialiseScreen(); // set screen info VSync(0); } // *************** // Setup up screen // *************** void InitialiseScreen() { SetVideoMode(MODE_PAL); // define screen as PAL GsInitGraph(SCREEN_WIDTH, SCREEN_HEIGHT, GsOFSGPU, 0, 0); // define screen resolution, whether // interlaced, dithered & colour depth GsDefDispBuff(0, 0, 0, SCREEN_HEIGHT); // define top left corners of // both screen buffers in memory OTable_Header[0].length = OTABLE_LENGTH; // notify OTable headers of OTable OTable_Header[1].length = OTABLE_LENGTH; // array lengths OTable_Header[0].org = OTable_Array[0]; // notify OTable headers of OTable OTable_Header[1].org = OTable_Array[1]; // array memory locations GsClearOt(0, 0, &OTable_Header[0]); // clear out OTable sorting info GsClearOt(0, 0, &OTable_Header[1]); // ready for use (not strictly necessary) }