#include "fxcg\display.h" #include "fxcg\keyboard.h" #include "fxcg\rtc.h" #include "fxcg\file.h" #include "keyboard_syscalls.h" #include "string.h" #include "stdint.h" #include "stdlib.h" #include "ctype.h" #include "math.h" #include "CatSprites.h" #include "Font.h" #define PATH "\\\\fls0\\Catylizm.hs" #define abs1(x) (x < 0 ? -x : x) #define max( a, b ) ( ((a) > (b)) ? (a) : (b) ) #define min( a, b ) ( ((a) < (b)) ? (a) : (b) ) #define M_PI 3.14159265358979323846264338327950288419716939932795502884 int round1(double number) { return (number >= 0) ? (int)(number + 0.5) : (int)(number - 0.5); } static const float costbl[360]={1,0.99984769515639,0.9993908270191,0.99862953475457,0.99756405025982,0.99619469809175,0.99452189536827,0.99254615164132,0.99026806874157,0.98768834059514,0.98480775301221,0.98162718344766,0.97814760073381,0.97437006478524,0.970295726276,0.96592582628907,0.96126169593832,0.95630475596304,0.95105651629515,0.94551857559932,0.93969262078591,0.9335804264972,0.92718385456679,0.92050485345244,0.9135454576426,0.90630778703665,0.89879404629917,0.89100652418837,0.88294759285893,0.8746197071394,0.86602540378444,0.85716730070211,0.84804809615643,0.83867056794542,0.82903757255504,0.81915204428899,0.80901699437495,0.79863551004729,0.78801075360672,0.77714596145697,0.76604444311898,0.75470958022277,0.74314482547739,0.73135370161917,0.71933980033865,0.70710678118655,0.694658370459,0.6819983600625,0.66913060635886,0.65605902899051,0.64278760968654,0.62932039104984,0.61566147532566,0.60181502315205,0.58778525229247,0.57357643635105,0.55919290347075,0.54463903501503,0.5299192642332,0.51503807491005,0.5,0.48480962024634,0.46947156278589,0.45399049973955,0.43837114678908,0.4226182617407,0.4067366430758,0.39073112848927,0.37460659341591,0.3583679495453,0.34202014332567,0.32556815445716,0.30901699437495,0.29237170472274,0.275637355817,0.25881904510252,0.24192189559967,0.22495105434386,0.20791169081776,0.19080899537654,0.17364817766693,0.15643446504023,0.13917310096007,0.12186934340515,0.10452846326765,0.087155742747658,0.069756473744125,0.052335956242944,0.034899496702501,0.017452406437283,6.1230317691119e-17,-0.017452406437283,-0.034899496702501,-0.052335956242944,-0.069756473744125,-0.087155742747658,-0.10452846326765,-0.12186934340515,-0.13917310096007,-0.15643446504023,-0.17364817766693,-0.19080899537654,-0.20791169081776,-0.22495105434386,-0.24192189559967,-0.25881904510252,-0.275637355817,-0.29237170472274,-0.30901699437495,-0.32556815445716,-0.34202014332567,-0.3583679495453,-0.37460659341591,-0.39073112848927,-0.4067366430758,-0.4226182617407,-0.43837114678908,-0.45399049973955,-0.46947156278589,-0.48480962024634,-0.5,-0.51503807491005,-0.5299192642332,-0.54463903501503,-0.55919290347075,-0.57357643635105,-0.58778525229247,-0.60181502315205,-0.61566147532566,-0.62932039104984,-0.64278760968654,-0.65605902899051,-0.66913060635886,-0.6819983600625,-0.694658370459,-0.70710678118655,-0.71933980033865,-0.73135370161917,-0.74314482547739,-0.75470958022277,-0.76604444311898,-0.77714596145697,-0.78801075360672,-0.79863551004729,-0.80901699437495,-0.81915204428899,-0.82903757255504,-0.83867056794542,-0.84804809615643,-0.85716730070211,-0.86602540378444,-0.8746197071394,-0.88294759285893,-0.89100652418837,-0.89879404629917,-0.90630778703665,-0.9135454576426,-0.92050485345244,-0.92718385456679,-0.9335804264972,-0.93969262078591,-0.94551857559932,-0.95105651629515,-0.95630475596304,-0.96126169593832,-0.96592582628907,-0.970295726276,-0.97437006478524,-0.97814760073381,-0.98162718344766,-0.98480775301221,-0.98768834059514,-0.99026806874157,-0.99254615164132,-0.99452189536827,-0.99619469809175,-0.99756405025982,-0.99862953475457,-0.9993908270191,-0.99984769515639,-1,-0.99984769515639,-0.9993908270191,-0.99862953475457,-0.99756405025982,-0.99619469809175,-0.99452189536827,-0.99254615164132,-0.99026806874157,-0.98768834059514,-0.98480775301221,-0.98162718344766,-0.97814760073381,-0.97437006478524,-0.970295726276,-0.96592582628907,-0.96126169593832,-0.95630475596304,-0.95105651629515,-0.94551857559932,-0.93969262078591,-0.9335804264972,-0.92718385456679,-0.92050485345244,-0.9135454576426,-0.90630778703665,-0.89879404629917,-0.89100652418837,-0.88294759285893,-0.8746197071394,-0.86602540378444,-0.85716730070211,-0.84804809615643,-0.83867056794542,-0.82903757255504,-0.81915204428899,-0.80901699437495,-0.79863551004729,-0.78801075360672,-0.77714596145697,-0.76604444311898,-0.75470958022277,-0.74314482547739,-0.73135370161917,-0.71933980033865,-0.70710678118655,-0.694658370459,-0.6819983600625,-0.66913060635886,-0.65605902899051,-0.64278760968654,-0.62932039104984,-0.61566147532566,-0.60181502315205,-0.58778525229247,-0.57357643635105,-0.55919290347075,-0.54463903501503,-0.52991926423321,-0.51503807491005,-0.5,-0.48480962024634,-0.46947156278589,-0.45399049973955,-0.43837114678908,-0.4226182617407,-0.4067366430758,-0.39073112848927,-0.37460659341591,-0.3583679495453,-0.34202014332567,-0.32556815445716,-0.30901699437495,-0.29237170472274,-0.275637355817,-0.25881904510252,-0.24192189559967,-0.22495105434387,-0.20791169081776,-0.19080899537655,-0.17364817766693,-0.15643446504023,-0.13917310096006,-0.12186934340515,-0.10452846326765,-0.087155742747658,-0.069756473744126,-0.052335956242944,-0.034899496702502,-0.017452406437283,-1.8369095307336e-16,0.017452406437283,0.034899496702501,0.052335956242944,0.069756473744125,0.087155742747658,0.10452846326765,0.12186934340515,0.13917310096007,0.15643446504023,0.17364817766693,0.19080899537654,0.20791169081776,0.22495105434386,0.24192189559967,0.25881904510252,0.275637355817,0.29237170472274,0.30901699437495,0.32556815445716,0.34202014332567,0.3583679495453,0.37460659341591,0.39073112848927,0.4067366430758,0.4226182617407,0.43837114678908,0.45399049973955,0.46947156278589,0.48480962024634,0.5,0.51503807491005,0.5299192642332,0.54463903501503,0.55919290347075,0.57357643635105,0.58778525229247,0.60181502315205,0.61566147532566,0.62932039104984,0.64278760968654,0.65605902899051,0.66913060635886,0.6819983600625,0.694658370459,0.70710678118655,0.71933980033865,0.73135370161917,0.74314482547739,0.75470958022277,0.76604444311898,0.77714596145697,0.78801075360672,0.79863551004729,0.80901699437495,0.81915204428899,0.82903757255504,0.83867056794542,0.84804809615643,0.85716730070211,0.86602540378444,0.8746197071394,0.88294759285893,0.89100652418837,0.89879404629917,0.90630778703665,0.9135454576426,0.92050485345244,0.92718385456679,0.9335804264972,0.93969262078591,0.94551857559932,0.95105651629515,0.95630475596304,0.96126169593832,0.96592582628907,0.970295726276,0.97437006478524,0.97814760073381,0.98162718344766,0.98480775301221,0.98768834059514,0.99026806874157,0.99254615164132,0.99452189536827,0.99619469809175,0.99756405025982,0.99862953475457,0.9993908270191,0.99984769515639}; static const float sintbl[360]={0,0.017452406437284,0.034899496702501,0.052335956242944,0.069756473744125,0.087155742747658,0.10452846326765,0.12186934340515,0.13917310096007,0.15643446504023,0.17364817766693,0.19080899537654,0.20791169081776,0.22495105434387,0.24192189559967,0.25881904510252,0.275637355817,0.29237170472274,0.30901699437495,0.32556815445716,0.34202014332567,0.3583679495453,0.37460659341591,0.39073112848927,0.4067366430758,0.4226182617407,0.43837114678908,0.45399049973955,0.46947156278589,0.48480962024634,0.5,0.51503807491005,0.5299192642332,0.54463903501503,0.55919290347075,0.57357643635105,0.58778525229247,0.60181502315205,0.61566147532566,0.62932039104984,0.64278760968654,0.65605902899051,0.66913060635886,0.6819983600625,0.694658370459,0.70710678118655,0.71933980033865,0.73135370161917,0.74314482547739,0.75470958022277,0.76604444311898,0.77714596145697,0.78801075360672,0.79863551004729,0.80901699437495,0.81915204428899,0.82903757255504,0.83867056794542,0.84804809615643,0.85716730070211,0.86602540378444,0.8746197071394,0.88294759285893,0.89100652418837,0.89879404629917,0.90630778703665,0.9135454576426,0.92050485345244,0.92718385456679,0.9335804264972,0.93969262078591,0.94551857559932,0.95105651629515,0.95630475596304,0.96126169593832,0.96592582628907,0.970295726276,0.97437006478524,0.97814760073381,0.98162718344766,0.98480775301221,0.98768834059514,0.99026806874157,0.99254615164132,0.99452189536827,0.99619469809175,0.99756405025982,0.99862953475457,0.9993908270191,0.99984769515639,1,0.99984769515639,0.9993908270191,0.99862953475457,0.99756405025982,0.99619469809175,0.99452189536827,0.99254615164132,0.99026806874157,0.98768834059514,0.98480775301221,0.98162718344766,0.97814760073381,0.97437006478524,0.970295726276,0.96592582628907,0.96126169593832,0.95630475596304,0.95105651629515,0.94551857559932,0.93969262078591,0.9335804264972,0.92718385456679,0.92050485345244,0.9135454576426,0.90630778703665,0.89879404629917,0.89100652418837,0.88294759285893,0.8746197071394,0.86602540378444,0.85716730070211,0.84804809615643,0.83867056794542,0.82903757255504,0.81915204428899,0.80901699437495,0.79863551004729,0.78801075360672,0.77714596145697,0.76604444311898,0.75470958022277,0.74314482547739,0.73135370161917,0.71933980033865,0.70710678118655,0.694658370459,0.6819983600625,0.66913060635886,0.65605902899051,0.64278760968654,0.62932039104984,0.61566147532566,0.60181502315205,0.58778525229247,0.57357643635105,0.55919290347075,0.54463903501503,0.5299192642332,0.51503807491005,0.5,0.48480962024634,0.46947156278589,0.45399049973955,0.43837114678908,0.4226182617407,0.4067366430758,0.39073112848927,0.37460659341591,0.3583679495453,0.34202014332567,0.32556815445716,0.30901699437495,0.29237170472274,0.275637355817,0.25881904510252,0.24192189559967,0.22495105434386,0.20791169081776,0.19080899537654,0.17364817766693,0.15643446504023,0.13917310096007,0.12186934340515,0.10452846326765,0.087155742747659,0.069756473744126,0.052335956242944,0.034899496702501,0.017452406437283,1.2246063538224e-16,-0.017452406437283,-0.034899496702501,-0.052335956242944,-0.069756473744125,-0.087155742747658,-0.10452846326765,-0.12186934340515,-0.13917310096007,-0.15643446504023,-0.17364817766693,-0.19080899537654,-0.20791169081776,-0.22495105434386,-0.24192189559967,-0.25881904510252,-0.275637355817,-0.29237170472274,-0.30901699437495,-0.32556815445716,-0.34202014332567,-0.3583679495453,-0.37460659341591,-0.39073112848927,-0.4067366430758,-0.4226182617407,-0.43837114678908,-0.45399049973955,-0.46947156278589,-0.48480962024634,-0.5,-0.51503807491005,-0.5299192642332,-0.54463903501503,-0.55919290347075,-0.57357643635105,-0.58778525229247,-0.60181502315205,-0.61566147532566,-0.62932039104984,-0.64278760968654,-0.65605902899051,-0.66913060635886,-0.6819983600625,-0.694658370459,-0.70710678118655,-0.71933980033865,-0.73135370161917,-0.74314482547739,-0.75470958022277,-0.76604444311898,-0.77714596145697,-0.78801075360672,-0.79863551004729,-0.80901699437495,-0.81915204428899,-0.82903757255504,-0.83867056794542,-0.84804809615643,-0.85716730070211,-0.86602540378444,-0.8746197071394,-0.88294759285893,-0.89100652418837,-0.89879404629917,-0.90630778703665,-0.9135454576426,-0.92050485345244,-0.92718385456679,-0.9335804264972,-0.93969262078591,-0.94551857559932,-0.95105651629515,-0.95630475596304,-0.96126169593832,-0.96592582628907,-0.970295726276,-0.97437006478524,-0.97814760073381,-0.98162718344766,-0.98480775301221,-0.98768834059514,-0.99026806874157,-0.99254615164132,-0.99452189536827,-0.99619469809175,-0.99756405025982,-0.99862953475457,-0.9993908270191,-0.99984769515639,-1,-0.99984769515639,-0.9993908270191,-0.99862953475457,-0.99756405025982,-0.99619469809175,-0.99452189536827,-0.99254615164132,-0.99026806874157,-0.98768834059514,-0.98480775301221,-0.98162718344766,-0.97814760073381,-0.97437006478524,-0.970295726276,-0.96592582628907,-0.96126169593832,-0.95630475596304,-0.95105651629515,-0.94551857559932,-0.93969262078591,-0.9335804264972,-0.92718385456679,-0.92050485345244,-0.9135454576426,-0.90630778703665,-0.89879404629917,-0.89100652418837,-0.88294759285893,-0.8746197071394,-0.86602540378444,-0.85716730070211,-0.84804809615643,-0.83867056794542,-0.82903757255504,-0.81915204428899,-0.80901699437495,-0.79863551004729,-0.78801075360672,-0.77714596145697,-0.76604444311898,-0.75470958022277,-0.74314482547739,-0.73135370161917,-0.71933980033865,-0.70710678118655,-0.694658370459,-0.6819983600625,-0.66913060635886,-0.65605902899051,-0.64278760968654,-0.62932039104984,-0.61566147532566,-0.60181502315205,-0.58778525229247,-0.57357643635105,-0.55919290347075,-0.54463903501503,-0.52991926423321,-0.51503807491005,-0.5,-0.48480962024634,-0.46947156278589,-0.45399049973955,-0.43837114678908,-0.4226182617407,-0.4067366430758,-0.39073112848927,-0.37460659341591,-0.3583679495453,-0.34202014332567,-0.32556815445716,-0.30901699437495,-0.29237170472274,-0.275637355817,-0.25881904510252,-0.24192189559967,-0.22495105434387,-0.20791169081776,-0.19080899537654,-0.17364817766693,-0.15643446504023,-0.13917310096007,-0.12186934340515,-0.10452846326765,-0.087155742747658,-0.069756473744125,-0.052335956242944,-0.034899496702501,-0.017452406437284}; float angleCorrect(float angle) { while(angle<0) { angle+=360.0; } return angle; } float cos1(float angle) { angle=angleCorrect(angle); int ipart=(int)angle; float t1=costbl[ipart%360]; float t2=costbl[(ipart+1)%360]; angle=angle-(float)ipart; return (t2-t1)*angle+t1; } float sin1(float angle) { angle=angleCorrect(angle); int ipart=(int)angle; float t1=sintbl[ipart%360]; float t2=sintbl[(ipart+1)%360]; angle=angle-(float)ipart; return (t2-t1)*angle+t1; } double sqrt1(double number) { const double ACCURACY=0.001; double lower, upper, guess; if (number < 1) { lower = number; upper = 1; } else { lower = 1; upper = number; } while ((upper-lower) > ACCURACY) { guess = (lower + upper)/2; if(guess*guess > number) upper =guess; else lower = guess; } return (lower + upper)/2; } unsigned int random(void); unsigned int srandom(int seed); static unsigned int lastrandom=0x12345678; unsigned int random(void) { return srandom(0); } unsigned int srandom(int seed){ if (seed) lastrandom=seed; lastrandom = ( 0x41C64E6D*lastrandom ) + 0x3039; return ( lastrandom >> 16 ); } long factorial(int n) { int c; long result = 1; for (c = 1; c <= n; c++) result = result * c; return result; } unsigned short getpixel(int x, int y) { unsigned short *VRAM = (unsigned short *)GetVRAMAddress(); return *(VRAM + (y * LCD_WIDTH_PX) + x); } void plot(int x0, int y0, int color){ char* VRAM = (char*)GetVRAMAddress(); VRAM += 2*(y0*LCD_WIDTH_PX + x0); *(VRAM++) = (color&0x0000FF00)>>8; *(VRAM++) = (color&0x000000FF); return; } void fillArea(int x, int y, int width, int height, int color) { //only use lower two bytes of color char* VRAM = (char*)GetVRAMAddress(); VRAM += 2*(LCD_WIDTH_PX*y + x); for(int j=y; j>8; *(VRAM++) = (color&0x000000FF); } VRAM += 2*(LCD_WIDTH_PX-width); } } int PRGM_GetKey(){ unsigned char buffer[12]; PRGM_GetKey_OS( buffer ); return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 ); } const unsigned short* keyboard_register = (unsigned short*)0xA44B0000; unsigned short lastkey[8]; unsigned short holdkey[8]; void keyupdate(void) { memcpy(holdkey, lastkey, sizeof(unsigned short)*8); memcpy(lastkey, keyboard_register, sizeof(unsigned short)*8); } int keydownlast(int basic_keycode) { int row, col, word, bit; row = basic_keycode%10; col = basic_keycode/10-1; word = row>>1; bit = col + 8*(row&1); return (0 != (lastkey[word] & 1<>1; bit = col + 8*(row&1); return (0 != (holdkey[word] & 1<>1; bit = col + ((row&1)<<3); return (0 != (keyboard_register[word] & 1<> 16); y2 = (((i - y) * y_ratio) >> 16); if(in[(y2 * w1) + x2] != maskcolor && i >= 0 && i < 216 && j >= 0 && j < 384) *VRAM++ = in[(y2 * w1) + x2]; else VRAM++; } VRAM += LCD_WIDTH_PX - w2; } } void ScaledSpriteNbitMasked(const unsigned char* data, int x, int y, int width, int height, int w2, int h2, const color_t* palette, color_t maskcolor, unsigned int bitwidth) { color_t* VRAM = (color_t*)GetVRAMAddress(); VRAM += (LCD_WIDTH_PX*y + x); int offset = 0; unsigned char buf; color_t temp[width * height * 2]; for(int j=0; j>(8-bitwidth)); color_t color = palette[this]; temp[(j*width) + i] = color; buf<<=bitwidth; availbits-=bitwidth; } } ScaledSpriteMasked(temp, x, y, width, height, w2, h2, maskcolor); } void PrintCustomFontH(int x, int y, char *Msg, int fontsize){ int i, j, k = 0; char Upper[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char Num[10] = "0123456789"; for(j = 0; j < strlen(Msg); j++){ for(i = 0; i < 26; i++){ if(Msg[j] == Upper[i]){ ScaledSpriteNbitMasked(Alphabet[i], x + k * (7*fontsize), y, 8, 9, 8 * fontsize, 9 * fontsize, font_palette, COLOR_RED, 2); k++; } } for(i = 0; i < 10; i++){ if(Msg[j] == Num[i]){ ScaledSpriteNbitMasked(Numbers[i], x + k * (7*fontsize), y, 8, 9, 8 * fontsize, 9 * fontsize, font_palette, COLOR_RED, 2); k++; } } if(Msg[j] == ':'){ ScaledSpriteNbitMasked(Colon, x + k * (7*fontsize), y, 8, 9, 8 * fontsize, 9 * fontsize, font_palette, COLOR_RED, 2); k++; } if(Msg[j] == '.'){ ScaledSpriteNbitMasked(Period, x + k * (7*fontsize), y, 8, 9, 8 * fontsize, 9 * fontsize, font_palette, COLOR_RED, 2); k++; } if(Msg[j] == ' '){ k++; } } } void PrintCustomFontV(int x, int y, char *Msg, int fontsize){ int i, j, k = 0; char Upper[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char Num[10] = "0123456789"; for(j = 0; j < strlen(Msg); j++){ for(i = 0; i < 26; i++){ if(Msg[j] == Upper[i]){ ScaledSpriteNbitMasked(Alphabet[i], x, y + k * (7*fontsize), 8, 9, 8 * fontsize, 9 * fontsize, font_palette, COLOR_RED, 2); k++; } } for(i = 0; i < 10; i++){ if(Msg[j] == Num[i]){ ScaledSpriteNbitMasked(Numbers[i], x, y + k * (7*fontsize), 8, 9, 8 * fontsize, 9 * fontsize, font_palette, COLOR_RED, 2); k++; } } if(Msg[j] == ':'){ ScaledSpriteNbitMasked(Colon, x, y + k * (7*fontsize), 8, 9, 8 * fontsize, 9 * fontsize, font_palette, COLOR_RED, 2); k++; } if(Msg[j] == '.'){ ScaledSpriteNbitMasked(Period, x, y + k * (7*fontsize), 8, 9, 8 * fontsize, 9 * fontsize, font_palette, COLOR_RED, 2); k++; } if(Msg[j] == ' '){ k++; } } } void drawLine(int x1, int y1, int x2, int y2, int color) { signed char ix; signed char iy; // if x1 == x2 or y1 == y2, then it does not matter what we set here int delta_x = (x2 > x1?(ix = 1, x2 - x1):(ix = -1, x1 - x2)) << 1; int delta_y = (y2 > y1?(iy = 1, y2 - y1):(iy = -1, y1 - y2)) << 1; plot(x1, y1, color); if (delta_x >= delta_y) { int error = delta_y - (delta_x >> 1); // error may go below zero while (x1 != x2) { if (error >= 0) { if (error || (ix > 0)) { y1 += iy; error -= delta_x; } // else do nothing } // else do nothing x1 += ix; error += delta_y; plot(x1, y1, color); } } else { int error = delta_x - (delta_y >> 1); // error may go below zero while (y1 != y2) { if (error >= 0) { if (error || (iy > 0)) { x1 += ix; error -= delta_y; } // else do nothing } // else do nothing y1 += iy; error += delta_x; plot(x1, y1, color); } } } int i, j; int oldTime, time, oneSecond, alternator = 0; int RL = 0; int StarX[15]; int StarY[15]; int StarState[15]; int CatX = 170; int CatY = 146; float FuelBar = 200, HealthBar = 200; int ObjectX[2], ObjectY[2], ObjectW[2], ObjectH[2], rndObject; int Objects[2]; int Coins = 0; char ScoreBuf[10]; int GameOver = 1; int Menu = 1; int Instructions = 0; int GetNumSec(){ return (int)(RTC_GetTicks() / 128); } void ResetVars(){ Coins = 0; FuelBar = 200; HealthBar = 200; for(i = 0; i < 15; i++){ StarX[i] = random() % 384; StarY[i] = random() % 216; StarState[i] = random() % 2; } rndObject = random() % 100; for(i = 0; i < 2; i++){ if(rndObject >= 0 && rndObject < 25){ Objects[i] = 1; //Coin ObjectW[i] = 16; ObjectH[i] = 34; } if(rndObject >= 25 && rndObject < 50){ Objects[i] = 2; //Fuel ObjectW[i] = 28; ObjectH[i] = 20; } if(rndObject >= 50 && rndObject < 90){ Objects[i] = 3; //Asteroid ObjectW[i] = 64; ObjectH[i] = 64; } if(rndObject >= 90 && rndObject < 100){ Objects[i] = 4; //Mouse ObjectW[i] = 54; ObjectH[i] = 42; } ObjectX[i] = (random() % 312) + 36; ObjectY[i] = -500 + (250 * i); } GameOver = 0; Menu = 1; Instructions = 0; } void drawBorder(){ //Draw fuel bar, health bar, and the score fillArea(0, 0, 36, 216, COLOR_GRAY); drawLine(35, 0, 35, 216, COLOR_LIGHTGRAY); drawLine(36, 0, 36, 216, 0x0000); PrintCustomFontV(10, 10, "FUEL", 2); fillArea(11, 71, 12, 134, 0x0000); fillArea(12, 72, 10, (int)(FuelBar*0.66), 0xb723); fillArea(348, 0, 36, 216, COLOR_GRAY); drawLine(349, 0, 349, 216, COLOR_LIGHTGRAY); drawLine(348, 0, 348, 216, 0x0000); PrintCustomFontV(358, 10, "HEALTH", 2); fillArea(359, 100, 12, 106, 0x0000); fillArea(360, 101, 10, (int)(HealthBar*0.52), 0xf800); PrintCustomFontH(38, 198, "SCORE:", 2); itoa(Coins, ScoreBuf); PrintCustomFontH(120, 198, ScoreBuf, 2); } void StarFunctions(){ //Draw stars for(i = 0; i < 15; i++){ if(oneSecond == 1){ alternator = 1 - alternator; StarState[i] = 1 - StarState[i]; } ScaledSpriteMasked(Star[StarState[i]], StarX[i], StarY[i], 3, 3, 6, 6, COLOR_RED); if(FuelBar > 0){ ScaledSpriteMasked(Flame[alternator], CatX + ((RL == 0) ? 2 : 32), CatY + 60, 5, 5, 10, 10, COLOR_RED); StarY[i]+=12; if(keydownlast(KEY_PRGM_LEFT) && keydownhold(KEY_PRGM_LEFT)) { RL = 1; StarX[i]+=4; } else if(keydownlast(KEY_PRGM_RIGHT) && keydownhold(KEY_PRGM_RIGHT)) { RL = 0; StarX[i]-=4; } FuelBar-=.0625; } if(StarY[i] > 216){ StarX[i] = random() % 384; StarY[i] = -6; } } } void ObjectFunctions(){ //Draw objects and their functions for(i = 0; i < 2; i++){ if(Objects[i] != 0){ if(FuelBar > 0){ if(keydownlast(KEY_PRGM_LEFT) && keydownhold(KEY_PRGM_LEFT)) { ObjectX[i]+=4; } else if(keydownlast(KEY_PRGM_RIGHT) && keydownhold(KEY_PRGM_RIGHT)) { ObjectX[i]-=4; } if(ObjectY[i] < 216) ObjectY[i]+=12; } if(ObjectY[i] >= 216){ ObjectY[i] = -500; ObjectX[i] = (random() % 312) + 36; rndObject = random() % 100; if(rndObject >= 0 && rndObject < 15){ Objects[i] = 1; //Coin ObjectW[i] = 16; ObjectH[i] = 34; } if(rndObject >= 15 && rndObject < 50){ Objects[i] = 2; //Fuel ObjectW[i] = 28; ObjectH[i] = 20; } if(rndObject >= 50 && rndObject < 90){ Objects[i] = 3; //Asteroid ObjectW[i] = 64; ObjectH[i] = 64; } if(rndObject >= 90 && rndObject < 100){ Objects[i] = 4; //Mouse ObjectW[i] = 54; ObjectH[i] = 42; } } if ((CatX < ObjectX[i] + ObjectW[i]) && (CatX + 44 > ObjectX[i]) && (CatY < ObjectY[i] + ObjectH[i]) && (70 + CatY > ObjectY[i])) { switch(Objects[i]){ case 1: Coins++; break; case 2: FuelBar += 50; break; case 3: HealthBar -= 50; break; case 4: Coins += 5; break; } ObjectY[i] = -500 + (250 * i); ObjectX[i] = (random() % 312) + 36; rndObject = random() % 100; if(rndObject >= 0 && rndObject < 15){ Objects[i] = 1; //Coin ObjectW[i] = 16; ObjectH[i] = 34; } if(rndObject >= 15 && rndObject < 50){ Objects[i] = 2; //Fuel ObjectW[i] = 28; ObjectH[i] = 20; } if(rndObject >= 50 && rndObject < 90){ Objects[i] = 3; //Asteroid ObjectW[i] = 64; ObjectH[i] = 64; } if(rndObject >= 90 && rndObject < 100){ Objects[i] = 4; //Mouse ObjectW[i] = 54; ObjectH[i] = 42; } } if(Objects[i] == 1){ ScaledSpriteMasked(Coin, ObjectX[i], (ObjectY[i] + (i * 20)), 8, 17, 16, 34, COLOR_RED); } if(Objects[i] == 2){ ScaledSpriteMasked(Fuel, ObjectX[i], (ObjectY[i] + (i * 20)), 14, 10, 28, 20, COLOR_RED); } if(Objects[i] == 3){ ScaledSpriteMasked(Asteroid, ObjectX[i], (ObjectY[i] + (i * 20)), 32, 32, 64, 64, COLOR_RED); } if(Objects[i] == 4){ ScaledSpriteMasked(Mouse[alternator], ObjectX[i], (ObjectY[i] + (i * 20)), 27, 21, 54, 42, COLOR_RED); } } } if(FuelBar > 200) FuelBar = 200; } void MainMenu(){ //Main menu screen int Head1X = 99, Head1Y = 75, Head2X = 250, Head2Y = 75, Option = 0; GameOver = 1; while(Menu){ int key = PRGM_GetKey(); if(key == KEY_PRGM_MENU){ GetKey(&key); } keyupdate(); oldTime = time; time = RTC_GetTicks() / 128; oneSecond = time - oldTime; fillArea(0, 0, 384, 216, 0x080b); for(i = 0; i < 15; i++){ if(oneSecond == 1){ alternator = 1 - alternator; StarState[i] = 1 - StarState[i]; } ScaledSpriteMasked(Star[StarState[i]], StarX[i], StarY[i], 3, 3, 6, 6, COLOR_RED); } if((keydownlast(KEY_PRGM_UP) && !keydownhold(KEY_PRGM_UP)) || (keydownlast(KEY_PRGM_DOWN) && !keydownhold(KEY_PRGM_DOWN))) Option = 1 - Option; if(Option == 0){ Head1X = 99; Head1Y = 75; Head2X = 250; Head2Y = 75; } else if(Option == 1){ Head1X = 37; Head1Y = 102; Head2X = 311; Head2Y = 102; } PrintCustomFontH(18, 0, "CATYLIZM", 6); PrintCustomFontH(136, 84, "START", 3); PrintCustomFontH(74, 111, "HOW TO PLAY", 3); PrintCustomFontH(64, 198, "PRESS MENU TO QUIT", 2); ScaledSpriteMasked(SpaceCatHead[0], Head1X, Head1Y, 17, 17, 34, 34, COLOR_RED); ScaledSpriteMasked(SpaceCatHead[1], Head2X, Head2Y, 17, 17, 34, 34, COLOR_RED); if((keydownlast(KEY_PRGM_SHIFT) && !keydownhold(KEY_PRGM_SHIFT)) || (keydownlast(KEY_PRGM_RETURN) && !keydownhold(KEY_PRGM_RETURN))){ if(Option == 0){ Menu = 0; GameOver = 0; } else if(Option == 1){ Menu = 0; Instructions = 1; } } Bdisp_PutDisp_DD(); Bdisp_AllClr_VRAM(); } } void Instruction(){ //Instruction screen while(Instructions){ int key = PRGM_GetKey(); if(key == KEY_PRGM_MENU){ GetKey(&key); } keyupdate(); oldTime = time; time = RTC_GetTicks() / 128; oneSecond = time - oldTime; fillArea(0, 0, 384, 216, 0x080b); for(i = 0; i < 15; i++){ if(oneSecond == 1){ alternator = 1 - alternator; StarState[i] = 1 - StarState[i]; } ScaledSpriteMasked(Star[StarState[i]], StarX[i], StarY[i], 3, 3, 6, 6, COLOR_RED); } PrintCustomFontH(18, 0, "CATYLIZM", 6); PrintCustomFontH(36, 64, "USE THE LEFT AND RIGHT", 2); PrintCustomFontH(22, 84, "ARROWS TO MOVE SPACE CAT", 2); PrintCustomFontH(1, 104, "CARL THROUGH SPACE. COLLECT", 2); PrintCustomFontH(30, 124, "COINS AND MICE TO SCORE", 2); PrintCustomFontH(2, 144, "POINTS. AVOID ASTEROIDS AND", 2); PrintCustomFontH(46, 164, "DONT RUN OUT OF FUEL.", 2); PrintCustomFontH(123, 184, "GOOD LUCK.", 2); if(keydownlast(KEY_PRGM_EXIT) && !keydownhold(KEY_PRGM_EXIT)){ Instructions = 0; Menu = 1; } Bdisp_PutDisp_DD(); Bdisp_AllClr_VRAM(); } } void Game(){ while(GameOver == 0){ int key = PRGM_GetKey(); if(key == KEY_PRGM_MENU){ GetKey(&key); } keyupdate(); oldTime = time; time = RTC_GetTicks() / 128; oneSecond = time - oldTime; fillArea(0, 0, 384, 216, 0x080b); StarFunctions(); ObjectFunctions(); if(FuelBar <= 0 || HealthBar <= 0) GameOver = 1; ScaledSpriteMasked(SpaceCat[RL], CatX, CatY, 22, 35, 44, 70, COLOR_RED); drawBorder(); Bdisp_PutDisp_DD(); Bdisp_AllClr_VRAM(); } fillArea(0, 0, 384, 216, 0x080b); StarFunctions(); ObjectFunctions(); ScaledSpriteMasked(SpaceCat[RL], CatX, CatY, 22, 35, 44, 70, COLOR_RED); drawBorder(); while(GameOver == 1){ int key = PRGM_GetKey(); if(key == KEY_PRGM_MENU){ GetKey(&key); } keyupdate(); PrintCustomFontH(33, 80, "GAME OVER", 5); PrintCustomFontH(24, 120, "PRESS EXIT FOR MAIN MENU", 2); if(keydownlast(KEY_PRGM_EXIT) && !keydownhold(KEY_PRGM_EXIT)){ ResetVars(); } Bdisp_PutDisp_DD(); } } int main() { Bdisp_EnableColor(1); srandom(RTC_GetTicks()); ResetVars(); while(1) { int key = PRGM_GetKey(); if(key == KEY_PRGM_MENU){ GetKey(&key); } keyupdate(); oldTime = time; time = RTC_GetTicks() / 128; oneSecond = time - oldTime; MainMenu(); Instruction(); if(GameOver == 0) Game(); } return 0; }