From 81cb89b3ca30a675287566ddeb57c4a169441012 Mon Sep 17 00:00:00 2001 From: solosky Date: Wed, 20 Nov 2024 10:37:56 +0800 Subject: [PATCH] add exit for games --- .../game/port/tiny_arkanoid/tiny_arkanoid.c | 769 ++++++++----- .../game/port/tiny_invaders/tiny_invaders.c | 1009 +++++++++-------- .../src/app/game/port/tiny_tris/tiny_tris.c | 9 + 3 files changed, 1016 insertions(+), 771 deletions(-) diff --git a/fw/application/src/app/game/port/tiny_arkanoid/tiny_arkanoid.c b/fw/application/src/app/game/port/tiny_arkanoid/tiny_arkanoid.c index b251b858..a95da769 100644 --- a/fw/application/src/app/game/port/tiny_arkanoid/tiny_arkanoid.c +++ b/fw/application/src/app/game/port/tiny_arkanoid/tiny_arkanoid.c @@ -39,7 +39,7 @@ uint8_t CheckLevelEnded(GROUPE *VAR); void UpdateBall(GROUPE *VAR); void RecupeBALLPosForSIM(GROUPE *VAR); void TestMoveBALL(GROUPE *VAR); -void SimulMove(uint8_t Sim,GROUPE *VAR); +void SimulMove(uint8_t Sim, GROUPE *VAR); uint8_t CheckCollisionBall(GROUPE *VAR); uint8_t CheckCollisionWithBLOCK(GROUPE *VAR); void RecupePositionOnGrid(GROUPE *VAR); @@ -47,16 +47,16 @@ uint8_t RecupeXPositionOnGrid(GROUPE *VAR); uint8_t RecupeYPositionOnGrid(GROUPE *VAR); uint8_t CheckCollisionWithTRACKBAR(GROUPE *VAR); void WriteBallMove(GROUPE *VAR); -static void Tiny_Flip(uint8_t render0_picture1,GROUPE *VAR); -uint8_t PannelLevel(uint8_t X,uint8_t Y,GROUPE *VAR); -uint8_t Block(uint8_t X,uint8_t Y,GROUPE *VAR); +static void Tiny_Flip(uint8_t render0_picture1, GROUPE *VAR); +uint8_t PannelLevel(uint8_t X, uint8_t Y, GROUPE *VAR); +uint8_t Block(uint8_t X, uint8_t Y, GROUPE *VAR); uint8_t RecupeDecalageY(uint8_t Valeur); -uint8_t Ball(uint8_t X,uint8_t Y,GROUPE *VAR); -static uint8_t SplitSpriteDecalageY(uint8_t decalage,uint8_t Input,uint8_t UPorDOWN); -uint8_t TrackBar(uint8_t X,uint8_t Y,GROUPE *VAR); -uint8_t PannelLive(uint8_t X,uint8_t Y,GROUPE *VAR); -static uint8_t background(uint8_t X,uint8_t Y); -void LoadLevel(uint8_t Level,GROUPE *VAR); +uint8_t Ball(uint8_t X, uint8_t Y, GROUPE *VAR); +static uint8_t SplitSpriteDecalageY(uint8_t decalage, uint8_t Input, uint8_t UPorDOWN); +uint8_t TrackBar(uint8_t X, uint8_t Y, GROUPE *VAR); +uint8_t PannelLive(uint8_t X, uint8_t Y, GROUPE *VAR); +static uint8_t background(uint8_t X, uint8_t Y); +void LoadLevel(uint8_t Level, GROUPE *VAR); void ResetVar(GROUPE *VAR); void ResetBall(GROUPE *VAR); @@ -64,359 +64,504 @@ void ResetBall(GROUPE *VAR); // Main Function // =================================================================================== int tiny_arkanoid_run(void) { -// Setup - JOY_init(); - -// Loop - while(1) { - GROUPE VARIABLE; - NEWGAME: - Tiny_Flip(1, &VARIABLE); - while(!JOY_act_pressed()){ - JOY_idle(); - //JOY_SLOWDOWN(); - } - RsVarNewGame(&VARIABLE); - Tiny_Flip(2,&VARIABLE); - PLAYMUSIC(); - LoadLevel(VARIABLE.LEVEL - 1, &VARIABLE); - goto ONE; - NEXTLEVEL: - JOY_sound(60,100); - JOY_sound(80,100); - JOY_sound(100,100); - JOY_sound(120,100); - JOY_sound(140,100); - if(VARIABLE.LEVELSPEED>8) VARIABLE.LEVELSPEED=VARIABLE.LEVELSPEED - 2; - Tiny_Flip(2, &VARIABLE); - JOY_DLY_ms(400); - ResetVar(&VARIABLE); - VARIABLE.LEVEL++; - goto ONE; - RESTARTLEVEL: - JOY_sound(200,100); - JOY_sound(150,100); - JOY_sound(100,100); - JOY_sound(50,100); - if(VARIABLE.live > 0) VARIABLE.live--; - else goto NEWGAME; - ONE: - ResetBall(&VARIABLE); - while(1) { - if(VARIABLE.Frame % 8 == 0) { - if(JOY_left_pressed()) { - if(VARIABLE.TrackBaryDecal < 7) { - if(VARIABLE.TrackBaryDecal + (VARIABLE.TrackBary * 8 ) < 44) { - VARIABLE.TrackBaryDecal++; + // Setup + JOY_init(); + + // Loop + while (1) { + GROUPE VARIABLE; + NEWGAME: + Tiny_Flip(1, &VARIABLE); + while (!JOY_act_pressed()) { + JOY_idle(); + // JOY_SLOWDOWN(); + if (JOY_exit()) { + goto EXIT; } - } - else { - VARIABLE.TrackBaryDecal = 0; - VARIABLE.TrackBary++; - } } - if(JOY_right_pressed()) { - if(VARIABLE.TrackBaryDecal > 0) { - if(VARIABLE.TrackBaryDecal + (VARIABLE.TrackBary * 8) > 4) { - VARIABLE.TrackBaryDecal--; + RsVarNewGame(&VARIABLE); + Tiny_Flip(2, &VARIABLE); + PLAYMUSIC(); + LoadLevel(VARIABLE.LEVEL - 1, &VARIABLE); + goto ONE; + NEXTLEVEL: + JOY_sound(60, 100); + JOY_sound(80, 100); + JOY_sound(100, 100); + JOY_sound(120, 100); + JOY_sound(140, 100); + if (VARIABLE.LEVELSPEED > 8) VARIABLE.LEVELSPEED = VARIABLE.LEVELSPEED - 2; + Tiny_Flip(2, &VARIABLE); + JOY_DLY_ms(400); + ResetVar(&VARIABLE); + VARIABLE.LEVEL++; + goto ONE; + RESTARTLEVEL: + JOY_sound(200, 100); + JOY_sound(150, 100); + JOY_sound(100, 100); + JOY_sound(50, 100); + if (VARIABLE.live > 0) + VARIABLE.live--; + else + goto NEWGAME; + ONE: + ResetBall(&VARIABLE); + while (1) { + if (VARIABLE.Frame % 8 == 0) { + if (JOY_left_pressed()) { + if (VARIABLE.TrackBaryDecal < 7) { + if (VARIABLE.TrackBaryDecal + (VARIABLE.TrackBary * 8) < 44) { + VARIABLE.TrackBaryDecal++; + } + } else { + VARIABLE.TrackBaryDecal = 0; + VARIABLE.TrackBary++; + } + } + if (JOY_right_pressed()) { + if (VARIABLE.TrackBaryDecal > 0) { + if (VARIABLE.TrackBaryDecal + (VARIABLE.TrackBary * 8) > 4) { + VARIABLE.TrackBaryDecal--; + } + } else { + VARIABLE.TrackBaryDecal = 7; + VARIABLE.TrackBary--; + } + } + if ((VARIABLE.launch == 0) && (JOY_act_pressed())) VARIABLE.launch = 1; + if (VARIABLE.launch == 0) { + VARIABLE.Ballypos = ((VARIABLE.TrackBary * 8) + VARIABLE.TrackBaryDecal) + 10; + VARIABLE.SIMBallypos = VARIABLE.Ballypos; + } + } + if ((VARIABLE.Frame % VARIABLE.LEVELSPEED == 0)) UpdateBall(&VARIABLE); + if (VARIABLE.Frame % 32 == 0) Tiny_Flip(0, &VARIABLE); + if (VARIABLE.Frame == 48) { + if (VARIABLE.ANIMREFLECT < 3) VARIABLE.ANIMREFLECT++; + if (BallMissing(&VARIABLE)) goto RESTARTLEVEL; + if (CheckLevelEnded(&VARIABLE)) goto NEXTLEVEL; } - } - else { - VARIABLE.TrackBaryDecal = 7; - VARIABLE.TrackBary--; - } + if (VARIABLE.Frame < 64) + VARIABLE.Frame++; + else + VARIABLE.Frame = 1; + JOY_idle(); + if (JOY_exit()) { + goto EXIT; + } + // JOY_SLOWDOWN(); + DLY_ms(1); } - if((VARIABLE.launch == 0) && (JOY_act_pressed())) VARIABLE.launch = 1; - if(VARIABLE.launch == 0) { - VARIABLE.Ballypos = ((VARIABLE.TrackBary * 8) + VARIABLE.TrackBaryDecal) + 10; - VARIABLE.SIMBallypos = VARIABLE.Ballypos; + + JOY_idle(); + if (JOY_exit()) { + goto EXIT; } - } - if((VARIABLE.Frame%VARIABLE.LEVELSPEED == 0)) UpdateBall(&VARIABLE); - if(VARIABLE.Frame % 32 == 0) Tiny_Flip(0, &VARIABLE); - if(VARIABLE.Frame == 48) { - if(VARIABLE.ANIMREFLECT < 3) VARIABLE.ANIMREFLECT++; - if(BallMissing(&VARIABLE)) goto RESTARTLEVEL; - if(CheckLevelEnded(&VARIABLE)) goto NEXTLEVEL; - } - if(VARIABLE.Frame < 64) VARIABLE.Frame++; - else VARIABLE.Frame = 1; - JOY_idle(); - //JOY_SLOWDOWN(); - DLY_ms(1); } - JOY_idle(); - } +EXIT: + return 0; } // =================================================================================== // Functions // =================================================================================== -void RsVarNewGame(GROUPE *VAR){ -VAR->LEVELSPEED=16; -VAR->LEVEL=1; -VAR->live=3; -VAR->ANIMREFLECT=0; -LoadLevel(0,VAR); +void RsVarNewGame(GROUPE *VAR) { + VAR->LEVELSPEED = 16; + VAR->LEVEL = 1; + VAR->live = 3; + VAR->ANIMREFLECT = 0; + LoadLevel(0, VAR); } -void PLAYMUSIC(void){ -for (uint8_t t=0;t<92;t=t+2){ -JOY_sound((Music1[t]),((Music1[t+1])-100)); -}} - -uint8_t BallMissing(GROUPE *VAR){ -if (VAR->Ballxpos<0) {return 1;} -return 0; +void PLAYMUSIC(void) { + for (uint8_t t = 0; t < 92; t = t + 2) { + JOY_sound((Music1[t]), ((Music1[t + 1]) - 100)); + } } -uint8_t CheckLevelEnded(GROUPE *VAR){ -uint8_t h,v,res=1; -for(v=0;v<5;v++){ -for(h=0;h<6;h++){ -if ((VAR->BlocsGrid[h][v]!=255)&&(VAR->BlocsGrid[h][v]!=5)) {res=0;} -}} -return res; +uint8_t BallMissing(GROUPE *VAR) { + if (VAR->Ballxpos < 0) { + return 1; + } + return 0; } -void UpdateBall(GROUPE *VAR){ -VAR->TrackAngleOut=0; -for (uint8_t T1=0;T1<=6;T1++) { -RecupeBALLPosForSIM(VAR); -if (VAR->launch==0) goto FIN; -SimulMove(T1,VAR); -TestMoveBALL(VAR); -if (CheckCollisionBall(VAR)==0) {goto FIN;} +uint8_t CheckLevelEnded(GROUPE *VAR) { + uint8_t h, v, res = 1; + for (v = 0; v < 5; v++) { + for (h = 0; h < 6; h++) { + if ((VAR->BlocsGrid[h][v] != 255) && (VAR->BlocsGrid[h][v] != 5)) { + res = 0; + } + } + } + return res; } + +void UpdateBall(GROUPE *VAR) { + VAR->TrackAngleOut = 0; + for (uint8_t T1 = 0; T1 <= 6; T1++) { + RecupeBALLPosForSIM(VAR); + if (VAR->launch == 0) goto FIN; + SimulMove(T1, VAR); + TestMoveBALL(VAR); + if (CheckCollisionBall(VAR) == 0) { + goto FIN; + } + } FIN:; -WriteBallMove(VAR); + WriteBallMove(VAR); } -void RecupeBALLPosForSIM(GROUPE *VAR){ -VAR->SIMBallxpos=VAR->Ballxpos; -VAR->SIMBallypos=VAR->Ballypos; -VAR->SIMBallSpeedx=VAR->BallSpeedx; -VAR->SIMBallSpeedy=VAR->BallSpeedy; +void RecupeBALLPosForSIM(GROUPE *VAR) { + VAR->SIMBallxpos = VAR->Ballxpos; + VAR->SIMBallypos = VAR->Ballypos; + VAR->SIMBallSpeedx = VAR->BallSpeedx; + VAR->SIMBallSpeedy = VAR->BallSpeedy; } -void TestMoveBALL(GROUPE *VAR){ -VAR->SIMBallxpos=VAR->SIMBallxpos+VAR->SIMBallSpeedx; -VAR->SIMBallypos=VAR->SIMBallypos+VAR->SIMBallSpeedy; +void TestMoveBALL(GROUPE *VAR) { + VAR->SIMBallxpos = VAR->SIMBallxpos + VAR->SIMBallSpeedx; + VAR->SIMBallypos = VAR->SIMBallypos + VAR->SIMBallSpeedy; } -void SimulMove(uint8_t Sim,GROUPE *VAR){ -switch(Sim){ - case (0):VAR->SIMBallSpeedx=VAR->BallSpeedx;VAR->SIMBallSpeedy=VAR->BallSpeedy;break; - case (1):VAR->SIMBallSpeedx=-VAR->BallSpeedx;VAR->SIMBallSpeedy=VAR->BallSpeedy;break; - case (2):VAR->SIMBallSpeedx=VAR->BallSpeedx;VAR->SIMBallSpeedy=-VAR->BallSpeedy;break; - case (3):VAR->SIMBallSpeedx=-VAR->BallSpeedx;VAR->SIMBallSpeedy=-VAR->BallSpeedy;break; - case (4):VAR->SIMBallSpeedx=-VAR->BallSpeedy;VAR->SIMBallSpeedy=-VAR->BallSpeedx;break; - case (5):VAR->SIMBallxpos=VAR->Ballxpos+1;VAR->SIMBallypos=VAR->Ballypos;VAR->SIMBallSpeedx=-1;VAR->SIMBallSpeedy=1;break; - case (6):VAR->SIMBallxpos=VAR->Ballxpos+1;VAR->SIMBallypos=VAR->Ballypos;VAR->SIMBallSpeedx=-1;VAR->SIMBallSpeedy=-1;break; - default:break; -}} - -uint8_t CheckCollisionBall(GROUPE *VAR){ -if (VAR->SIMBallxpos>106) {return 1;} -if (VAR->SIMBallypos>59) {return 1;} -if (VAR->SIMBallypos<4) {return 1;} -if (CheckCollisionWithTRACKBAR(VAR)) {JOY_sound(60,10);return 1;} -if (CheckCollisionWithBLOCK(VAR)) {return 1;} -return 0; +void SimulMove(uint8_t Sim, GROUPE *VAR) { + switch (Sim) { + case (0): + VAR->SIMBallSpeedx = VAR->BallSpeedx; + VAR->SIMBallSpeedy = VAR->BallSpeedy; + break; + case (1): + VAR->SIMBallSpeedx = -VAR->BallSpeedx; + VAR->SIMBallSpeedy = VAR->BallSpeedy; + break; + case (2): + VAR->SIMBallSpeedx = VAR->BallSpeedx; + VAR->SIMBallSpeedy = -VAR->BallSpeedy; + break; + case (3): + VAR->SIMBallSpeedx = -VAR->BallSpeedx; + VAR->SIMBallSpeedy = -VAR->BallSpeedy; + break; + case (4): + VAR->SIMBallSpeedx = -VAR->BallSpeedy; + VAR->SIMBallSpeedy = -VAR->BallSpeedx; + break; + case (5): + VAR->SIMBallxpos = VAR->Ballxpos + 1; + VAR->SIMBallypos = VAR->Ballypos; + VAR->SIMBallSpeedx = -1; + VAR->SIMBallSpeedy = 1; + break; + case (6): + VAR->SIMBallxpos = VAR->Ballxpos + 1; + VAR->SIMBallypos = VAR->Ballypos; + VAR->SIMBallSpeedx = -1; + VAR->SIMBallSpeedy = -1; + break; + default: + break; + } } -uint8_t CheckCollisionWithBLOCK(GROUPE *VAR){ -RecupePositionOnGrid(VAR); -if ((VAR->Px==255)||(VAR->Py==255)) {return 0;} -if (VAR->BlocsGrid[VAR->Py][VAR->Px]==5) {JOY_sound(210,50);VAR->ANIMREFLECT=0;return 1;} -if (VAR->BlocsGrid[VAR->Py][VAR->Px]==255) {return 0;} -JOY_sound(150,10); -VAR->BlocsGrid[VAR->Py][VAR->Px]=255; -return 1; +uint8_t CheckCollisionBall(GROUPE *VAR) { + if (VAR->SIMBallxpos > 106) { + return 1; + } + if (VAR->SIMBallypos > 59) { + return 1; + } + if (VAR->SIMBallypos < 4) { + return 1; + } + if (CheckCollisionWithTRACKBAR(VAR)) { + JOY_sound(60, 10); + return 1; + } + if (CheckCollisionWithBLOCK(VAR)) { + return 1; + } + return 0; } -void RecupePositionOnGrid(GROUPE *VAR){ -VAR->Px=RecupeXPositionOnGrid(VAR); -VAR->Py=RecupeYPositionOnGrid(VAR); +uint8_t CheckCollisionWithBLOCK(GROUPE *VAR) { + RecupePositionOnGrid(VAR); + if ((VAR->Px == 255) || (VAR->Py == 255)) { + return 0; + } + if (VAR->BlocsGrid[VAR->Py][VAR->Px] == 5) { + JOY_sound(210, 50); + VAR->ANIMREFLECT = 0; + return 1; + } + if (VAR->BlocsGrid[VAR->Py][VAR->Px] == 255) { + return 0; + } + JOY_sound(150, 10); + VAR->BlocsGrid[VAR->Py][VAR->Px] = 255; + return 1; } -uint8_t RecupeXPositionOnGrid(GROUPE *VAR){ -if ((VAR->SIMBallxpos>=66)&&(VAR->SIMBallxpos<72)) return 0; -else if ((VAR->SIMBallxpos>=72)&&(VAR->SIMBallxpos<78)) return 1; -else if ((VAR->SIMBallxpos>=78)&&(VAR->SIMBallxpos<84)) return 2; -else if ((VAR->SIMBallxpos>=84)&&(VAR->SIMBallxpos<90)) return 3; -else if ((VAR->SIMBallxpos>=90)&&(VAR->SIMBallxpos<96)) return 4; -return 255; +void RecupePositionOnGrid(GROUPE *VAR) { + VAR->Px = RecupeXPositionOnGrid(VAR); + VAR->Py = RecupeYPositionOnGrid(VAR); } -uint8_t RecupeYPositionOnGrid(GROUPE *VAR){ -if ((VAR->SIMBallypos>=8)&&(VAR->SIMBallypos<16)) return 0; -else if ((VAR->SIMBallypos>=16)&&(VAR->SIMBallypos<23)) return 1; -else if ((VAR->SIMBallypos>=23)&&(VAR->SIMBallypos<31)) return 2; -else if ((VAR->SIMBallypos>=31)&&(VAR->SIMBallypos<40)) return 3; -else if ((VAR->SIMBallypos>=40)&&(VAR->SIMBallypos<48)) return 4; -else if ((VAR->SIMBallypos>=48)&&(VAR->SIMBallypos<55)) return 5; -return 255; +uint8_t RecupeXPositionOnGrid(GROUPE *VAR) { + if ((VAR->SIMBallxpos >= 66) && (VAR->SIMBallxpos < 72)) + return 0; + else if ((VAR->SIMBallxpos >= 72) && (VAR->SIMBallxpos < 78)) + return 1; + else if ((VAR->SIMBallxpos >= 78) && (VAR->SIMBallxpos < 84)) + return 2; + else if ((VAR->SIMBallxpos >= 84) && (VAR->SIMBallxpos < 90)) + return 3; + else if ((VAR->SIMBallxpos >= 90) && (VAR->SIMBallxpos < 96)) + return 4; + return 255; } -uint8_t CheckCollisionWithTRACKBAR(GROUPE *VAR){ -uint8_t TRACK=(VAR->TrackBary*8)+VAR->TrackBaryDecal; -if ((VAR->SIMBallxpos>6)||(VAR->SIMBallxpos<5)) {return 0;} -if (TRACK>VAR->SIMBallypos) {return 0;} -if ((TRACK+16)SIMBallypos) {return 0;} -VAR->TrackAngleOut=(((VAR->SIMBallypos-TRACK)*200)/16)-100; -return 1; +uint8_t RecupeYPositionOnGrid(GROUPE *VAR) { + if ((VAR->SIMBallypos >= 8) && (VAR->SIMBallypos < 16)) + return 0; + else if ((VAR->SIMBallypos >= 16) && (VAR->SIMBallypos < 23)) + return 1; + else if ((VAR->SIMBallypos >= 23) && (VAR->SIMBallypos < 31)) + return 2; + else if ((VAR->SIMBallypos >= 31) && (VAR->SIMBallypos < 40)) + return 3; + else if ((VAR->SIMBallypos >= 40) && (VAR->SIMBallypos < 48)) + return 4; + else if ((VAR->SIMBallypos >= 48) && (VAR->SIMBallypos < 55)) + return 5; + return 255; } -void WriteBallMove(GROUPE *VAR){ -float CORECTIONY=(VAR->SIMBallSpeedy)+(VAR->TrackAngleOut/100.00); -if (CORECTIONY<-1) {CORECTIONY=-1;} -if (CORECTIONY>1) {CORECTIONY=1;} -VAR->Ballxpos=VAR->SIMBallxpos; -VAR->Ballypos=VAR->SIMBallypos; -VAR->BallSpeedx=VAR->SIMBallSpeedx; -VAR->BallSpeedy=CORECTIONY; -VAR->BALLyDecal=RecupeDecalageY(VAR->Ballypos-1); -VAR->Ypos=((VAR->Ballypos-1)/8); +uint8_t CheckCollisionWithTRACKBAR(GROUPE *VAR) { + uint8_t TRACK = (VAR->TrackBary * 8) + VAR->TrackBaryDecal; + if ((VAR->SIMBallxpos > 6) || (VAR->SIMBallxpos < 5)) { + return 0; + } + if (TRACK > VAR->SIMBallypos) { + return 0; + } + if ((TRACK + 16) < VAR->SIMBallypos) { + return 0; + } + VAR->TrackAngleOut = (((VAR->SIMBallypos - TRACK) * 200) / 16) - 100; + return 1; } -void Tiny_Flip(uint8_t render0_picture1,GROUPE *VAR){ - uint8_t y,x; - for(y = 0; y < 8; y++) { - JOY_OLED_data_start(y); - for(x = 0; x < 128; x++) { - if(render0_picture1==0) - JOY_OLED_send(Block(x,y,VAR)|Ball(x,y,VAR)|TrackBar(x,y,VAR)|background(x,y)|PannelLive(x,y,VAR)|PannelLevel(x,y,VAR)); - else if(render0_picture1==1) - JOY_OLED_send((MAIN[x+(y*128)])); - else if(render0_picture1==2) - JOY_OLED_send(background(x,y)); +void WriteBallMove(GROUPE *VAR) { + float CORECTIONY = (VAR->SIMBallSpeedy) + (VAR->TrackAngleOut / 100.00); + if (CORECTIONY < -1) { + CORECTIONY = -1; + } + if (CORECTIONY > 1) { + CORECTIONY = 1; } - JOY_OLED_end(); - } + VAR->Ballxpos = VAR->SIMBallxpos; + VAR->Ballypos = VAR->SIMBallypos; + VAR->BallSpeedx = VAR->SIMBallSpeedx; + VAR->BallSpeedy = CORECTIONY; + VAR->BALLyDecal = RecupeDecalageY(VAR->Ballypos - 1); + VAR->Ypos = ((VAR->Ballypos - 1) / 8); } -uint8_t PannelLevel(uint8_t X,uint8_t Y,GROUPE *VAR){ -if ((Y<5)||(Y>6)||(X<117)||(X>123)) return 0x00; -#define VAl10 (VAR->LEVEL/10) -#define VAl01 (VAR->LEVEL-(VAl10*10)) -if (Y==5) {return ((DIGITAL[(X-117)+(VAl10*7)]));} -else if (Y==6) {return ((DIGITAL[(X-117)+(VAl01*7)]));} -return 0x00; +void Tiny_Flip(uint8_t render0_picture1, GROUPE *VAR) { + uint8_t y, x; + for (y = 0; y < 8; y++) { + JOY_OLED_data_start(y); + for (x = 0; x < 128; x++) { + if (render0_picture1 == 0) + JOY_OLED_send(Block(x, y, VAR) | Ball(x, y, VAR) | TrackBar(x, y, VAR) | background(x, y) | + PannelLive(x, y, VAR) | PannelLevel(x, y, VAR)); + else if (render0_picture1 == 1) + JOY_OLED_send((MAIN[x + (y * 128)])); + else if (render0_picture1 == 2) + JOY_OLED_send(background(x, y)); + } + JOY_OLED_end(); + } } -uint8_t Block(uint8_t X,uint8_t Y,GROUPE *VAR){ -uint8_t XValue=255; -if ((X>=67)&&(X<97)&&(Y>=1)&&(Y<=6)) { -if ((X>=67)&&(X<73)) XValue=0; -else if ((X>=73)&&(X<79)) XValue=1; -else if ((X>=79)&&(X<85)) XValue=2; -else if ((X>=85)&&(X<91)) XValue=3; -else if ((X>=91)&&(X<97)) XValue=4; -if (XValue==255) return 0x00; -//uint8_t XValue=((X-67)/6); -if (VAR->BlocsGrid[(Y-1)][XValue]==255) return 0x00; -if (VAR->BlocsGrid[(Y-1)][XValue]==5) {return (BLOCKREFLECT[((X-67)-(XValue*6))+(VAR->ANIMREFLECT*6)])|(BLOCK[((X-67)-(XValue*6))+((VAR->BlocsGrid[(Y-1)][XValue])*6)]);} -return (BLOCK[((X-67)-(XValue*6))+((VAR->BlocsGrid[(Y-1)][XValue])*6)]); -}return 0x00;} - -uint8_t RecupeDecalageY(uint8_t Valeur){ -while(Valeur>7){Valeur=Valeur-8;} -return Valeur; +uint8_t PannelLevel(uint8_t X, uint8_t Y, GROUPE *VAR) { + if ((Y < 5) || (Y > 6) || (X < 117) || (X > 123)) return 0x00; +#define VAl10 (VAR->LEVEL / 10) +#define VAl01 (VAR->LEVEL - (VAl10 * 10)) + if (Y == 5) { + return ((DIGITAL[(X - 117) + (VAl10 * 7)])); + } else if (Y == 6) { + return ((DIGITAL[(X - 117) + (VAl01 * 7)])); + } + return 0x00; } -uint8_t Ball(uint8_t X,uint8_t Y,GROUPE *VAR){ -#define BALLXPOS (VAR->Ballxpos-1) -#define BALLYPOS (VAR->Ballypos-1) - if (YYpos) return 0x00; - if (Y>(VAR->Ypos+1)) return 0x00; - if ((X-(uint8_t)(BALLXPOS))<0) return 0x00; - if (XBALLXPOS+2) return 0x00; -if (VAR->BALLyDecal==0) { -if (Y==VAR->Ypos ) {return ((BALL[(X-(uint8_t)(BALLXPOS))]));} - }else{ -uint8_t DECAL=RecupeDecalageY(BALLYPOS); -if (Y==VAR->Ypos) { return SplitSpriteDecalageY(DECAL,(BALL[(X-(uint8_t)(BALLXPOS))]),1);} -if (Y==(VAR->Ypos)+1) { return SplitSpriteDecalageY(DECAL,(BALL[(X-(uint8_t)(BALLXPOS))]),0);} -}return 0x00;} - -uint8_t SplitSpriteDecalageY(uint8_t decalage,uint8_t Input,uint8_t UPorDOWN){ -if (UPorDOWN) { -return Input<>(8-decalage); -}} - -uint8_t TrackBar(uint8_t X,uint8_t Y,GROUPE *VAR){ -if (X>6) return 0; -if (X<3) return 0; -if (Y>=(3+VAR->TrackBary)) return 0; -if (Y<(VAR->TrackBary)) return 0; -if (VAR->TrackBaryDecal==0){if (Y!=VAR->TrackBary+2){ return ((TRACKBAR[(X-3)+((Y-VAR->TrackBary)*4)])); -}}else{ -if (Y==VAR->TrackBary) {return SplitSpriteDecalageY(VAR->TrackBaryDecal,(TRACKBAR[(X-3)]),1);} -else if (Y==VAR->TrackBary+1) {return SplitSpriteDecalageY(VAR->TrackBaryDecal,(TRACKBAR[(X-3)]),0)|SplitSpriteDecalageY(VAR->TrackBaryDecal,(TRACKBAR[(X-3)+4]),1);} -else if ((Y==VAR->TrackBary+2)&&(VAR->TrackBaryDecal!=0)) {return SplitSpriteDecalageY(VAR->TrackBaryDecal,(TRACKBAR[(X-3)+4]),0);} -}return 0x00;} - -uint8_t PannelLive(uint8_t X,uint8_t Y,GROUPE *VAR){ -if ((Y<1)||(Y>VAR->live)||(X>121)||(X<119)) return 0x00; -return ((LIVE3[X-119]));} - -uint8_t SWIFT_TEXTURE=0; -uint8_t background(uint8_t X,uint8_t Y){ -if (X==0) SWIFT_TEXTURE=0; -if (X<=105){ -if (SWIFT_TEXTURE<14) {SWIFT_TEXTURE++;}else{SWIFT_TEXTURE=0;} -switch(Y){ - case 0:return ((back_UP[X]));break; - case 1: - case 2: - case 3: - case 4: - case 5: - case 6:return (texture[SWIFT_TEXTURE]);break; - case 7:return (back_DOWN[X]);break; - default:break; +uint8_t Block(uint8_t X, uint8_t Y, GROUPE *VAR) { + uint8_t XValue = 255; + if ((X >= 67) && (X < 97) && (Y >= 1) && (Y <= 6)) { + if ((X >= 67) && (X < 73)) + XValue = 0; + else if ((X >= 73) && (X < 79)) + XValue = 1; + else if ((X >= 79) && (X < 85)) + XValue = 2; + else if ((X >= 85) && (X < 91)) + XValue = 3; + else if ((X >= 91) && (X < 97)) + XValue = 4; + if (XValue == 255) return 0x00; + // uint8_t XValue=((X-67)/6); + if (VAR->BlocsGrid[(Y - 1)][XValue] == 255) return 0x00; + if (VAR->BlocsGrid[(Y - 1)][XValue] == 5) { + return (BLOCKREFLECT[((X - 67) - (XValue * 6)) + (VAR->ANIMREFLECT * 6)]) | + (BLOCK[((X - 67) - (XValue * 6)) + ((VAR->BlocsGrid[(Y - 1)][XValue]) * 6)]); + } + return (BLOCK[((X - 67) - (XValue * 6)) + ((VAR->BlocsGrid[(Y - 1)][XValue]) * 6)]); + } + return 0x00; } -}else{ -return ((back_RIGHT[(X-106)+(Y*22)])); +uint8_t RecupeDecalageY(uint8_t Valeur) { + while (Valeur > 7) { + Valeur = Valeur - 8; } -return 0x00; + return Valeur; } -void LoadLevel(uint8_t Level,GROUPE *VAR){ -uint8_t a,b; -for(b=0;b<5;b++){ -for(a=0;a<6;a++){ -VAR->BlocsGrid[a][b]=(LEVEL[(Level*30)+b+(a*5)]); -}}} - -void ResetVar(GROUPE *VAR){ -uint8_t f=VAR->LEVEL; -while(1){if (f>4) {f=f-5;}else{break;}} -LoadLevel(f,VAR); -VAR->launch=0;} - -void ResetBall(GROUPE *VAR){ -VAR->ANIMREFLECT=0; -VAR->TrackBary=2; -VAR->TrackBaryDecal=4; -VAR->Ballxpos=8; -VAR->SIMBallxpos=8; -VAR->Ballypos=32; -VAR->SIMBallypos=32; -VAR->BallSpeedx=1; -VAR->SIMBallSpeedx=1; -if (VAR->Frame>32) { -VAR->BallSpeedy=.41; -VAR->SIMBallSpeedy=.41; -}else{ -VAR->BallSpeedy=.47; -VAR->SIMBallSpeedy=.47; +uint8_t Ball(uint8_t X, uint8_t Y, GROUPE *VAR) { +#define BALLXPOS (VAR->Ballxpos - 1) +#define BALLYPOS (VAR->Ballypos - 1) + if (Y < VAR->Ypos) return 0x00; + if (Y > (VAR->Ypos + 1)) return 0x00; + if ((X - (uint8_t)(BALLXPOS)) < 0) return 0x00; + if (X < BALLXPOS) return 0x00; + if (X > BALLXPOS + 2) return 0x00; + if (VAR->BALLyDecal == 0) { + if (Y == VAR->Ypos) { + return ((BALL[(X - (uint8_t)(BALLXPOS))])); + } + } else { + uint8_t DECAL = RecupeDecalageY(BALLYPOS); + if (Y == VAR->Ypos) { + return SplitSpriteDecalageY(DECAL, (BALL[(X - (uint8_t)(BALLXPOS))]), 1); + } + if (Y == (VAR->Ypos) + 1) { + return SplitSpriteDecalageY(DECAL, (BALL[(X - (uint8_t)(BALLXPOS))]), 0); + } + } + return 0x00; +} + +uint8_t SplitSpriteDecalageY(uint8_t decalage, uint8_t Input, uint8_t UPorDOWN) { + if (UPorDOWN) { + return Input << decalage; + } else { + return Input >> (8 - decalage); + } +} + +uint8_t TrackBar(uint8_t X, uint8_t Y, GROUPE *VAR) { + if (X > 6) return 0; + if (X < 3) return 0; + if (Y >= (3 + VAR->TrackBary)) return 0; + if (Y < (VAR->TrackBary)) return 0; + if (VAR->TrackBaryDecal == 0) { + if (Y != VAR->TrackBary + 2) { + return ((TRACKBAR[(X - 3) + ((Y - VAR->TrackBary) * 4)])); + } + } else { + if (Y == VAR->TrackBary) { + return SplitSpriteDecalageY(VAR->TrackBaryDecal, (TRACKBAR[(X - 3)]), 1); + } else if (Y == VAR->TrackBary + 1) { + return SplitSpriteDecalageY(VAR->TrackBaryDecal, (TRACKBAR[(X - 3)]), 0) | + SplitSpriteDecalageY(VAR->TrackBaryDecal, (TRACKBAR[(X - 3) + 4]), 1); + } else if ((Y == VAR->TrackBary + 2) && (VAR->TrackBaryDecal != 0)) { + return SplitSpriteDecalageY(VAR->TrackBaryDecal, (TRACKBAR[(X - 3) + 4]), 0); + } + } + return 0x00; +} + +uint8_t PannelLive(uint8_t X, uint8_t Y, GROUPE *VAR) { + if ((Y < 1) || (Y > VAR->live) || (X > 121) || (X < 119)) return 0x00; + return ((LIVE3[X - 119])); +} + +uint8_t SWIFT_TEXTURE = 0; +uint8_t background(uint8_t X, uint8_t Y) { + if (X == 0) SWIFT_TEXTURE = 0; + if (X <= 105) { + if (SWIFT_TEXTURE < 14) { + SWIFT_TEXTURE++; + } else { + SWIFT_TEXTURE = 0; + } + switch (Y) { + case 0: + return ((back_UP[X])); + break; + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + return (texture[SWIFT_TEXTURE]); + break; + case 7: + return (back_DOWN[X]); + break; + default: + break; + } + + } else { + return ((back_RIGHT[(X - 106) + (Y * 22)])); + } + return 0x00; } -VAR->launch=0; + +void LoadLevel(uint8_t Level, GROUPE *VAR) { + uint8_t a, b; + for (b = 0; b < 5; b++) { + for (a = 0; a < 6; a++) { + VAR->BlocsGrid[a][b] = (LEVEL[(Level * 30) + b + (a * 5)]); + } + } +} + +void ResetVar(GROUPE *VAR) { + uint8_t f = VAR->LEVEL; + while (1) { + if (f > 4) { + f = f - 5; + } else { + break; + } + } + LoadLevel(f, VAR); + VAR->launch = 0; +} + +void ResetBall(GROUPE *VAR) { + VAR->ANIMREFLECT = 0; + VAR->TrackBary = 2; + VAR->TrackBaryDecal = 4; + VAR->Ballxpos = 8; + VAR->SIMBallxpos = 8; + VAR->Ballypos = 32; + VAR->SIMBallypos = 32; + VAR->BallSpeedx = 1; + VAR->SIMBallSpeedx = 1; + if (VAR->Frame > 32) { + VAR->BallSpeedy = .41; + VAR->SIMBallSpeedy = .41; + } else { + VAR->BallSpeedy = .47; + VAR->SIMBallSpeedy = .47; + } + VAR->launch = 0; } diff --git a/fw/application/src/app/game/port/tiny_invaders/tiny_invaders.c b/fw/application/src/app/game/port/tiny_invaders/tiny_invaders.c index 3a921bf7..59d94b58 100644 --- a/fw/application/src/app/game/port/tiny_invaders/tiny_invaders.c +++ b/fw/application/src/app/game/port/tiny_invaders/tiny_invaders.c @@ -81,584 +81,675 @@ void VarResetNewLevel(SPACE *space); // Main Function // =================================================================================== int tiny_invaders_run(void) { - // Setup - JOY_init(); - - // Loop - while(1) { - uint8_t Decompte = 0; - uint8_t VarPot; - uint8_t MyShootReady = SHOOTS; - SPACE space; - - NEWGAME: - Live = 3; - LEVELS = 0; - Tiny_Flip(1, &space); - while(1) { - if(JOY_act_pressed()) { - JOY_sound(100, 125); JOY_sound(50, 125); - goto BYPASS2; - } - JOY_idle(); - } - - NEWLEVEL: - JOY_DLY_ms(1000); - - BYPASS2: - VarResetNewLevel(&space); - SpeedControle(&space); - VarPot = 54; - ShipPos = 56; - space.ScrBackV=(ShipPos / 14) + 52; - goto Bypass; - - RestartLevel: - if(Live > 0) Live--; - else goto NEWGAME; - - Bypass: - ShipDead = 0; - Decompte = 0; - Tiny_Flip(0, &space); - JOY_DLY_ms(1000); - while(1) { - if(MONSTERrest == 0) { - JOY_sound(110, 255); JOY_DLY_ms(40); JOY_sound(130, 255); JOY_DLY_ms(40); - JOY_sound(100, 255); JOY_DLY_ms(40); JOY_sound(1, 155); JOY_DLY_ms(20); - JOY_sound(60, 255); JOY_sound(60, 255); - if(LEVELS < 9) LEVELS++; - goto NEWLEVEL; - } - if((((space.MonsterGroupeYpos) + (space.MonsterFloorMax + 1)) == 7) && (Decompte == 0)) ShipDead = 1; - if(SpeedShootMonster <= 9 - LEVELS) SpeedShootMonster++; - else {SpeedShootMonster = 0; MonsterShootGenerate(&space);} - space.ScrBackV = (ShipPos / 14) + 52; - Tiny_Flip(0, &space); - space.oneFrame = !space.oneFrame; - RemoveExplodOnMonsterGrid(&space); - MonsterShootupdate(&space); - UFOUpdate(&space); - if(((space.MonsterGroupeXpos >= 26) && (space.MonsterGroupeXpos <= 28)) - && (space.MonsterGroupeYpos == 2) && (space.DecalageY8 == 4)) space.UFOxPos = 127; - if(VarPot > (ShipPos + 2)) ShipPos = ShipPos + ((VarPot - ShipPos) / 3); - if(VarPot < (ShipPos - 2)) ShipPos = ShipPos - ((ShipPos - VarPot) / 3); - if(ShipDead != 1) { - if(space.frame < space.frameMax) space.frame++; - else { - GRIDMonsterFloorY(&space); - space.anim = !space.anim; - if(space.anim == 0) SnD(space.UFOxPos, 200); - else SnD(space.UFOxPos, 100); - MonsterRefreshMove(&space); - space.frame = 0; + // Setup + JOY_init(); + + // Loop + while (1) { + uint8_t Decompte = 0; + uint8_t VarPot; + uint8_t MyShootReady = SHOOTS; + SPACE space; + + NEWGAME: + Live = 3; + LEVELS = 0; + Tiny_Flip(1, &space); + while (1) { + if (JOY_act_pressed()) { + JOY_sound(100, 125); + JOY_sound(50, 125); + goto BYPASS2; + } + JOY_idle(); + if (JOY_exit()) { + goto EXIT; + } } - if(JOY_left_pressed()) { - if(VarPot > 5) VarPot = VarPot - 6; - } - if(JOY_right_pressed()) { - if(VarPot < 108) VarPot = VarPot + 6; - } - if((JOY_act_pressed()) && (MyShootReady == SHOOTS)) { - JOY_sound(200, 4); MyShootReady = 0; space.MyShootBall = 6; space.MyShootBallxpos = ShipPos + 6; + NEWLEVEL: + JOY_DLY_ms(1000); + + BYPASS2: + VarResetNewLevel(&space); + SpeedControle(&space); + VarPot = 54; + ShipPos = 56; + space.ScrBackV = (ShipPos / 14) + 52; + goto Bypass; + + RestartLevel: + if (Live > 0) + Live--; + else + goto NEWGAME; + + Bypass: + ShipDead = 0; + Decompte = 0; + Tiny_Flip(0, &space); + JOY_DLY_ms(1000); + while (1) { + if (MONSTERrest == 0) { + JOY_sound(110, 255); + JOY_DLY_ms(40); + JOY_sound(130, 255); + JOY_DLY_ms(40); + JOY_sound(100, 255); + JOY_DLY_ms(40); + JOY_sound(1, 155); + JOY_DLY_ms(20); + JOY_sound(60, 255); + JOY_sound(60, 255); + if (LEVELS < 9) LEVELS++; + goto NEWLEVEL; + } + if ((((space.MonsterGroupeYpos) + (space.MonsterFloorMax + 1)) == 7) && (Decompte == 0)) ShipDead = 1; + if (SpeedShootMonster <= 9 - LEVELS) + SpeedShootMonster++; + else { + SpeedShootMonster = 0; + MonsterShootGenerate(&space); + } + space.ScrBackV = (ShipPos / 14) + 52; + Tiny_Flip(0, &space); + space.oneFrame = !space.oneFrame; + RemoveExplodOnMonsterGrid(&space); + MonsterShootupdate(&space); + UFOUpdate(&space); + if (((space.MonsterGroupeXpos >= 26) && (space.MonsterGroupeXpos <= 28)) && + (space.MonsterGroupeYpos == 2) && (space.DecalageY8 == 4)) + space.UFOxPos = 127; + if (VarPot > (ShipPos + 2)) ShipPos = ShipPos + ((VarPot - ShipPos) / 3); + if (VarPot < (ShipPos - 2)) ShipPos = ShipPos - ((ShipPos - VarPot) / 3); + if (ShipDead != 1) { + if (space.frame < space.frameMax) + space.frame++; + else { + GRIDMonsterFloorY(&space); + space.anim = !space.anim; + if (space.anim == 0) + SnD(space.UFOxPos, 200); + else + SnD(space.UFOxPos, 100); + MonsterRefreshMove(&space); + space.frame = 0; + } + + if (JOY_left_pressed()) { + if (VarPot > 5) VarPot = VarPot - 6; + } + if (JOY_right_pressed()) { + if (VarPot < 108) VarPot = VarPot + 6; + } + if ((JOY_act_pressed()) && (MyShootReady == SHOOTS)) { + JOY_sound(200, 4); + MyShootReady = 0; + space.MyShootBall = 6; + space.MyShootBallxpos = ShipPos + 6; + } + } else { + JOY_sound(80, 1); + JOY_sound(100, 1); + Decompte++; + if (Decompte >= 30) { + JOY_DLY_ms(600); + if (((space.MonsterGroupeYpos) + (space.MonsterFloorMax + 1)) == 7) + goto NEWGAME; + else + goto RestartLevel; + } + } + if (space.MyShootBall == -1) { + if (MyShootReady < SHOOTS) MyShootReady++; + } + JOY_idle(); + if (JOY_exit()) { + goto EXIT; + } + JOY_SLOWDOWN(); } - } - else { - JOY_sound(80, 1); JOY_sound(100, 1); - Decompte++; - if(Decompte >= 30) { - JOY_DLY_ms(600); - if(((space.MonsterGroupeYpos) + (space.MonsterFloorMax + 1)) == 7) goto NEWGAME; - else goto RestartLevel; - } - } - if(space.MyShootBall == -1) { - if(MyShootReadyMonsterGrid[y][x] = MonstersLevels[(Levels * 24) + (y * 6) + x]; - else space->MonsterGrid[y][x] = -1; + uint8_t x, y; + for (y = 0; y < 5; y++) { + for (x = 0; x < 6; x++) { + if (y != 4) + space->MonsterGrid[y][x] = MonstersLevels[(Levels * 24) + (y * 6) + x]; + else + space->MonsterGrid[y][x] = -1; + } } - } } void SnD(int8_t Sp_, uint8_t SN) { - if(Sp_ != -120) {JOY_sound(220, 8); JOY_sound(200, 4);} - else JOY_sound(SN, 1); + if (Sp_ != -120) { + JOY_sound(220, 8); + JOY_sound(200, 4); + } else + JOY_sound(SN, 1); } void SpeedControle(SPACE *space) { - uint8_t xx, yy; - MONSTERrest = 0; - for(yy=0; yy<4; yy++) { - for(xx=0; xx<6; xx++) { - if((space->MonsterGrid[yy][xx] != -1) && ((space->MonsterGrid[yy][xx] <=5 ))) MONSTERrest++; + uint8_t xx, yy; + MONSTERrest = 0; + for (yy = 0; yy < 4; yy++) { + for (xx = 0; xx < 6; xx++) { + if ((space->MonsterGrid[yy][xx] != -1) && ((space->MonsterGrid[yy][xx] <= 5))) MONSTERrest++; + } } - } - space->frameMax = (MONSTERrest >> 3); + space->frameMax = (MONSTERrest >> 3); } // Thanks to Sven Bruns for informing me of an error in this function! void GRIDMonsterFloorY(SPACE *space) { - uint8_t y,x; - space->MonsterFloorMax = 3; - for(y=0; y<4; y++) { - for(x=0; x<6; x++) { - if(space->MonsterGrid[3-y][x] != -1) return; + uint8_t y, x; + space->MonsterFloorMax = 3; + for (y = 0; y < 4; y++) { + for (x = 0; x < 6; x++) { + if (space->MonsterGrid[3 - y][x] != -1) return; + } + space->MonsterFloorMax = space->MonsterFloorMax - 1; } - space->MonsterFloorMax = space->MonsterFloorMax - 1; - } } uint8_t LivePrint(uint8_t x, uint8_t y) { - #define XLIVEWIDE ((5 * Live) - 1) - if((0 >= (x - XLIVEWIDE)) && (y == 7)) { - return LIVE[x]; - } - return 0x00; +#define XLIVEWIDE ((5 * Live) - 1) + if ((0 >= (x - XLIVEWIDE)) && (y == 7)) { + return LIVE[x]; + } + return 0x00; } void Tiny_Flip(uint8_t render0_picture1, SPACE *space) { - uint8_t y, x; - uint8_t MYSHIELD = 0x00; - for(y=0; y<8; y++) { - JOY_OLED_data_start(y); - for(x=0; x<128; x++) { - if(render0_picture1 == 0) { - if(ShieldRemoved == 0) MYSHIELD = MyShield(x, y, space); - else MYSHIELD = 0x00; - JOY_OLED_send( background(x, y, space) - | LivePrint(x, y) - | Vesso(x, y, space) - | UFOWrite(x, y, space) - | Monster(x, y, space) - | MyShoot(x, y, space) - | MonsterShoot(x, y, space) - | MYSHIELD); - } - else JOY_OLED_send(intro[x + (y * 128)]); - } - if(render0_picture1 == 0) { - if(ShieldRemoved == 0) ShieldDestroy(0, space->MyShootBallxpos, space->MyShootBall, space); + uint8_t y, x; + uint8_t MYSHIELD = 0x00; + for (y = 0; y < 8; y++) { + JOY_OLED_data_start(y); + for (x = 0; x < 128; x++) { + if (render0_picture1 == 0) { + if (ShieldRemoved == 0) + MYSHIELD = MyShield(x, y, space); + else + MYSHIELD = 0x00; + JOY_OLED_send(background(x, y, space) | LivePrint(x, y) | Vesso(x, y, space) | UFOWrite(x, y, space) | + Monster(x, y, space) | MyShoot(x, y, space) | MonsterShoot(x, y, space) | MYSHIELD); + } else + JOY_OLED_send(intro[x + (y * 128)]); + } + if (render0_picture1 == 0) { + if (ShieldRemoved == 0) ShieldDestroy(0, space->MyShootBallxpos, space->MyShootBall, space); + } + JOY_OLED_end(); } - JOY_OLED_end(); - } - if(render0_picture1 == 0) { - if(!(space->MonsterGroupeYpos < (2 + (4 - (space->MonsterFloorMax + 1))))) { - if(ShieldRemoved != 1) { - space->Shield[0] = 0x00; - space->Shield[1] = 0x00; - space->Shield[2] = 0x00; - space->Shield[3] = 0x00; - space->Shield[4] = 0x00; - space->Shield[5] = 0x00; - ShieldRemoved = 1; - } + if (render0_picture1 == 0) { + if (!(space->MonsterGroupeYpos < (2 + (4 - (space->MonsterFloorMax + 1))))) { + if (ShieldRemoved != 1) { + space->Shield[0] = 0x00; + space->Shield[1] = 0x00; + space->Shield[2] = 0x00; + space->Shield[3] = 0x00; + space->Shield[4] = 0x00; + space->Shield[5] = 0x00; + ShieldRemoved = 1; + } + } } - } } uint8_t UFOWrite(uint8_t x, uint8_t y, SPACE *space) { - if((space->UFOxPos != -120) && (y == 0) && (space->UFOxPos <= x) && (space->UFOxPos >= (x - 14))) - return Monsters[(x - space->UFOxPos) + (6 * 14) + (space->oneFrame * 14)]; - return 0x00; + if ((space->UFOxPos != -120) && (y == 0) && (space->UFOxPos <= x) && (space->UFOxPos >= (x - 14))) + return Monsters[(x - space->UFOxPos) + (6 * 14) + (space->oneFrame * 14)]; + return 0x00; } void UFOUpdate(SPACE *space) { - if(space->UFOxPos != -120) { - space->UFOxPos = space->UFOxPos - 2; - SnD(space->UFOxPos, 0); - if(space->UFOxPos <= -20) space->UFOxPos = -120; - } + if (space->UFOxPos != -120) { + space->UFOxPos = space->UFOxPos - 2; + SnD(space->UFOxPos, 0); + if (space->UFOxPos <= -20) space->UFOxPos = -120; + } } void ShipDestroyByMonster(SPACE *space) { - if((space->MonsterShoot[1] >= 14) && (space->MonsterShoot[1] <= 15) - && (space->MonsterShoot[0] >= ShipPos) && (space->MonsterShoot[0] <= ShipPos+14)) - ShipDead=1; + if ((space->MonsterShoot[1] >= 14) && (space->MonsterShoot[1] <= 15) && (space->MonsterShoot[0] >= ShipPos) && + (space->MonsterShoot[0] <= ShipPos + 14)) + ShipDead = 1; } void MonsterShootupdate(SPACE *space) { - if(space->MonsterShoot[1] != 16) { - ShipDestroyByMonster(space); - if(ShieldDestroy(1, space->MonsterShoot[0], space->MonsterShoot[1] >> 1, space)) - space->MonsterShoot[1] = 16; - else - space->MonsterShoot[1] = space->MonsterShoot[1] + 1; - } + if (space->MonsterShoot[1] != 16) { + ShipDestroyByMonster(space); + if (ShieldDestroy(1, space->MonsterShoot[0], space->MonsterShoot[1] >> 1, space)) + space->MonsterShoot[1] = 16; + else + space->MonsterShoot[1] = space->MonsterShoot[1] + 1; + } } void MonsterShootGenerate(SPACE *space) { - uint8_t a = JOY_random() % 3; - uint8_t b = JOY_random() % 6; - if(b >= 5) b = 5; - if(space->MonsterShoot[1] == 16) { - if(space->MonsterGrid[a][b] != -1) { - space->MonsterShoot[0] = (space->MonsterGroupeXpos + 7) + (b * 14); - space->MonsterShoot[1] = ((space->MonsterGroupeYpos + a) * 2) + 1; + uint8_t a = JOY_random() % 3; + uint8_t b = JOY_random() % 6; + if (b >= 5) b = 5; + if (space->MonsterShoot[1] == 16) { + if (space->MonsterGrid[a][b] != -1) { + space->MonsterShoot[0] = (space->MonsterGroupeXpos + 7) + (b * 14); + space->MonsterShoot[1] = ((space->MonsterGroupeYpos + a) * 2) + 1; + } } - } } uint8_t MonsterShoot(uint8_t x, uint8_t y, SPACE *space) { - if(((space->MonsterShoot[1] >> 1) == y) && (space->MonsterShoot[0] == x)) { - if((space->MonsterShoot[1] & 1) == 0) return 0b00001111; - else return 0b11110000; - } - return 0x00; + if (((space->MonsterShoot[1] >> 1) == y) && (space->MonsterShoot[0] == x)) { + if ((space->MonsterShoot[1] & 1) == 0) + return 0b00001111; + else + return 0b11110000; + } + return 0x00; } uint8_t ShieldDestroy(uint8_t Origine, uint8_t VarX, uint8_t VarY, SPACE *space) { - #define OFFSETXSHIELD -1 - if(VarY == 6) { - if((VarX >= 20 + OFFSETXSHIELD) && (VarX <= 27 + OFFSETXSHIELD)) { - if(BOOLREAD(0, VarX - (20 + OFFSETXSHIELD), space)) { - ShieldDestroyWrite(0, VarX - (20 + OFFSETXSHIELD), space, Origine); - return 1; - } - } - if((VarX >= 28 + OFFSETXSHIELD) && (VarX <= 35 + OFFSETXSHIELD)) { - if(BOOLREAD(1, VarX - (28 + OFFSETXSHIELD), space)) { - ShieldDestroyWrite(1, VarX - (28 + OFFSETXSHIELD), space, Origine); - return 1; - } - } - if((VarX >= 55 + OFFSETXSHIELD) && (VarX <= 62 + OFFSETXSHIELD)) { - if(BOOLREAD(2, VarX - (55 + OFFSETXSHIELD), space)) { - ShieldDestroyWrite(2, VarX - (55 + OFFSETXSHIELD), space, Origine); - return 1; - } - } - if((VarX >= 63 + OFFSETXSHIELD) && (VarX <= 70 + OFFSETXSHIELD)) { - if(BOOLREAD(3, VarX - (63 + OFFSETXSHIELD), space)) { - ShieldDestroyWrite(3, VarX - (63 + OFFSETXSHIELD), space, Origine); - return 1; - } - } - if((VarX >= 90 + OFFSETXSHIELD) && (VarX <= 97 + OFFSETXSHIELD)) { - if(BOOLREAD(4, VarX - (90 + OFFSETXSHIELD), space)) { - ShieldDestroyWrite(4, VarX - (90 + OFFSETXSHIELD), space, Origine); - return 1; - } - } - if((VarX >= 98 + OFFSETXSHIELD) && (VarX <= 105 + OFFSETXSHIELD)) { - if(BOOLREAD(5, VarX - (98 + OFFSETXSHIELD), space)) { - ShieldDestroyWrite(5, VarX - (98 + OFFSETXSHIELD), space, Origine); - return 1; - } +#define OFFSETXSHIELD -1 + if (VarY == 6) { + if ((VarX >= 20 + OFFSETXSHIELD) && (VarX <= 27 + OFFSETXSHIELD)) { + if (BOOLREAD(0, VarX - (20 + OFFSETXSHIELD), space)) { + ShieldDestroyWrite(0, VarX - (20 + OFFSETXSHIELD), space, Origine); + return 1; + } + } + if ((VarX >= 28 + OFFSETXSHIELD) && (VarX <= 35 + OFFSETXSHIELD)) { + if (BOOLREAD(1, VarX - (28 + OFFSETXSHIELD), space)) { + ShieldDestroyWrite(1, VarX - (28 + OFFSETXSHIELD), space, Origine); + return 1; + } + } + if ((VarX >= 55 + OFFSETXSHIELD) && (VarX <= 62 + OFFSETXSHIELD)) { + if (BOOLREAD(2, VarX - (55 + OFFSETXSHIELD), space)) { + ShieldDestroyWrite(2, VarX - (55 + OFFSETXSHIELD), space, Origine); + return 1; + } + } + if ((VarX >= 63 + OFFSETXSHIELD) && (VarX <= 70 + OFFSETXSHIELD)) { + if (BOOLREAD(3, VarX - (63 + OFFSETXSHIELD), space)) { + ShieldDestroyWrite(3, VarX - (63 + OFFSETXSHIELD), space, Origine); + return 1; + } + } + if ((VarX >= 90 + OFFSETXSHIELD) && (VarX <= 97 + OFFSETXSHIELD)) { + if (BOOLREAD(4, VarX - (90 + OFFSETXSHIELD), space)) { + ShieldDestroyWrite(4, VarX - (90 + OFFSETXSHIELD), space, Origine); + return 1; + } + } + if ((VarX >= 98 + OFFSETXSHIELD) && (VarX <= 105 + OFFSETXSHIELD)) { + if (BOOLREAD(5, VarX - (98 + OFFSETXSHIELD), space)) { + ShieldDestroyWrite(5, VarX - (98 + OFFSETXSHIELD), space, Origine); + return 1; + } + } } - } - return 0; + return 0; } void ShieldDestroyWrite(uint8_t BOOLWRITE, uint8_t line, SPACE *space, uint8_t Origine) { - switch(line) { + switch (line) { case 0: - space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 128; - if(Origine == 0) space->MyShootBall = -1; - break; + space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 128; + if (Origine == 0) space->MyShootBall = -1; + break; case 1: - space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 64; - if(Origine == 0) space->MyShootBall = -1; - break; + space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 64; + if (Origine == 0) space->MyShootBall = -1; + break; case 2: - space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 32; - if(Origine == 0) space->MyShootBall = -1; - break; + space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 32; + if (Origine == 0) space->MyShootBall = -1; + break; case 3: - space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 16; - if(Origine == 0) space->MyShootBall = -1; - break; + space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 16; + if (Origine == 0) space->MyShootBall = -1; + break; case 4: - space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 8; - if(Origine == 0) space->MyShootBall = -1; - break; + space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 8; + if (Origine == 0) space->MyShootBall = -1; + break; case 5: - space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 4; - if(Origine == 0) space->MyShootBall = -1; - break; + space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 4; + if (Origine == 0) space->MyShootBall = -1; + break; case 6: - space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 2; - if(Origine == 0) space->MyShootBall = -1; - break; + space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 2; + if (Origine == 0) space->MyShootBall = -1; + break; case 7: - space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 1; - if(Origine == 0) space->MyShootBall = -1; - break; + space->Shield[BOOLWRITE] = space->Shield[BOOLWRITE] - 1; + if (Origine == 0) space->MyShootBall = -1; + break; default: - break; - } + break; + } } uint8_t MyShield(uint8_t x, uint8_t y, SPACE *space) { - #define OFFSETXSHIELD -1 - if(y != 6) return 0x00; - if((x >= 20 + OFFSETXSHIELD) && (x <= 27 + OFFSETXSHIELD)) { - if(BOOLREAD(0, x - (20 + OFFSETXSHIELD), space)) return ShieldBlitz(0, x - (20 + OFFSETXSHIELD)); - else return 0x00; - } - if((x >= 28 + OFFSETXSHIELD) && (x <= 35 + OFFSETXSHIELD)) { - if(BOOLREAD(1, x - (28 + OFFSETXSHIELD), space)) return ShieldBlitz(1, x - (28 + OFFSETXSHIELD)); - else return 0x00; - } - if((x >= 55 + OFFSETXSHIELD) && (x <= 62 + OFFSETXSHIELD)) { - if(BOOLREAD(2, x - (55 + OFFSETXSHIELD), space)) return ShieldBlitz(0, x - (55 + OFFSETXSHIELD)); - else return 0x00; - } - if((x >= 63 + OFFSETXSHIELD) && (x <= 70 + OFFSETXSHIELD)) { - if(BOOLREAD(3, x - (63 + OFFSETXSHIELD), space)) return ShieldBlitz(1, x - (63 + OFFSETXSHIELD)); - else return 0x00; - } - if((x >= 90 + OFFSETXSHIELD) && (x <= 97 + OFFSETXSHIELD)) { - if(BOOLREAD(4, x - (90 + OFFSETXSHIELD), space)) return ShieldBlitz(0, x - (90 + OFFSETXSHIELD)); - else return 0x00; - } - if((x >= 98 + OFFSETXSHIELD) && (x <= 105 + OFFSETXSHIELD)) { - if(BOOLREAD(5, x - (98 + OFFSETXSHIELD), space)) return ShieldBlitz(1, x - (98 + OFFSETXSHIELD)); - else return 0x00; - } - return 0x00; +#define OFFSETXSHIELD -1 + if (y != 6) return 0x00; + if ((x >= 20 + OFFSETXSHIELD) && (x <= 27 + OFFSETXSHIELD)) { + if (BOOLREAD(0, x - (20 + OFFSETXSHIELD), space)) + return ShieldBlitz(0, x - (20 + OFFSETXSHIELD)); + else + return 0x00; + } + if ((x >= 28 + OFFSETXSHIELD) && (x <= 35 + OFFSETXSHIELD)) { + if (BOOLREAD(1, x - (28 + OFFSETXSHIELD), space)) + return ShieldBlitz(1, x - (28 + OFFSETXSHIELD)); + else + return 0x00; + } + if ((x >= 55 + OFFSETXSHIELD) && (x <= 62 + OFFSETXSHIELD)) { + if (BOOLREAD(2, x - (55 + OFFSETXSHIELD), space)) + return ShieldBlitz(0, x - (55 + OFFSETXSHIELD)); + else + return 0x00; + } + if ((x >= 63 + OFFSETXSHIELD) && (x <= 70 + OFFSETXSHIELD)) { + if (BOOLREAD(3, x - (63 + OFFSETXSHIELD), space)) + return ShieldBlitz(1, x - (63 + OFFSETXSHIELD)); + else + return 0x00; + } + if ((x >= 90 + OFFSETXSHIELD) && (x <= 97 + OFFSETXSHIELD)) { + if (BOOLREAD(4, x - (90 + OFFSETXSHIELD), space)) + return ShieldBlitz(0, x - (90 + OFFSETXSHIELD)); + else + return 0x00; + } + if ((x >= 98 + OFFSETXSHIELD) && (x <= 105 + OFFSETXSHIELD)) { + if (BOOLREAD(5, x - (98 + OFFSETXSHIELD), space)) + return ShieldBlitz(1, x - (98 + OFFSETXSHIELD)); + else + return 0x00; + } + return 0x00; } uint8_t ShieldBlitz(uint8_t Part, uint8_t LineSH) { - uint8_t Var0 = 0; - switch(LineSH) { - case 0: if(Part == 0) Var0 = 0b11110000; else Var0 = 0b00001111; break; - case 1: if(Part == 0) Var0 = 0b11111100; else Var0 = 0b00001111; break; + uint8_t Var0 = 0; + switch (LineSH) { + case 0: + if (Part == 0) + Var0 = 0b11110000; + else + Var0 = 0b00001111; + break; + case 1: + if (Part == 0) + Var0 = 0b11111100; + else + Var0 = 0b00001111; + break; case 2: case 3: case 4: - case 5: Var0 = 0b00001111; break; - case 6: if(Part == 1) Var0 = 0b11111100; else Var0 = 0b00001111; break; - case 7: if(Part == 1) Var0 = 0b11110000; else Var0 = 0b00001111; break; - default: Var0 = 0b00000000; break; - } - return Var0; + case 5: + Var0 = 0b00001111; + break; + case 6: + if (Part == 1) + Var0 = 0b11111100; + else + Var0 = 0b00001111; + break; + case 7: + if (Part == 1) + Var0 = 0b11110000; + else + Var0 = 0b00001111; + break; + default: + Var0 = 0b00000000; + break; + } + return Var0; } uint8_t BOOLREAD(uint8_t SHnum, uint8_t LineSH, SPACE *space) { - uint8_t Var0 = 0b10000000 >> LineSH; - return((space->Shield[SHnum] & Var0) != 0); + uint8_t Var0 = 0b10000000 >> LineSH; + return ((space->Shield[SHnum] & Var0) != 0); } void RemoveExplodOnMonsterGrid(SPACE *space) { - uint8_t x, y; - for(y=0; y<=3; y++) { - for(x=0; x<=5; x++) { - if(space->MonsterGrid[y][x] >= 11) space->MonsterGrid[y][x] = -1; - if(space->MonsterGrid[y][x] >= 8) space->MonsterGrid[y][x] = space->MonsterGrid[y][x] + 1; + uint8_t x, y; + for (y = 0; y <= 3; y++) { + for (x = 0; x <= 5; x++) { + if (space->MonsterGrid[y][x] >= 11) space->MonsterGrid[y][x] = -1; + if (space->MonsterGrid[y][x] >= 8) space->MonsterGrid[y][x] = space->MonsterGrid[y][x] + 1; + } } - } } uint8_t background(uint8_t x, uint8_t y, SPACE *space) { - uint8_t scr = space->ScrBackV + x; - if(scr > 127) scr = space->ScrBackV + x - 128; - return(0xff - back[y * 128 + scr]); + uint8_t scr = space->ScrBackV + x; + if (scr > 127) scr = space->ScrBackV + x - 128; + return (0xff - back[y * 128 + scr]); } uint8_t Vesso(uint8_t x, uint8_t y, SPACE *space) { - if((x - ShipPos >= 0) && (x - ShipPos < 13) && (y==7)) { - if(ShipDead == 0) return vesso[x - ShipPos]; - else return vesso[x - ShipPos + (12 * space->oneFrame)]; - } - return 0; + if ((x - ShipPos >= 0) && (x - ShipPos < 13) && (y == 7)) { + if (ShipDead == 0) + return vesso[x - ShipPos]; + else + return vesso[x - ShipPos + (12 * space->oneFrame)]; + } + return 0; } void UFO_Attack_Check(uint8_t x, SPACE *space) { - if(space->MyShootBall == 0) { - if((space->MyShootBallxpos >= space->UFOxPos) && (space->MyShootBallxpos <= space->UFOxPos + 14)) { - for(x=1; x<100; x++) JOY_sound(x, 1); - if(Live < 3) Live++; - space->UFOxPos =- 120; + if (space->MyShootBall == 0) { + if ((space->MyShootBallxpos >= space->UFOxPos) && (space->MyShootBallxpos <= space->UFOxPos + 14)) { + for (x = 1; x < 100; x++) + JOY_sound(x, 1); + if (Live < 3) Live++; + space->UFOxPos = -120; + } } - } } uint8_t MyShoot(uint8_t x, uint8_t y, SPACE *space) { - if((space->MyShootBallxpos == x) && (y == space->MyShootBall)) { - if(space->MyShootBall > -1) space->MyShootBallFrame = !space->MyShootBallFrame; - else return 0x00; - if(space->MyShootBallFrame == 1) space->MyShootBall--; - Monster_Attack_Check(space); - UFO_Attack_Check(x, space); - return SHOOT[space->MyShootBallFrame]; - } - return 0x00; + if ((space->MyShootBallxpos == x) && (y == space->MyShootBall)) { + if (space->MyShootBall > -1) + space->MyShootBallFrame = !space->MyShootBallFrame; + else + return 0x00; + if (space->MyShootBallFrame == 1) space->MyShootBall--; + Monster_Attack_Check(space); + UFO_Attack_Check(x, space); + return SHOOT[space->MyShootBallFrame]; + } + return 0x00; } void Monster_Attack_Check(SPACE *space) { - int8_t Varx = 0, Vary = 0; - #define Xmouin (space->MonsterGroupeXpos) - #define Ymouin (space->MonsterGroupeYpos << 3) //-space->DecalageY8 - #define XPlus (Xmouin + 84) - #define YPlus (Ymouin + (4*8)) - #define MYSHOOTX (space->MyShootBallxpos) - #define MYSHOOTY ((space->MyShootBall << 3) + ((space->MyShootBallFrame + 1) << 2)) - if((MYSHOOTX >= Xmouin) && (MYSHOOTX <= XPlus) && (MYSHOOTY >= Ymouin) && (MYSHOOTY <= YPlus)) { - //enter in the monster zone - Vary = (MYSHOOTY - Ymouin + 4) >> 3; - Varx = (MYSHOOTX - Xmouin + 7) / 14; - if(Varx < 0) Varx = 0; - if(Vary < 0) Vary = 0; - if(Varx > 5) return; - if(Vary > 3) return; - if((space->MonsterGrid[Vary][Varx] > -1) && (space->MonsterGrid[Vary][Varx] < 6)) { - JOY_sound(50, 10); - space->MonsterGrid[Vary][Varx] = 8; - space->MyShootBall = -1; - SpeedControle(space); + int8_t Varx = 0, Vary = 0; +#define Xmouin (space->MonsterGroupeXpos) +#define Ymouin (space->MonsterGroupeYpos << 3) //-space->DecalageY8 +#define XPlus (Xmouin + 84) +#define YPlus (Ymouin + (4 * 8)) +#define MYSHOOTX (space->MyShootBallxpos) +#define MYSHOOTY ((space->MyShootBall << 3) + ((space->MyShootBallFrame + 1) << 2)) + if ((MYSHOOTX >= Xmouin) && (MYSHOOTX <= XPlus) && (MYSHOOTY >= Ymouin) && (MYSHOOTY <= YPlus)) { + // enter in the monster zone + Vary = (MYSHOOTY - Ymouin + 4) >> 3; + Varx = (MYSHOOTX - Xmouin + 7) / 14; + if (Varx < 0) Varx = 0; + if (Vary < 0) Vary = 0; + if (Varx > 5) return; + if (Vary > 3) return; + if ((space->MonsterGrid[Vary][Varx] > -1) && (space->MonsterGrid[Vary][Varx] < 6)) { + JOY_sound(50, 10); + space->MonsterGrid[Vary][Varx] = 8; + space->MyShootBall = -1; + SpeedControle(space); + } + // fin monster zone } - //fin monster zone - } } int8_t OuDansLaGrilleMonster(uint8_t x, uint8_t y, SPACE *space) { - if(x < space->MonsterGroupeXpos) return -1; - if(y < space->MonsterGroupeYpos) return -1; - space->PositionDansGrilleMonsterX = (x - space->MonsterGroupeXpos) / 14; - space->PositionDansGrilleMonsterY = (y - space->MonsterGroupeYpos); - if(space->PositionDansGrilleMonsterX > 5) return -1; - if(space->PositionDansGrilleMonsterY > 4) return -1; - return 0; + if (x < space->MonsterGroupeXpos) return -1; + if (y < space->MonsterGroupeYpos) return -1; + space->PositionDansGrilleMonsterX = (x - space->MonsterGroupeXpos) / 14; + space->PositionDansGrilleMonsterY = (y - space->MonsterGroupeYpos); + if (space->PositionDansGrilleMonsterX > 5) return -1; + if (space->PositionDansGrilleMonsterY > 4) return -1; + return 0; } uint8_t SplitSpriteDecalageY(uint8_t Input, uint8_t UPorDOWN, SPACE *space) { - if(UPorDOWN) return(Input << space->DecalageY8); - else return(Input >> (8 - space->DecalageY8)); + if (UPorDOWN) + return (Input << space->DecalageY8); + else + return (Input >> (8 - space->DecalageY8)); } uint8_t Murge_Split_UP_DOWN(uint8_t x, SPACE *space) { - int8_t SpriteType = -1; - int8_t ANIMs = -1; - uint8_t Murge1 = 0; - uint8_t Murge2 = 0; - if(space->DecalageY8 == 0) { - SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY][space->PositionDansGrilleMonsterX]; - if(SpriteType < 8) ANIMs = space->anim * 14; - else ANIMs = 0; - if(SpriteType == -1) return 0x00; - return Monsters[(WriteMonster14(x - space->MonsterGroupeXpos) + SpriteType * 14) + ANIMs]; - } - else { - //debut - if(space->PositionDansGrilleMonsterY == 0) { - SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY][space->PositionDansGrilleMonsterX]; - if(SpriteType < 8) ANIMs = space->anim * 14; - else ANIMs = 0; - if(SpriteType != -1) Murge2 = SplitSpriteDecalageY(Monsters[(WriteMonster14(x - space->MonsterGroupeXpos) + SpriteType * 14) + ANIMs], 1, space); - else Murge2 = 0x00; - return Murge2; - } - else { - SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY - 1][space->PositionDansGrilleMonsterX]; - if(SpriteType < 8) ANIMs = space->anim * 14; - else ANIMs = 0; - if(SpriteType != -1) Murge1 = SplitSpriteDecalageY(Monsters[(WriteMonster14(x - space->MonsterGroupeXpos) + SpriteType * 14) + ANIMs], 0, space); - else Murge1 = 0x00; - SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY][space->PositionDansGrilleMonsterX]; - if(SpriteType < 8) ANIMs = space->anim * 14; - else ANIMs = 0; - if(SpriteType != -1) Murge2 = SplitSpriteDecalageY(Monsters[(WriteMonster14(x - space->MonsterGroupeXpos) + SpriteType * 14) + ANIMs], 1, space); - else Murge2 = 0x00; - return(Murge1 | Murge2); - } - } //fin + int8_t SpriteType = -1; + int8_t ANIMs = -1; + uint8_t Murge1 = 0; + uint8_t Murge2 = 0; + if (space->DecalageY8 == 0) { + SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY][space->PositionDansGrilleMonsterX]; + if (SpriteType < 8) + ANIMs = space->anim * 14; + else + ANIMs = 0; + if (SpriteType == -1) return 0x00; + return Monsters[(WriteMonster14(x - space->MonsterGroupeXpos) + SpriteType * 14) + ANIMs]; + } else { + // debut + if (space->PositionDansGrilleMonsterY == 0) { + SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY][space->PositionDansGrilleMonsterX]; + if (SpriteType < 8) + ANIMs = space->anim * 14; + else + ANIMs = 0; + if (SpriteType != -1) + Murge2 = SplitSpriteDecalageY( + Monsters[(WriteMonster14(x - space->MonsterGroupeXpos) + SpriteType * 14) + ANIMs], 1, space); + else + Murge2 = 0x00; + return Murge2; + } else { + SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY - 1][space->PositionDansGrilleMonsterX]; + if (SpriteType < 8) + ANIMs = space->anim * 14; + else + ANIMs = 0; + if (SpriteType != -1) + Murge1 = SplitSpriteDecalageY( + Monsters[(WriteMonster14(x - space->MonsterGroupeXpos) + SpriteType * 14) + ANIMs], 0, space); + else + Murge1 = 0x00; + SpriteType = space->MonsterGrid[space->PositionDansGrilleMonsterY][space->PositionDansGrilleMonsterX]; + if (SpriteType < 8) + ANIMs = space->anim * 14; + else + ANIMs = 0; + if (SpriteType != -1) + Murge2 = SplitSpriteDecalageY( + Monsters[(WriteMonster14(x - space->MonsterGroupeXpos) + SpriteType * 14) + ANIMs], 1, space); + else + Murge2 = 0x00; + return (Murge1 | Murge2); + } + } // fin } uint8_t WriteMonster14(uint8_t x) { - while(x >= 14) x -= 14; - return x; + while (x >= 14) + x -= 14; + return x; } uint8_t Monster(uint8_t x, uint8_t y, SPACE *space) { - if(OuDansLaGrilleMonster(x, y, space) != -1) return Murge_Split_UP_DOWN(x, space); - return 0x00; + if (OuDansLaGrilleMonster(x, y, space) != -1) return Murge_Split_UP_DOWN(x, space); + return 0x00; } uint8_t MonsterRefreshMove(SPACE *space) { - if(space->Direction == 1) { - if(space->MonsterGroupeXpos < space->MonsterOffsetDroite) { - space->MonsterGroupeXpos = space->MonsterGroupeXpos + 2; - return 0; - } - else { - if(space->DecalageY8 < 7) { - space->DecalageY8 = space->DecalageY8 + 4; - if(space->DecalageY8 > 7) space->DecalageY8 = 7; - } - else { - space->MonsterGroupeYpos++; - space->DecalageY8 = 0; - } - space->Direction = 0; - return 0; - } - } - else { - if(space->MonsterGroupeXpos > space->MonsterOffsetGauche) { - space->MonsterGroupeXpos = space->MonsterGroupeXpos - 2; - return 0; - } - else { - if(space->DecalageY8 < 7) { - space->DecalageY8 = space->DecalageY8 + 4; - if(space->DecalageY8 > 7) space->DecalageY8 = 7; - } - else { - space->MonsterGroupeYpos++; - space->DecalageY8 = 0; - } - space->Direction = 1; - return 0; + if (space->Direction == 1) { + if (space->MonsterGroupeXpos < space->MonsterOffsetDroite) { + space->MonsterGroupeXpos = space->MonsterGroupeXpos + 2; + return 0; + } else { + if (space->DecalageY8 < 7) { + space->DecalageY8 = space->DecalageY8 + 4; + if (space->DecalageY8 > 7) space->DecalageY8 = 7; + } else { + space->MonsterGroupeYpos++; + space->DecalageY8 = 0; + } + space->Direction = 0; + return 0; + } + } else { + if (space->MonsterGroupeXpos > space->MonsterOffsetGauche) { + space->MonsterGroupeXpos = space->MonsterGroupeXpos - 2; + return 0; + } else { + if (space->DecalageY8 < 7) { + space->DecalageY8 = space->DecalageY8 + 4; + if (space->DecalageY8 > 7) space->DecalageY8 = 7; + } else { + space->MonsterGroupeYpos++; + space->DecalageY8 = 0; + } + space->Direction = 1; + return 0; + } } - } } void VarResetNewLevel(SPACE *space) { - ShieldRemoved = 0; - SpeedShootMonster = 0; - MONSTERrest = 24; - LoadMonstersLevels(LEVELS, space); - space->Shield[0] = 255; - space->Shield[1] = 255; - space->Shield[2] = 255; - space->Shield[3] = 255; - space->Shield[4] = 255; - space->Shield[5] = 255; - space->MonsterShoot[0] = 16; - space->MonsterShoot[1] = 16; - space->UFOxPos = -120; - - space->MyShootBall = -1; - space->MyShootBallxpos = 0; - space->MyShootBallFrame = 0; - space->anim = 0; - space->frame = 0; - space->PositionDansGrilleMonsterX = 0; - space->PositionDansGrilleMonsterY = 0; - space->MonsterFloorMax = 3; - space->MonsterOffsetGauche = 0; - space->MonsterOffsetDroite = 44; - space->MonsterGroupeXpos = 20; - if(LEVELS > 3) space->MonsterGroupeYpos = 1; - else space->MonsterGroupeYpos = 0; - space->DecalageY8 = 0; - space->frameMax = 8; - space->Direction = 1; //1 right 0 gauche - space->oneFrame = 0; + ShieldRemoved = 0; + SpeedShootMonster = 0; + MONSTERrest = 24; + LoadMonstersLevels(LEVELS, space); + space->Shield[0] = 255; + space->Shield[1] = 255; + space->Shield[2] = 255; + space->Shield[3] = 255; + space->Shield[4] = 255; + space->Shield[5] = 255; + space->MonsterShoot[0] = 16; + space->MonsterShoot[1] = 16; + space->UFOxPos = -120; + + space->MyShootBall = -1; + space->MyShootBallxpos = 0; + space->MyShootBallFrame = 0; + space->anim = 0; + space->frame = 0; + space->PositionDansGrilleMonsterX = 0; + space->PositionDansGrilleMonsterY = 0; + space->MonsterFloorMax = 3; + space->MonsterOffsetGauche = 0; + space->MonsterOffsetDroite = 44; + space->MonsterGroupeXpos = 20; + if (LEVELS > 3) + space->MonsterGroupeYpos = 1; + else + space->MonsterGroupeYpos = 0; + space->DecalageY8 = 0; + space->frameMax = 8; + space->Direction = 1; // 1 right 0 gauche + space->oneFrame = 0; } diff --git a/fw/application/src/app/game/port/tiny_tris/tiny_tris.c b/fw/application/src/app/game/port/tiny_tris/tiny_tris.c index 5bbe8cae..38ace7c3 100644 --- a/fw/application/src/app/game/port/tiny_tris/tiny_tris.c +++ b/fw/application/src/app/game/port/tiny_tris/tiny_tris.c @@ -176,8 +176,14 @@ int tiny_tris_run(void) { } JOY_idle(); + if (JOY_exit()) { + goto EXIT; + } } } + +EXIT: + return 0; } // =================================================================================== @@ -249,6 +255,9 @@ void INTRO_MANIFEST_TTRIS(void) { TIMER_1 = (TIMER_1 < 7) ? TIMER_1 + 1 : 0; Flip_intro_TTRIS(&TIMER_1); JOY_idle(); + if (JOY_exit()) { + return; + } } SND_TTRIS(4); }