|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
#include <TFT_eSPI.h> // Include the library for the LCD screen
|
|
|
|
|
#include <TFT_eSPI.h>
|
|
|
|
|
#include <LIS3DHTR.h>
|
|
|
|
|
|
|
|
|
|
TFT_eSPI tft = TFT_eSPI(); // Create an instance of the library
|
|
|
|
|
TFT_eSPI tft = TFT_eSPI();
|
|
|
|
|
LIS3DHTR<TwoWire> lis;
|
|
|
|
|
//Constantes :
|
|
|
|
|
//couleurs :
|
|
|
|
|
#define TFT_BLACK 0x0000 /* 0, 0, 0 */
|
|
|
|
@ -22,36 +24,100 @@ TFT_eSPI tft = TFT_eSPI(); // Create an instance of the library
|
|
|
|
|
#define TFT_ORANGE 0xFDA0 /* 255, 180, 0 */
|
|
|
|
|
#define TFT_GREENYELLOW 0xB7E0 /* 180, 255, 0 */
|
|
|
|
|
|
|
|
|
|
// Parameters for the game
|
|
|
|
|
String level = "Novice"; // Example for level
|
|
|
|
|
int score = 0; // Initial score
|
|
|
|
|
int timeLeft = 30; // Initial time
|
|
|
|
|
#define SPEEDGAME 100
|
|
|
|
|
// Paramètres du jeu :
|
|
|
|
|
|
|
|
|
|
int score = 0; // Initialisation du score
|
|
|
|
|
int timeLeft = 30; // Initialisation du timer
|
|
|
|
|
String oldLevel = ""; // Niveau précédent
|
|
|
|
|
int oldScore = -1; // Score précédent
|
|
|
|
|
int oldTimeLeft = -1; // Temps précédent
|
|
|
|
|
String level = "Novice"; // Initialisation du niveau (changeable après)
|
|
|
|
|
int ballRadius = 7; // rayon de la boule rouge
|
|
|
|
|
int ballX = 160; // coordonné x du centre de la boule
|
|
|
|
|
int ballY = 120; // coordonné y du centre de la boule
|
|
|
|
|
int oldBallX = ballX; // stocker les anciennes coordonnées de la balle
|
|
|
|
|
int oldBallY = ballY; // stocker les anciennes coordonnées de la balle
|
|
|
|
|
|
|
|
|
|
// variable pour stocker les données de l'accèléromètre
|
|
|
|
|
float accX, accY;
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
tft.begin(); // Start the screen
|
|
|
|
|
tft.setRotation(3); // Rotate the screen to the correct orientation
|
|
|
|
|
tft.begin(); // Démarage de l'écran
|
|
|
|
|
tft.setRotation(3); // Oriente l'écran dans le bon sens
|
|
|
|
|
|
|
|
|
|
// Draw the blue banner
|
|
|
|
|
// dessine la bannière bleu
|
|
|
|
|
tft.fillRoundRect(0, 0, 320, 40, 0, TFT_BLUE);
|
|
|
|
|
tft.fillRoundRect(0, 40, 320, 200, 0, TFT_DARKGREY);
|
|
|
|
|
|
|
|
|
|
// Set the color and size of the text
|
|
|
|
|
//set la couleur du text
|
|
|
|
|
tft.setTextColor(TFT_WHITE, TFT_BLUE);
|
|
|
|
|
tft.setTextSize(2);
|
|
|
|
|
|
|
|
|
|
// Display the level, score and time
|
|
|
|
|
// Affichage du niveau, score et timer
|
|
|
|
|
tft.drawString(level, 10, 10);
|
|
|
|
|
tft.drawString(String(score)+" pts", 160, 10);
|
|
|
|
|
tft.drawString(String(timeLeft), 290, 10);
|
|
|
|
|
|
|
|
|
|
//dessine la boule rouge :
|
|
|
|
|
tft.fillCircle(ballX, ballY, ballRadius, TFT_RED);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
lis.begin(Wire1);
|
|
|
|
|
if (!lis) {
|
|
|
|
|
while (1);
|
|
|
|
|
}
|
|
|
|
|
lis.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
|
|
|
|
|
lis.setFullScaleRange(LIS3DHTR_RANGE_2G);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateBanner() {
|
|
|
|
|
// Vérifier si les valeurs ont changé
|
|
|
|
|
if (level != oldLevel || score != oldScore || timeLeft != oldTimeLeft) {
|
|
|
|
|
// Actualiser le bandeau
|
|
|
|
|
tft.fillRoundRect(0, 0, 320, 40, 0, TFT_BLUE);
|
|
|
|
|
tft.drawString(level, 10, 10);
|
|
|
|
|
tft.drawString(String(score) + " pts", 160, 10);
|
|
|
|
|
tft.drawString(String(timeLeft), 290, 10);
|
|
|
|
|
// Mettre à jour les valeurs précédentes
|
|
|
|
|
oldLevel = level;
|
|
|
|
|
oldScore = score;
|
|
|
|
|
oldTimeLeft = timeLeft;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
// Update the score and time every second
|
|
|
|
|
delay(1000);
|
|
|
|
|
tft.fillRoundRect(0, 0, 320, 40, 0, TFT_BLUE);
|
|
|
|
|
tft.drawString(level, 10, 10);
|
|
|
|
|
tft.drawString(String(score)+" pts", 160, 10);
|
|
|
|
|
tft.drawString(String(timeLeft), 290, 10);
|
|
|
|
|
delay(10);
|
|
|
|
|
// Lire les données de l'accéléromètre
|
|
|
|
|
accX = -lis.getAccelerationY();
|
|
|
|
|
accY = lis.getAccelerationX();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Nettoyer l'ancienne position de la balle
|
|
|
|
|
tft.fillCircle(oldBallX, oldBallY, ballRadius, TFT_DARKGREY);
|
|
|
|
|
|
|
|
|
|
// Déplacer la balle en fonction des données de l'accéléromètre
|
|
|
|
|
ballX += accX * SPEEDGAME;
|
|
|
|
|
ballY += accY * SPEEDGAME;
|
|
|
|
|
|
|
|
|
|
// Limiter les positions de la balle à l'intérieur de la zone de jeu
|
|
|
|
|
if (ballX < 0 + ballRadius) ballX = ballRadius;
|
|
|
|
|
if (ballX > 320 - ballRadius) ballX = 320 - ballRadius;
|
|
|
|
|
if (ballY < 40 + ballRadius) ballY = 40 + ballRadius;
|
|
|
|
|
if (ballY > 240 - ballRadius) ballY = 240 - ballRadius;
|
|
|
|
|
|
|
|
|
|
// Actualisation de l'affichage toutes les secondes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Mettre à jour le bandeau si nécessaire
|
|
|
|
|
updateBanner();
|
|
|
|
|
|
|
|
|
|
// Dessiner la nouvelle position de la balle
|
|
|
|
|
tft.fillCircle(ballX, ballY, ballRadius, TFT_RED);
|
|
|
|
|
|
|
|
|
|
// Update the game parameters here
|
|
|
|
|
// ...
|
|
|
|
|
// Mettre à jour les anciennes coordonnées de la balle
|
|
|
|
|
oldBallX = ballX;
|
|
|
|
|
oldBallY = ballY;
|
|
|
|
|
}
|
|
|
|
|