#include "stdio.h" #include "SpritLib.c" #include "epsilon.h" int jeu(unsigned char map[64][2], SL_Img *voiture) { unsigned int key = 0, score = 0; char voitureX = 61, a = 0, i; for(i=0 ; i<64 ; i++) SL_Horizontal(i, map[(i+a)%64][0] - map[(i+a)%64][1], map[(i+a)%64][0] + map[(i+a)%64][1], BLANC); SL_DrawImg_VRAM(voiture, voitureX, 56); PrintXY(46, 25, (unsigned char*)"Ready?", 1); while(key != KEY_CTRL_EXE) GetKey(&key); while(1) { score++; a = (a+63) % 64; if(IsKeyDown(KEY_CTRL_MENU)) return 0; if(IsKeyDown(KEY_CTRL_LEFT)) voitureX--; if(IsKeyDown(KEY_CTRL_RIGHT)) voitureX++; map[a][0] = map[(a+1)%64][0] + (rand() % 5) - 2; if(map[a][0] < 20) map[a][0] = 21; if(map[a][0] > 107) map[a][0] = 106; map[a][1] = map[(a+1)%64][1] + (rand() % 3) - 1; if(map[a][1] < 9) map[a][1] = 10; if(map[a][1] > 16) map[a][1] = 15; RestoreDisp(1); for(i=0 ; i<64 ; i++) SL_Horizontal(i, map[(i+a)%64][0] - map[(i+a)%64][1], map[(i+a)%64][0] + map[(i+a)%64][1], BLANC); SL_DrawImg_VRAM(voiture, voitureX, 56); Bdisp_PutDisp_DD(); if((voitureX < map[(a+63)%64][0] - map[(a+63)%64][1]) || ((voitureX + 6) > map[(a+61)%64][0] + map[(a+61)%64][1])) { perdu(score); return 1; } } } perdu(int score) { unsigned int key = 0; char affichage[20]; DISPBOX espace = {22, 20, 105, 45}; Bdisp_AreaClr_VRAM(&espace); SL_Horizontal(espace.top + 2, espace.left + 2, espace.right - 3, NOIR); SL_Horizontal(espace.bottom - 3, espace.left + 2, espace.right - 3, NOIR); SL_Horizontal(espace.bottom - 2, espace.left + 3, espace.right - 2, NOIR); SL_Vertical(espace.left + 2, espace.top + 2, espace.bottom - 3, NOIR); SL_Vertical(espace.right - 3, espace.top + 2, espace.bottom - 3, NOIR); SL_Vertical(espace.right - 2, espace.top + 3, espace.bottom - 2, NOIR); PrintMini(32, 25, (unsigned char*)"You had a crash", 0); sprintf(affichage, "Your score : %ld", score); PrintMini(27, 34, affichage, 0); while(key != KEY_CTRL_EXE) GetKey(&key); } void init(unsigned char map[64][2]) { char i; for(i=0 ; i<64 ; i++) { map[i][0] = 64; map[i][1] = 10; SL_Horizontal(i, 0, 127, NOIR); } SaveDisp(1); } int AddIn_main(int isAppli, unsigned short OptionNum) { unsigned char map[64][2]; char image[8][7] = { {3,1,1,1,1,1,3}, {1,1,0,0,0,1,1}, {1,1,0,0,0,1,1}, {3,1,1,1,1,1,3}, {3,1,1,1,1,1,3}, {1,1,0,0,0,1,1}, {1,1,1,1,1,1,1}, {3,1,1,1,1,1,3}, }; SL_Img *voiture = SL_LoadImg((char*)image, 7, 8); srand(RTCReadSecond() + RTCReadMinute() + RTCReadHour()); do { Bdisp_AllClr_VRAM(); init(map); }while(jeu(map, voiture)); SL_FreeImg(voiture); return 1; } #pragma section _BR_Size unsigned long BR_Size; #pragma section #pragma section _TOP int InitializeSystem(int isAppli, unsigned short OptionNum) { return INIT_ADDIN_APPLICATION(isAppli, OptionNum); } #pragma section