Puzzle game

Dependencies:   PokittoLib mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 #include "Pokitto.h"
00003 #include "sens_levs.h"
00004 #include "gfx.h"
00005 
00006 Pokitto::Core game;
00007 
00008 #define OFF_X 2
00009 #define OFF_Y 42
00010 #define LEVWIDTH 18
00011 #define LEVHEIGHT 11
00012 #define SCROLLHEIGHT 112
00013 #define RUMBLEFRAMES 15
00014 #define STEPSIZE 1
00015 #define EXPLODESPRITES 15
00016 #define EXPLODESPEED 5
00017 
00018 byte oldLev[LEVWIDTH * LEVHEIGHT];
00019 byte curLev[LEVWIDTH * LEVHEIGHT];
00020 byte teleportMap[LEVWIDTH * LEVHEIGHT];
00021 byte telArray[32];
00022 char satTime = 0;
00023 int numTiles;
00024 int px,py,ps,pd;
00025 int levelNum=0;
00026 int maxLevels=sizeof(levels)/102;
00027 int tileSize=12;
00028 uint32_t frameNumber=0;
00029 int score=0;
00030 int hiscore=0;
00031 bool stillExploding=0;
00032 int telNum = 0;
00033 byte gameMode;
00034 unsigned int myInt=0;
00035 byte scroller=0;
00036 char musicName[] = "sensitiv.raw";
00037 int lives;
00038 
00039 uint32_t myDelay;
00040 uint32_t tempTime;
00041 
00042 // explosion
00043 uint8_t expX[EXPLODESPRITES], expY[EXPLODESPRITES], expF[EXPLODESPRITES], expU[EXPLODESPRITES];
00044 uint8_t explode = 0;
00045 
00046 void rumbleOn(){
00047     DigitalOut outPin(P0_13);
00048     DigitalOut inPin(P0_11);
00049     inPin=0;
00050     outPin=1;
00051 }
00052 void rumbleOff(){
00053     DigitalOut outPin(P0_13);
00054     DigitalOut inPin(P0_11);
00055     inPin=0;
00056     outPin=0;
00057 }
00058 
00059 /**************************************************************************/
00060 #define HELD 0
00061 #define NEW 1
00062 #define RELEASE 2
00063 byte CompletePad, ExPad, TempPad, myPad;
00064 bool _A[3], _B[3], _C[3], _Up[3], _Down[3], _Left[3], _Right[3];
00065 
00066 DigitalIn _aPin(P1_9);
00067 DigitalIn _bPin(P1_4);
00068 DigitalIn _cPin(P1_10);
00069 DigitalIn _upPin(P1_13);
00070 DigitalIn _downPin(P1_3);
00071 DigitalIn _leftPin(P1_25);
00072 DigitalIn _rightPin(P1_7);
00073 
00074 void UPDATEPAD(int pad, int var) {
00075   _C[pad] = (var >> 1)&1;
00076   _B[pad] = (var >> 2)&1;
00077   _A[pad] = (var >> 3)&1;
00078   _Down[pad] = (var >> 4)&1;
00079   _Left[pad] = (var >> 5)&1;
00080   _Right[pad] = (var >> 6)&1;
00081   _Up[pad] = (var >> 7)&1;
00082 }
00083 
00084 void UpdatePad(int joy_code){
00085   ExPad = CompletePad;
00086   CompletePad = joy_code;
00087   UPDATEPAD(HELD, CompletePad); // held
00088   UPDATEPAD(RELEASE, (ExPad & (~CompletePad))); // released
00089   UPDATEPAD(NEW, (CompletePad & (~ExPad))); // newpress
00090 }
00091 
00092 byte updateButtons(byte var){
00093    var = 0;
00094    if (_cPin) var |= (1<<1);
00095    if (_bPin) var |= (1<<2);
00096    if (_aPin) var |= (1<<3); // P1_9 = A
00097    if (_downPin) var |= (1<<4);
00098    if (_leftPin) var |= (1<<5);
00099    if (_rightPin) var |= (1<<6);
00100    if (_upPin) var |= (1<<7);
00101 
00102    return var;
00103 }
00104 
00105 /**************************************************************************/
00106 
00107 void new2BitTile(int x1, int y1, int wide, int high, int tile, const uint16_t *gfx, int palNumber){
00108 
00109     uint16_t tileBuffer[wide*high];
00110 
00111     uint8_t pix;
00112     uint8_t quartWide=wide/4;
00113     uint8_t pic;
00114 
00115     int palNo = palLookup[palNumber]*4;
00116     for(int y=0; y<high; y++){
00117         for(int x=0; x<quartWide; x++){
00118             pic = gfx[(tile*quartWide*high)+(x+quartWide*y)];
00119             pix = (pic >> 6)&3; tileBuffer[y+high*(  x*4)]=_pal[_miniPal[palNo+pix]];
00120             pix = (pic >> 4)&3; tileBuffer[y+high*(1+x*4)]=_pal[_miniPal[palNo+pix]];
00121             pix = (pic >> 2)&3; tileBuffer[y+high*(2+x*4)]=_pal[_miniPal[palNo+pix]];
00122             pix = pic &3;       tileBuffer[y+high*(3+x*4)]=_pal[_miniPal[palNo+pix]];
00123         }
00124     }
00125 
00126     game.display.directTile(x1, y1, x1+wide, y1+high, tileBuffer);
00127 }
00128 
00129 void new4BitTile(int x1, int y1, int wide, int high, int tile, int transparentColor, const uint8_t *gfx){
00130     uint16_t tileBuffer[wide*high];
00131     int pix1,pix2;
00132     int halfWide=wide/2;
00133     for(int y=0; y<high; y++){
00134         for(int x=0; x<halfWide; x++){
00135             pix1 = gfx[(tile*halfWide*high)+(x+halfWide*y)]>>4;
00136             pix2 = gfx[(tile*halfWide*high)+(x+halfWide*y)]&15;
00137             tileBuffer[y+high*(  x*2)]=_pal[pix1];
00138             tileBuffer[y+high*(1+x*2)]=_pal[pix2];
00139         }
00140     }
00141     game.display.directTile(x1, y1, x1+wide, y1+high, tileBuffer);
00142 }
00143 
00144 
00145 /**************************************************************************/
00146 /**************************************************************************/
00147 
00148 
00149 int RandMinMax(int min, int max){
00150     return rand() % max + min;
00151 }
00152 
00153 void refreshDisplay(){
00154     // place holder to replace a simulator command.
00155 }
00156 
00157 void draw4BitTile(int x1, int y1, int wide, int high, int tile, int transparentColor, const uint8_t *gfx){
00158     int pix1,pix2;
00159     int halfWide=wide/2;
00160     for(int y=0; y<high; y++){
00161         for(int x=0; x<halfWide; x++){
00162             pix1 = gfx[(tile*halfWide*high)+(x+halfWide*y)]>>4;
00163             pix2 = gfx[(tile*halfWide*high)+(x+halfWide*y)]&15;
00164             if(pix1 != transparentColor){game.display.directPixel(x1+(x*2),y1+y,_pal[pix1]);}
00165             if(pix2 != transparentColor){game.display.directPixel(1+x1+(x*2),y1+y,_pal[pix2]);}
00166         }
00167     }
00168 }
00169 
00170 void draw2BitTile(int x1, int y1, int wide, int high, int tile, int transparentColor, const uint8_t *gfx, int palNumber, int palReplace = -1){
00171     uint8_t pix;
00172     uint8_t quartWide=wide/4;
00173     uint8_t pic;
00174 
00175     int palNo = palLookup[palNumber]*4;
00176     for(int y=0; y<high; y++){
00177         for(int x=0; x<quartWide; x++){
00178             pic = gfx[(tile*quartWide*high)+(x+quartWide*y)];
00179             pix = (pic >> 6)&3; if(pix != transparentColor){game.display.directPixel(  x1+(x*4),y1+y,_pal[_miniPal[palNo+pix]]);}
00180             pix = (pic >> 4)&3; if(pix != transparentColor){game.display.directPixel(1+x1+(x*4),y1+y,_pal[_miniPal[palNo+pix]]);}
00181             pix = (pic >> 2)&3; if(pix != transparentColor){game.display.directPixel(2+x1+(x*4),y1+y,_pal[_miniPal[palNo+pix]]);}
00182             pix = pic &3;       if(pix != transparentColor){game.display.directPixel(3+x1+(x*4),y1+y,_pal[_miniPal[palNo+pix]]);}
00183         }
00184     }
00185 }
00186 
00187 
00188 void drawFont(int x1, int y1, int wide, int high, int tile, int transparentColor, const uint8_t *gfx, int palReplace = -1){
00189     uint16_t tileBuffer[(wide+1)*(high+1)];
00190 
00191     uint8_t pix;
00192     uint8_t quartWide=wide/4;
00193     uint8_t pic;
00194 
00195     for(int y=0; y<high; y++){
00196         for(int x=0; x<quartWide; x++){
00197             pic = gfx[(tile*quartWide*high)+(x+quartWide*y)];
00198             pix = (pic >> 6)&3; if(pix != transparentColor){tileBuffer[y+high*(  x*4)]=numbers_pal[pix];}else{tileBuffer[y+high*(  x*4)]=palReplace;}
00199             pix = (pic >> 4)&3; if(pix != transparentColor){tileBuffer[y+high*(1+x*4)]=numbers_pal[pix];}else{tileBuffer[y+high*(1+x*4)]=palReplace;}
00200             pix = (pic >> 2)&3; if(pix != transparentColor){tileBuffer[y+high*(2+x*4)]=numbers_pal[pix];}else{tileBuffer[y+high*(2+x*4)]=palReplace;}
00201             pix = pic &3;       if(pix != transparentColor){tileBuffer[y+high*(3+x*4)]=numbers_pal[pix];}else{tileBuffer[y+high*(3+x*4)]=palReplace;}
00202         }
00203     }
00204 
00205     game.display.directTile(x1, y1, x1+wide, y1+high, tileBuffer);
00206 
00207 }
00208 
00209 // print text
00210 void print(uint16_t x, uint16_t y, const char* text, uint8_t bgCol, signed int repCol=-1){
00211     if(repCol==-1)repCol=bgCol;
00212     for(uint8_t t = 0; t < strlen(text); t++){
00213         uint8_t character = text[t]-32;
00214         drawFont(x, y, 8, 8, character, bgCol, myFont, repCol);
00215         x += 8;
00216     }
00217 }
00218 
00219 
00220 
00221 void loadLevel(int number) {
00222 /*
00223     // store level number in file for testing
00224    FILE *fp;
00225    fp = fopen("test.txt", "w+");
00226    fwrite(&number, sizeof(int),1, fp);
00227    fclose(fp);
00228 */
00229 
00230   numTiles = 0;
00231   satTime = 0;
00232   int numTels = 0;
00233 
00234   int amount = (LEVWIDTH/2)*LEVHEIGHT;
00235 
00236   for (int t = amount-1; t >= 0; t--) {
00237     int s = pgm_read_byte(levels + t + ((amount+3) * number));
00238     curLev[t * 2] = pgm_read_byte(lookUpTile + (s >> 4));
00239     curLev[(t * 2) + 1] = pgm_read_byte(lookUpTile + (s & 15));
00240     s = t * 2;
00241     teleportMap[s] = 0;
00242     teleportMap[s+1] = 0;
00243 
00244     switch (curLev[s]) {
00245       case 1:
00246         numTiles++;
00247         break;
00248       case 2:
00249         numTiles += 2;
00250         break;
00251       case 4:
00252         curLev[s + 1] = 5;
00253         curLev[s + LEVWIDTH] = 6;
00254         curLev[s + LEVWIDTH+1] = 7;
00255         break;
00256       case 8:
00257         curLev[s + 1] = 9;
00258         break;
00259       case 10:
00260         curLev[s + 1] = 11;
00261         break;
00262       case 12:
00263         curLev[s + LEVWIDTH] = 13;
00264         break;
00265     }
00266 
00267     s = (t * 2) + 1;
00268     switch (curLev[s]) {
00269       case 1:
00270         numTiles++;
00271         break;
00272       case 2:
00273         numTiles += 2;
00274         break;
00275       case 4:
00276         curLev[s + 1] = 5;
00277         curLev[s + LEVWIDTH] = 6;
00278         curLev[s + LEVWIDTH+1] = 7;
00279         break;
00280       case 8:
00281         curLev[s + 1] = 9;
00282         break;
00283       case 10:
00284         curLev[s + 1] = 11;
00285         break;
00286       case 12:
00287         curLev[s + LEVWIDTH] = 13;
00288         break;
00289     }
00290 
00291   }
00292 
00293 
00294   px = pgm_read_byte(levels + amount + ((amount+3) * number))*tileSize;
00295   py = pgm_read_byte(levels + amount+1 + ((amount+3) * number))*tileSize;
00296   int telNumber = pgm_read_byte(levels + amount+2 + ((amount+3) * number));
00297   ps = 0; pd = 0;
00298   satTime = 0;
00299 
00300   for(int t=0; t<31; t++){
00301     telArray[t] = pgm_read_byte(telPath + t + (telNumber*32));
00302   }
00303 
00304     // teleport locations
00305     numTels=0;
00306     for (int y = 0; y <LEVHEIGHT; y++) {
00307       for (int x = 0; x <LEVWIDTH ; x++) {
00308         int tn = (y * LEVWIDTH) + x;
00309         if(curLev[tn]==16){
00310             teleportMap[tn] = numTels;
00311             numTels++;
00312         }
00313       }
00314     }
00315 
00316 
00317   // draw part of the screen here
00318   // bad practice I know, but so what!
00319 
00320     for(byte t=0; t<LEVWIDTH * LEVHEIGHT; t++){
00321         oldLev[t] = 255;
00322     }
00323 
00324     for (int x = LEVWIDTH-1; x >= 0 ; x--) {
00325         new2BitTile(OFF_X+x*tileSize, 42, tileSize, tileSize, 0, gbTiles, 0);
00326     }
00327 
00328     game.display.directRectangle(OFF_X,0,218,40,_pal[10]);
00329     game.display.directRectangle(OFF_X,0,218,0,_pal[4]);
00330     game.display.directRectangle(OFF_X,1,218,1,_pal[10]);
00331     game.display.directRectangle(OFF_X,2,218,2,_pal[15]);
00332     game.display.directRectangle(OFF_X,3,218,3,_pal[15]);
00333     game.display.directRectangle(OFF_X,4,218,4,_pal[10]);
00334     game.display.directRectangle(OFF_X,5,218,5,_pal[4]);
00335     game.display.directRectangle(OFF_X,36,218,36,_pal[4]);
00336     game.display.directRectangle(OFF_X,37,218,37,_pal[10]);
00337     game.display.directRectangle(OFF_X,38,218,38,_pal[15]);
00338     game.display.directRectangle(OFF_X,39,218,39,_pal[15]);
00339     game.display.directRectangle(OFF_X,40,218,40,_pal[10]);
00340     game.display.directRectangle(OFF_X,41,218,41,_pal[4]);
00341 
00342 
00343     // pause if any buttons held
00344     while(_Up[HELD] || _Down[HELD] || _Left[HELD] || _Right[HELD] || _A[HELD] || _B[HELD] || _C[HELD]){
00345       myPad = updateButtons(myPad);
00346       UpdatePad(myPad);
00347     }
00348 
00349 
00350 }
00351 
00352 void renderLevel(bool drawPlayer = 1, bool fullLevel=0){
00353 
00354     signed int xStart=(px / tileSize)+4;
00355     signed int yStart=(py / tileSize)+4;
00356     signed int xEnd=(px / tileSize)-4;
00357     signed int yEnd=(py / tileSize)-4;
00358     if(xEnd<0){xStart+=-xEnd; xEnd=0;}
00359     if(yEnd<0){yStart+=-yEnd; yEnd=0;}
00360     if(xStart>LEVWIDTH-1){xStart=LEVWIDTH-1; xEnd=xStart-9;}
00361     if(yStart>LEVHEIGHT-1){yStart=LEVHEIGHT-1; yEnd=yStart-9;}
00362 
00363 //  if(fullLevel){
00364         xStart=LEVWIDTH-1;
00365         yStart=LEVHEIGHT-1;
00366         xEnd=0;
00367         yEnd=1;
00368 //  }
00369 
00370 
00371 //        oldLev[t] = curLev[t];
00372 
00373 
00374  //   int transp=-1;
00375     for (int y = yStart; y >= yEnd; y--) {
00376       for (int x = xStart; x >= xEnd; x--) {
00377         int tn = (y * LEVWIDTH) + x;
00378             if(oldLev[tn] != curLev[tn]){
00379                 oldLev[tn] = curLev[tn];
00380                 if(curLev[tn]==0){
00381                     // water tile with shaddow
00382                     uint8_t tile = 0;
00383                     if(y>0){
00384                         if(curLev[((y-1) * LEVWIDTH) + (x)]){ tile += 1; }
00385                         if(x>0){if(curLev[((y-1) * LEVWIDTH) + (x-1)]){ tile += 2; }}
00386                     }
00387                     if(x>0){if(curLev[((y) * LEVWIDTH) + (x-1)]){ tile += 4; }}
00388                     new2BitTile(OFF_X+x*tileSize, OFF_Y+y*tileSize, tileSize, tileSize, shaddow[tile], gbTiles, shaddow[tile]);
00389                 }else{
00390                     // all other tiles
00391                     new2BitTile(OFF_X+x*tileSize, OFF_Y+y*tileSize, tileSize, tileSize, curLev[tn], gbTiles, curLev[tn]);
00392                 }
00393             }
00394       }
00395 
00396 
00397     }
00398 
00399         // explosions
00400         stillExploding=0;
00401         for (int t = 0; t < EXPLODESPRITES; t++) {
00402           if (expU[t] == 1) {
00403             oldLev[expX[t] + LEVWIDTH * expY[t]] = 255;
00404 
00405             stillExploding=1;
00406             if(expF[t]<=1){
00407                 new2BitTile(OFF_X+(expX[t]*tileSize), OFF_Y+expY[t]*tileSize, tileSize, tileSize, 1, gbTiles, 1);
00408             }
00409             draw4BitTile(OFF_X+(expX[t]*tileSize), OFF_Y+expY[t]*tileSize, tileSize, tileSize, expF[t], 8, explode_tiles);
00410             if (frameNumber % EXPLODESPEED == 0) {
00411               expF[t]++;
00412               if (expF[t] == 8) {
00413                 expU[t] = 0;
00414               }
00415             }
00416           }
00417         }
00418 
00419         // player sprite
00420         if(drawPlayer){
00421             uint16_t tileBuffer[10];
00422             for(byte y=0; y<8; y++){
00423                 int offX = ball[y][0];
00424                 int wide = ball[y][1];
00425                 for(byte x=0; x<wide; x++){
00426                     tileBuffer[x]=_pal[ball[y][x+2]];
00427                 }
00428                 game.display.directTile(OFF_X+px+offX+2, OFF_Y+py+y+2, OFF_X+px+wide+offX+2, OFF_Y+py+3+y , tileBuffer);
00429             }// y
00430         }//drawplayer
00431 
00432 
00433     print(8, 14, "SCORE  LEV LIVES  HISCORE",0,_pal[10]);
00434     char text[] = "      ";
00435     sprintf(text, "%05d",score);
00436     print(8, 24, text,0,_pal[10]);
00437     sprintf(text, "%03d",levelNum+1);
00438     print(64, 24, text,0,_pal[10]);
00439     sprintf(text, "%02d",lives);
00440     print(104, 24, text,0,_pal[10]);
00441     sprintf(text, "%05d",hiscore);
00442     print(160, 24, text,0,_pal[10]);
00443 
00444 }
00445 
00446 void explodeHere(){
00447     for (int t = 0; t < EXPLODESPRITES; t++) {
00448         if (expU[t] == 0) {
00449             expX[t] = px / tileSize;
00450             expY[t] = py / tileSize;
00451             expF[t] = 0;
00452             expU[t] = 1;
00453             score++;
00454             break;
00455         }
00456     }
00457 }
00458 
00459 void checkTile(int x, int y) {
00460   int t = curLev[x + LEVWIDTH * y];
00461   switch (t) {
00462     case 1:
00463       curLev[x + LEVWIDTH * y] = 0;
00464       oldLev[x + LEVWIDTH * y] = 255;
00465       oldLev[(x+1) + LEVWIDTH * y] = 255;
00466       oldLev[(x+1) + LEVWIDTH * (y+1)] = 255;
00467       oldLev[x + LEVWIDTH * (y+1)] = 255;
00468       numTiles--;
00469       explodeHere();
00470       break;
00471     case 2:
00472       curLev[x + LEVWIDTH * y] = 1;
00473       numTiles--;
00474       score++;
00475       break;
00476   }
00477   if(score > 9999) {
00478     score = 9999;
00479   }
00480   if(score > hiscore) {
00481     hiscore = score;
00482   }
00483 }
00484 
00485 
00486 void movePlayer() {
00487     char x = px/tileSize;
00488     char y = py/tileSize;
00489       oldLev[(x-1) + LEVWIDTH * y] = 255;
00490       oldLev[x + LEVWIDTH * y] = 255;
00491       oldLev[(x+1) + LEVWIDTH * y] = 255;
00492       oldLev[x + LEVWIDTH * (y+1)] = 255;
00493 
00494   if (ps == 0) { // not moving
00495     // sneeky exit check
00496     if (curLev[(px / tileSize) + LEVWIDTH * (py / tileSize)] == 10 || curLev[(px / tileSize) + LEVWIDTH * (py / tileSize)] == 11) {
00497       if (numTiles == 0) {
00498         levelNum++;
00499         if (levelNum >= maxLevels) {
00500           levelNum = 0;
00501         }
00502         // make sure explosions have finished :-)
00503         for (int t = 0; t < EXPLODESPRITES; t++){expU[t] = 0;}
00504         renderLevel(); refreshDisplay();
00505         loadLevel(levelNum);
00506         renderLevel(0,1);
00507       }
00508     }
00509     // sneeky water check
00510     int p = curLev[(px / tileSize) + LEVWIDTH * (py / tileSize)];
00511     if (p == 0 || (p>=24 && p<=32)) {
00512       lives--;
00513       rumbleOn();
00514       if (lives >= 0) {
00515         explodeHere();
00516         // make sure explosions have finished :-)
00517         for(frameNumber=0; frameNumber<30; frameNumber++){
00518             if(frameNumber>=RUMBLEFRAMES){rumbleOff();}
00519             renderLevel(0); // 0 to hide player
00520             refreshDisplay();
00521         }
00522         loadLevel(levelNum);
00523         renderLevel(0,1);
00524       } else {
00525         explodeHere();
00526         // make sure explosions have finished :-)
00527         for(frameNumber=0; frameNumber<30; frameNumber++){
00528             if(frameNumber>=RUMBLEFRAMES){rumbleOff();}
00529             renderLevel(0); // 0 to hide player
00530             refreshDisplay();
00531         }
00532         gameMode = 0; // titlescreen
00533       }
00534     }
00535 
00536 
00537     pd = 0;
00538 //    if (!_B[HELD]) {
00539       if (_Up[HELD]) {
00540         if (curLev[(px / tileSize) + LEVWIDTH * (py / tileSize)] != 14 && curLev[(px / tileSize) + LEVWIDTH * ((py-tileSize) / tileSize)] != 14) {
00541           pd = 1;
00542           checkTile(px / tileSize, py / tileSize);
00543         }
00544       }
00545       if (_Down[HELD]) {
00546         if (curLev[(px / tileSize) + LEVWIDTH * (py / tileSize)] != 14 && curLev[(px / tileSize) + LEVWIDTH * (py / tileSize)] != 14) {
00547           pd = 2;
00548           checkTile(px / tileSize, py / tileSize);
00549         }
00550       }
00551       if (_Left[HELD]) {
00552         if (curLev[(px / tileSize) + LEVWIDTH * (py / tileSize)] != 15 && curLev[((px-tileSize) / tileSize) + LEVWIDTH * (py / tileSize)] != 15) {
00553           pd = 3;
00554           checkTile(px / tileSize, py / tileSize);
00555         }
00556       }
00557       if (_Right[HELD]) {
00558         if (curLev[(px / tileSize) + LEVWIDTH * (py / tileSize)] != 15 && curLev[((px+tileSize) / tileSize) + LEVWIDTH * (py / tileSize)] != 15) {
00559           pd = 4;
00560           checkTile(px / tileSize, py / tileSize);
00561         }
00562       }
00563       if (_A[NEW]) {
00564         if (curLev[(px / tileSize) + LEVWIDTH * (py / tileSize)] == 16) { // teleport
00565           int t = (px / tileSize) + LEVWIDTH * (py / tileSize);
00566           telNum = teleportMap[t];
00567           px = (telArray[telNum]%LEVWIDTH)*tileSize;
00568           py = (telArray[telNum]/LEVWIDTH)*tileSize;
00569           renderLevel(1,1);
00570         }
00571       }
00572 
00573   }
00574 
00575   switch (pd) {
00576     case 0:
00577       break;
00578     case 1:
00579       py-=STEPSIZE;
00580       ps+=STEPSIZE;
00581       break;
00582     case 2:
00583       py+=STEPSIZE;
00584       ps+=STEPSIZE;
00585       break;
00586     case 3:
00587       px-=STEPSIZE;
00588       ps+=STEPSIZE;
00589       break;
00590     case 4:
00591       px+=STEPSIZE;
00592       ps+=STEPSIZE;
00593       break;
00594   }
00595   if (ps == tileSize) {
00596     ps = 0; pd = 0;
00597     satTime = 0;
00598   }
00599 
00600 }
00601 
00602 void drawTitleScreen(){
00603     game.display.directRectangle(0,0,220,176,_pal[0]); // clear the screen
00604     draw4BitTile(4, 41, 212, 23, 0, -1, title);
00605 
00606     print(40, 80, "Remade for Pokitto",0,_pal[0]);
00607     print(40, 96, "    By Spinal",0,_pal[0]);
00608 
00609     print(8, 136, "    Original on C64 by",0,_pal[0]);
00610     print(8, 152, "   Oliva Kirwa (C) 1990",0,_pal[0]);
00611 
00612     for(int x=0; x<220; x++){
00613         game.display.directPixel(x,SCROLLHEIGHT,_pal[4]);
00614         game.display.directPixel(x,SCROLLHEIGHT+1,_pal[10]);
00615         game.display.directPixel(x,SCROLLHEIGHT+2,_pal[15]);
00616         game.display.directPixel(x,SCROLLHEIGHT+11,_pal[15]);
00617         game.display.directPixel(x,SCROLLHEIGHT+12,_pal[10]);
00618         game.display.directPixel(x,SCROLLHEIGHT+13,_pal[4]);
00619     }
00620 
00621     gameMode=1;
00622 }
00623 
00624 void titleScreen(){
00625     char text1[34];
00626     memcpy(text1, &text[myInt],33);
00627     text1[32]=0;
00628     //titleprint(-scroller, 6 , text1);
00629     print(-scroller, SCROLLHEIGHT+3, text1,0,_pal[14]);
00630     if(frameNumber%3==0){
00631         scroller++;
00632         if(scroller==8){
00633         scroller=0;
00634         myInt++;
00635         if(myInt==strlen(text)){myInt=0;}
00636         }
00637     }
00638 
00639     if(_A[NEW]){
00640         lives = 5;
00641         score = 0;
00642         levelNum = 0;
00643         gameMode = 10;
00644         game.display.directRectangle(0,0,220,176,0x0000); // clear the screen
00645     }
00646 
00647 }
00648 
00649 void playLevel(){
00650 
00651     movePlayer();
00652 
00653     // sit still too long at your peril!
00654     if (pd == 0) {
00655         satTime++;
00656         int t=curLev[(px / tileSize) + LEVWIDTH * (py / tileSize)];
00657         char satCount = 16;
00658         if(t==2) satCount = 8;
00659 
00660         if(satTime == satCount) {
00661             checkTile(px / tileSize, py / tileSize);
00662             satTime = 0;
00663         }
00664     }
00665 
00666     renderLevel();
00667 
00668 }
00669 
00670 
00671 int main(){
00672     rumbleOff(); // just in case
00673 
00674     game.begin();
00675     game.display.width = 220; // full size
00676     game.display.height = 174;
00677 
00678     game.sound.ampEnable(true);
00679     game.sound.playMusicStream(musicName);
00680 
00681     gameMode = 0; // titleScreen
00682     tempTime = game.getTime();
00683 
00684     while (game.isRunning()) {
00685 
00686           // if it is time to update the screen
00687  //       if (game.update(true)){
00688 
00689             game.sound.updateStream();
00690 
00691             myPad = updateButtons(myPad);
00692             UpdatePad(myPad);
00693 
00694             frameNumber++;
00695             char oldMode = gameMode;
00696             switch(gameMode){
00697                 case 0:
00698                     drawTitleScreen();
00699                     break;
00700                 case 1:
00701                     levelNum = 0;
00702                     myDelay = 10;
00703                     titleScreen();
00704                     break;
00705                 case 10:
00706                     // start new game.
00707                     loadLevel(levelNum);
00708                     renderLevel(0,1);
00709                     gameMode = 20;
00710                     break;
00711                 case 20:
00712                     // play levels
00713                     myDelay = 30;
00714                     playLevel();
00715                     break;
00716             }
00717 
00718         // timing loop
00719         while(game.getTime()-tempTime < myDelay){
00720             refreshDisplay();
00721         };
00722         tempTime = game.getTime();
00723 //  } // update
00724   }
00725     return 1;
00726 }