From 598b367ccd5877e4d906c32defbb381101f66499 Mon Sep 17 00:00:00 2001 From: flo Date: Tue, 7 Feb 2017 07:46:19 +0100 Subject: [PATCH] =?UTF-8?q?bug=20r=C3=A9gl=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/voiture.h | 2 +- src/voiture.c | 36 ++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/voiture.h b/include/voiture.h index 1f66b2e..97ad75b 100644 --- a/include/voiture.h +++ b/include/voiture.h @@ -30,7 +30,7 @@ unsigned short money; unsigned short essence; unsigned int distance; - unsigned int life; + int life; unsigned char speed; unsigned char decalx; } Voiture; diff --git a/src/voiture.c b/src/voiture.c index 050275b..4caadfc 100644 --- a/src/voiture.c +++ b/src/voiture.c @@ -61,6 +61,7 @@ while(1) case 0 : Jeu(); break; case 1 : /*garage();*/ break; } + break; case KEY_EXIT : return 1; @@ -70,26 +71,32 @@ while(1) int Jeu() { -unsigned short RTC_id; +//unsigned short RTC_id; init(); // initialisation du Jeu -timer_start(TIMER_USER, 45, Clock_Hz, new_frame, 0); -RTC_id = rtc_cb_add(RTCFreq_1Hz, update_essence, 0); +timer_start(TIMER_USER, 16, Clock_Hz, new_frame, 0); +//RTC_id = rtc_cb_add(RTCFreq_16Hz, new_frame, 0); while(1) { - key = getkey(); + //key = getkey(); + + if (voiture.life <= 0) + { + key = KEY_EXIT; + //timer_stop(TIMER_USER); + } + else + { + key = getkey(); + } - if (voiture.life == 0) - { - key = KEY_EXIT; - } switch(key) { case KEY_UP : voiture.corridor=(voiture.corridor<=1 ? 1 : voiture.corridor-1); break; case KEY_DOWN : voiture.corridor=(voiture.corridor>=4 ? 4 : voiture.corridor+1); break; - case KEY_EXIT : timer_stop(TIMER_USER); rtc_cb_end(RTC_id); return 1; + case KEY_EXIT : timer_stop(TIMER_USER); /*rtc_cb_end(RTC_id);*/ return 1; } } } @@ -106,7 +113,7 @@ dclear(); dimage(voiture.decalx-20, 11*voiture.corridor, &img_formel1); dprint(1, 1, "%d", compteur); - +dprint(40, 1, "%d", voiture.life); //Jauge d'essence dline(25+voiture.essence/5, 58, 45, 58, Color_Black); dreverse_area(24, 57, 46, 59); @@ -141,12 +148,17 @@ if(obstacle[voiture.corridor-1].coordx < voiture.decalx - 2 && obstacle[voiture. obstacle[voiture.corridor-1].num_obst = 0; } -if (voiture.essence == 0) +if(compteur%30 == 0 ) + { + voiture.essence -= 1; + } + +if (voiture.essence <= 0) { voiture.life = 0; } -if (voiture.life == 0) +if (voiture.life <= 0) { dclear(); dtext(10,10,"Vous etes mort");