#include "lib2d.h" // setup up screen for 2d graphics environment void Initialise2DGraphics() { // set output to PAL not NTSC SetVideoMode(MODE_PAL); // set screen resolution as 320x240 GsInitGraph(320, 240, GsOFSGPU, 1, 0); // set top left corners of both buffers in video RAM GsDefDispBuff(0, 0, 0, 240); // ORDERING TABLE INITIALISATION // set Headers to correct length OTable_Header[0].length = ORDERING_TABLE_LENGTH; OTable_Header[1].length = ORDERING_TABLE_LENGTH; // set Headers to point to start of the OTable_Arrays OTable_Header[0].org = OTable_Array[0]; OTable_Header[1].org = OTable_Array[1]; // Just to be on the safe side, clear both ordering tables GsClearOt(0, 0, &OTable_Header[0]); GsClearOt(0, 0, &OTable_Header[1]); // load font into vram and open a text window on screen FntLoad(960, 256); FntOpen(0, 0, 320, 240, 0, 700); } // **** This sets up sprite information, such as x,y, what .TIM data to use etc. etc. void SetSpriteInfo(GsSPRITE *tSprite, u_long tMemAddress, long tX, long tY) { GsIMAGE tTim; u_long tDepth1, tDepth2; // copy tim information into GsIMAGE structure for easy access GsGetTimInfo((u_long *) (tMemAddress+4), &tTim); // calculate the bit depth of texture image and set variables for use // case 0 = 16 colour, 1 = 256 colour, 2 = truecolour switch (tTim.pmode&3) { case 0: {tDepth1=0; tDepth2=4; break;} case 1: {tDepth1=1; tDepth2=2; break;} case 2: {tDepth1=2; tDepth2=1; break;} } // set attribute to specify colour depth of texture image tSprite->attribute = (tDepth1<<24); // specify start position of sprite tSprite->x = tX; tSprite->y = tY; // set width of texture image (modified by bit depth) tSprite->w = tTim.pw * tDepth2; tSprite->h = tTim.ph; // set texture page for texture image tSprite->tpage = GetTPage(tDepth1, 0, tTim.px, tTim.py); // set texuture offset from top left of texture page tSprite->u = tTim.px%64; tSprite->v = tTim.py%256; // set CLUT if texture image is not truecolour if (!(tDepth1==2)) { tSprite->cx = tTim.cx; tSprite->cy = tTim.cy; } // set brightness regulation to normal tSprite->r = tSprite->g = tSprite->b = 128; // set handle to center of texture image tSprite->mx = tTim.pw*tDepth2/2; tSprite->my = tTim.ph/2; // set size and orientation to normal tSprite->scalex = tSprite->scaley = ONE; tSprite->rotate = 0; } // **** draw a gradient coloured filled box on screen void DrawGradBox(long x, long y, long w, long h, u_long priority, long draw, u_char r0, u_char g0, u_char b0, u_char r1, u_char g1, u_char b1, u_char r2, u_char g2, u_char b2, u_char r3, u_char g3, u_char b3) { static GsGLINE tempLine; long tTemp1; u_long tLeftColorR = r0<<20, tLeftColorG = g0<<20, tLeftColorB = b0<<20; u_long tRightColorR = r1<<20, tRightColorG= g1<<20, tRightColorB = b1<<20; long tLeftAddR, tLeftAddG, tLeftAddB; long tRightAddR, tRightAddG, tRightAddB; float tTempWidth; // if the box is to be drawn semitransparently, set the attribute as such if ((draw>-1) && (draw<4)) tempLine.attribute = (1<<30) + (draw<<28); else tempLine.attribute = 0; SetGradLinePos(&tempLine, x, y, x+w, y); tTempWidth = h; tLeftAddR = (((r0 - r2) << 20) / tTempWidth) -1; tLeftAddG = (((g0 - g2) << 20) / tTempWidth) -1; tLeftAddB = (((b0 - b2) << 20) / tTempWidth) -1; tRightAddR = (((r1 - r3) << 20) / tTempWidth) -1; tRightAddG = (((g1 - g3) << 20) / tTempWidth) -1; tRightAddB = (((b1 - b3) << 20) / tTempWidth) -1; for (tTemp1 = 0; tTemp1>20), (short) (tLeftColorG>>20), (short) (tLeftColorB>>20), (short) (tRightColorR>>20), (short) (tRightColorG>>20), (short) (tRightColorB>>20)); DrawGradLine(&tempLine, priority); tempLine.y0++; tempLine.y1++; } } // **** general collision detection routine u_long CheckRectOverlap(RECT *rect1, RECT *rect2) { u_long returnedValue = FALSE; if ((rect1->x+rect1->w) >= rect2->x) if ((rect1->y+rect1->h) >= rect2->y) if (rect1->x <= (rect2->x+rect2->w)) if (rect1->y <= (rect2->y+rect2->h)) returnedValue = TRUE; return returnedValue; }