sons + bouton ajout de temps

master
Maxime André-Masse 2 years ago
parent 69126dcc05
commit 8fcbc10dd4

@ -32,6 +32,7 @@ LIS3DHTR<TwoWire> lis;
// Paramètres du jeu :
bool isGameRunning = false;
int rep = 1;
unsigned long lastButtonPressTime = 0;
unsigned long lastTimeDecrement = 0; // Stocke le moment où la dernière seconde a été décrémentée
unsigned long timeInterval = 1000; // Interval de temps en millisecondes (1000 ms = 1 seconde)
@ -103,7 +104,70 @@ float accX, accY;
float distance(int x1, int y1, int x2, int y2) {
void addsound(int number){ // GESTION DU SON
switch (number)
{
pinMode(WIO_BUZZER, OUTPUT);
case 0:
// SON DE CHOIX DE NIVEAU
analogWrite(WIO_BUZZER,100);
delay(100);
analogWrite(WIO_BUZZER,0);
delay(100);
analogWrite(WIO_BUZZER,100);
delay(100);
analogWrite(WIO_BUZZER,0);
delay(100);
analogWrite(WIO_BUZZER,100);
delay(100);
analogWrite(WIO_BUZZER,0);
break;
case 1:
// SON LORS DE PIECE JAUNE
for(int i=0; i< 1000000 ; i+=1014 *2){
digitalWrite(WIO_BUZZER, HIGH);
delayMicroseconds(900);
digitalWrite(WIO_BUZZER, LOW);
delayMicroseconds(900);
}
break;
case 2:
// SON LORS DE PIECE NOIRE
for(int i=0; i< 1000000 ; i+=1014 *2){
digitalWrite(WIO_BUZZER, HIGH);
delayMicroseconds(1100);
digitalWrite(WIO_BUZZER, LOW);
delayMicroseconds(1100);
}
break;
case 3:
// SON LORS DE FIN DE NIVEAU
analogWrite(WIO_BUZZER,128);
analogWrite(WIO_BUZZER,0);
break;
case 4:
for(int i=0; i< 1000000 ; i+=500 *2){
digitalWrite(WIO_BUZZER, HIGH);
delayMicroseconds(500);
digitalWrite(WIO_BUZZER, LOW);
delayMicroseconds(1100);
}
break;
}
}
void checkButtonAState(){ // GESTION AJOUT DE TEMPS
int buttonState=digitalRead(WIO_KEY_A);
if (buttonState==LOW && rep == 1){
timeLeft=timeLeft+10;
rep=2;
}
}
float distance(int x1, int y1, int x2, int y2){
return sqrt(sq(x2 - x1) + sq(y2 - y1));
}
@ -141,6 +205,7 @@ void checkButtonState() {
if(buttonState == LOW && isGameRunning == false){
lastTimeDecrement = millis();
addsound(0);
resetGame();
}
}
@ -184,6 +249,7 @@ void checkTime() {
}
// Si le temps est écoulé, arrêtez le jeu
if (timeLeft <= 0) {
addsound(3);
isGameRunning = false;
}
}
@ -234,13 +300,16 @@ void checkColision() {
currentPieces[i].isCollected = true;
tft.fillCircle(currentPieces[i].x, currentPieces[i].y, 5, TFT_DARKGREY);
if (currentPieces[i].isBlack) {
timeLeft -= 10; // Enlève 5 secondes
} else {
timeLeft -= 10; // Enlève 5 secondes
addsound(2);
}
else {
addsound(1);
srand(time(0));
int points_ajoutes = rand() % 16 + 10; // tire un entier au sort aléatoirement entre 10 et 25
score += points_ajoutes; //ajoute le score de la pièce au score de la partie
}
}
}
}
@ -310,12 +379,9 @@ void loop() {
if(isGameRunning){
updateBallPosition();
checkTime();
checkButtonAState();
}
else tft.fillCircle(ballX, ballY, ballRadius, TFT_RED);
updateBanner(); // Mettre à jour le bandeau dans chaque boucle, que le jeu soit en cours ou non
checkColision();
}

Loading…
Cancel
Save