#include #include #include #include #include #include #include #include "images.h" #define M_PI 3.14159265358979323846 #define itofix(x) ((x) << 8) #define fixtoi(x) ((x) >> 8) #define fixmul(x, y) ((x)* (y) >> 8) #define fixdiv(x, y) (((x) << 8) / (y)) #define fixsin(x) fixcos((x) - 64) #define K_ESC isKeyPressed(KEY_NSPIRE_ESC) #define K_ENTER isKeyPressed(KEY_NSPIRE_ENTER) #define K_TAB isKeyPressed(KEY_NSPIRE_TAB) #define K_A isKeyPressed(KEY_NSPIRE_A) #define K_7 isKeyPressed(KEY_NSPIRE_7) #define K_9 isKeyPressed(KEY_NSPIRE_9) #define K_8 isKeyPressed(KEY_NSPIRE_8) #define K_5 isKeyPressed(KEY_NSPIRE_5) #define K_4 isKeyPressed(KEY_NSPIRE_4) #define K_6 isKeyPressed(KEY_NSPIRE_6) #define COLOR_BPP 16 #define COLOR_STORAGE_SIZE 2 #define BMPWIDTH 17; #define BMPHEIGHT 12; #define shift_y 8 #define shift_x 8 #define vy_limit 256 #define vx_limit 256 #define maxtrail 20 typedef int Fixed; struct Rect { int x; int y; int h; int w; }; struct Point { int x; int y; }; Fixed fixcos(Fixed angle) { static Fixed cosLUT[] = { 256, 255, 255, 255, 254, 254, 253, 252, 251, 249, 248, 246, 244, 243, 241, 238, 236, 234, 231, 228, 225, 222, 219, 216, 212, 209, 205, 201, 197, 193, 189, 185, 181, 176, 171, 167, 162, 157, 152, 147, 142, 136, 131, 126, 120, 115, 109, 103, 97, 92, 86, 80, 74, 68, 62, 56, 49, 43, 37, 31, 25, 18, 12, 6, 0, -6, -12, -18, -25, -31, -37, -43, -49, -56, -62, -68, -74, -80, -86, -92, -97, -103, -109, -115, -120, -126, -131, -136, -142, -147, -152, -157, -162, -167, -171, -176, -181, -185, -189, -193, -197, -201, -205, -209, -212, -216, -219, -222, -225, -228, -231, -234, -236, -238, -241, -243, -244, -246, -248, -249, -251, -252, -253, -254, -254, -255, -255, -255, -256, -255, -255, -255, -254, -254, -253, -252, -251, -249, -248, -246, -244, -243, -241, -238, -236, -234, -231, -228, -225, -222, -219, -216, -212, -209, -205, -201, -197, -193, -189, -185, -181, -176, -171, -167, -162, -157, -152, -147, -142, -136, -131, -126, -120, -115, -109, -103, -97, -92, -86, -80, -74, -68, -62, -56, -49, -43, -37, -31, -25, -18, -12, -6, 0, 6, 12, 18, 25, 31, 37, 43, 49, 56, 62, 68, 74, 80, 86, 92, 97, 103, 109, 115, 120, 126, 131, 136, 142, 147, 152, 157, 162, 167, 171, 176, 181, 185, 189, 193, 197, 201, 205, 209, 212, 216, 219, 222, 225, 228, 231, 234, 236, 238, 241, 243, 244, 246, 248, 249, 251, 252, 253, 254, 254, 255, 255, 255 }; return cosLUT[angle & 0xff]; } inline void setPixel565(int x, int y, uint16_t c) { if(x>=0 && x<320 && y>=0 && y<240) { if(is_cx) { *((unsigned short*)(SCREEN_BASE_ADDRESS + (x << 1) + (y << 9) + (y << 7))) = c; }else{ unsigned char* p = (unsigned char*)(SCREEN_BASE_ADDRESS + ((x >> 1) + (y << 7) + (y << 5))); char black_and_white = ((c>>11)+((c&0x7E0)>>5)+(c&0x1F))>>3; *p = (x & 1) ? ((*p & 0xF0) | black_and_white) : ((*p & 0x0F) | (black_and_white << 4)); } } } inline void setPixelRGB(int x, int y, int r, int g, int b) { if(x>=0 && x<320 && y>=0 && y<240) { if(is_cx) { *((unsigned short*)(SCREEN_BASE_ADDRESS + (x << 1) + (y << 9) + (y << 7))) = (((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3); }else{ unsigned char* p = (unsigned char*)(SCREEN_BASE_ADDRESS + ((x >> 1) + (y << 7) + (y << 5))); char black_and_white = (r>>6) + (g>>5) + (b>>6); *p = (x & 1) ? ((*p & 0xF0) | black_and_white) : ((*p & 0x0F) | (black_and_white << 4)); } } } void rotate(int x, int y, Fixed ca, Fixed sa, struct Rect* out) { out->x = fixtoi(fixmul(itofix(x), ca)+fixmul(itofix(y), sa)); out->y = fixtoi(fixmul(itofix(x), -sa)+fixmul(itofix(y), ca)); } void custom_rotosprite(unsigned short* source, struct Rect sr, Fixed angle) { struct Rect upleft, upright, downleft, downright; struct Rect fr; Fixed dX = fixcos(angle), dY = fixsin(angle); rotate(-source[0] / 2, -source[1] / 2, dX, dY, &upleft); rotate(source[0] / 2, -source[1] / 2, dX, dY, &upright); rotate(-source[0] / 2, source[1] / 2, dX, dY, &downleft); rotate(source[0] / 2, source[1] / 2, dX, dY, &downright); fr.x = min(min(min(upleft.x, upright.x), downleft.x), downright.x)+sr.x; fr.y = min(min(min(upleft.y, upright.y), downleft.y), downright.y)+sr.y; fr.w = max(max(max(upleft.x, upright.x), downleft.x), downright.x)+sr.x; fr.h = max(max(max(upleft.y, upright.y), downleft.y), downright.y)+sr.y; struct Rect cp; struct Rect lsp; struct Rect cdrp; lsp.x = fixmul(itofix(fr.x-sr.x), dX)+fixmul(itofix(fr.y-sr.y), -dY); lsp.y = fixmul(itofix(fr.x-sr.x), dY)+fixmul(itofix(fr.y-sr.y), dX); for(cp.y = fr.y; cp.y < fr.h; cp.y++) { cdrp.x = lsp.x; cdrp.y = lsp.y; for(cp.x = fr.x; cp.x < fr.w; cp.x++) { if(cp.x>=0 && cp.x<320 && cp.y>=0 && cp.y<240) { if(abs(fixtoi(cdrp.x))320*512) {xt=0;bullets[i].active=1;} if(yt<0) {yt=240*512;bullets[i].active=1;} if(yt>240*512) {yt=0;bullets[i].active=1;} //c'est des moins dans tous les cas (même 320-wb et pas 320+wb) car //xt,yt sont les coordonnées du coin haut gauche, pas du milieu bullets[i].x=xt; bullets[i].y=yt; if(bullets[i].active) { sr.x=xt/512; sr.y=yt/512; custom_rotosprite(Fire, sr, bullets[i].angle); } if((abs((x>>shift_x)-xt/512)<3+8) && (abs((y>>shift_y)-yt/512)<3+6) && (score>0) && (bullets[i].active)) { //les "3+" après les "<" sont la taille des météores sans compter la trail //le reste (8 et 6) représente la moitié de la dimension de Jill dan la direction concernée alive=0; } } for(i=0;i<3;i++) { if((abs((x>>shift_x)-greens[i].x)<11) && (abs((y>>shift_y)-greens[i].y)<9)) { putsprite(greens[i].x,greens[i].y,Green_shadow); EraseCenteredNum(SCREEN_WIDTH/2, 50, score, chiffres); score++; greens[i].x=rand()%320; greens[i].y=rand()%240; } putsprite(greens[i].x,greens[i].y,Green); } DrawCenteredNum(SCREEN_WIDTH/2, 50, score, chiffres); int oldx=x; int oldy=y; int oldvx=vx; unsigned short* oldJill_shadow=Jill_shadow; if(K_7 || K_9) { //accélération vers le haut trailon=1; vy-=6; if(vy<-vy_limit) {vy=-vy_limit;} if(K_7) { //accélération vers la gauche Jill=JillG; Jill_shadow=JillG_shadow; vx=vx-7; if(vx<-vx_limit) {vx=-vx_limit;} } if(K_9) { //accélération vers la droite Jill=JillD; Jill_shadow=JillD_shadow; vx=vx+7; if(vx>vx_limit) {vx=vx_limit;} } }else{ //gravité et frottements trailon=0; if(vy0)+vx; } y+=vy; x+=vx; if(x>>shift_x<(-8)) {x=(320-8)<>shift_x>320-8) {x=-8<>shift_y<(-8)) {y=(240-8)<>shift_y>240-8) {y=-8<>shift_x)-(Jill==JillD?8:-8); trail[currenttrail].y=y>>shift_y; }else{ trail[currenttrail].x=-20; } for(i=0;i>shift_x; sr.y=oldy>>shift_y; custom_rotosprite(oldJill_shadow, sr, -oldvx*32/vx_limit); sr.x=x>>shift_x; sr.y=y>>shift_y; custom_rotosprite(Jill, sr, -vx*32/vx_limit); if(K_TAB) {pause=1;} if(pause) { while(!(K_7||K_9||K_ESC)); pause=0; } if(K_ESC) { keep_playing=0; } if(slp) { sleep(2); //changer en 2 avant de compiler pour calculette, et mettre 3 pour l'emu } } if(getHighscore()