Hey Guys,
I need help with my Arduino project Flappy Bird. The project works so far that the only problem I have is that my bird is not inserted. I want to insert the bird using an ICONS and a UTFT file. The bird I have with an Imageconverter on 32x32 pixels tailored. Here is my program
#include <UTFT.h>
#include <URTouch.h>
#include <EEPROM.h>
//#include <UTFT_Buttons.h>
UTFT myGLCD(ITDB50,38,39,40,41); //Pins müssen an Display Art angepasst werden
URTouch myTouch( 6, 5, 4, 3, 2);
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
//extern unsigned int bird01[0x400]; // Bird Bitmap
int x, y; // Variablen für die Koordianaten wo der Display gedrückt wird
int xP = 798;
int yP = 200;
int yB = 100;
int movingRate = 3;
int fallRateInt = 0;
float fallRate = 0;
int score = 0;
int lastSpeedUpScore = 0;
int highestScore;
boolean screenPressed = false;
boolean gameStarted = false;
void setup() {
// Display Initialisierung
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
highestScore = EEPROM.read(0); // Liest die Höchste Punktzahl der EEPROM
initiateGame();
}
void loop() {
xP=xP-movingRate; // xP - x Position der Röhren; größe: 319 - (-51)
drawPilars(xP, yP); // Zeichnet die Röhren
// yB - y hängt ab von der Fallrate des Vogels
yB+=fallRateInt;
fallRate=fallRate+0.4; // bestimmt die Fallrate des Vogels
fallRateInt= int(fallRate);
// Überprüfen ob der Vogel es durch schafft
if(yB>=360 || yB<=0){ // oben und unten
gameOver();
}
if((xP<=213) && (xP>=13) && (yB<=yP-4)){ // obere Röhre
gameOver();
}
if((xP<=213) && (xP>=13) && (yB>=yP+120)){ // untere Röhre
gameOver();
}
// Vogel
// zeichnet den Vogel(yB);
// Nachdem das Hinderniss den Bildschirm durchflogen hat
if (xP<=-128){
xP=798; // Setzt xP zurück zu 798
yP = rand() % 200+40; // Zufallshöhe der Röhren
score++; // erhöt den Score um eins
}
//Vogel Kontrolle
if (myTouch.dataAvailable()&& !screenPressed) {
fallRate=-6; // Wenn die fallrate negative ist, springt der Vogel
screenPressed = true;
}
// Passt auf, das der Bildschrim gedrückt wird und nicht dauerthaft jemand draufdrückt
else if ( !myTouch.dataAvailable() && screenPressed){
screenPressed = false;
}
// Nach 5 Röhren, wird die Geschwindigkeit erhöht
if ((score - lastSpeedUpScore) == 5) {
lastSpeedUpScore = score;
movingRate++;
}
}
// Benutzereinstellungen
void initiateGame() {
myGLCD.clrScr();
// Hintergrundfarbe ( Blau)
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(0,0,798,478);
// Boden (Grün)
myGLCD.setColor(221,216,148);
myGLCD.fillRect(0, 430, 798, 478);
myGLCD.setColor(47,175,68);
myGLCD.fillRect(0, 410, 798, 428);
// Text
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(221, 216, 148);
myGLCD.setFont(BigFont);
myGLCD.print("Score:",13,440);
myGLCD.setFont(BigFont);
myGLCD.print("Neumaier,Niklas", 350, 440);
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(114, 198, 206);
myGLCD.print("Highest Score: ",13,10);
myGLCD.printNumI(highestScore, 300, 12);
myGLCD.print(">RESET<",638,10);
myGLCD.drawLine(0,46,798,46);
myGLCD.setFont(BigFont);
myGLCD.print("TAB TO START",CENTER,200);
// Zeichnet den Vogel
// Wartet bis der Bildschrim gedrückt wird
while (!gameStarted) {
if (myTouch.dataAvailable()) {
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
// Setzt den Highscore zurück
if ((x>=625) && (x<=798) &&(y>=0) && (y<=56)) {
highestScore = 0;
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(300, 0, 375, 44);
myGLCD.setColor(0, 0, 0);
myGLCD.printNumI(highestScore, 300, 10);
}
if ((x>=0) && (x<=798) &&(y>=60) && (y<=478)) {
gameStarted = true;
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(0, 0, 798, 64);
}
}
}
// Löscht den Text "TAP TO START" bevor das Spiel losgeht
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(213, 200, 588, 332);
}
// Zeichnet Hindernisse
void drawPilars(int x, int y) {
if (x>=675){
myGLCD.setColor(0, 200, 20);
myGLCD.fillRect(795, 0, x, y-1);
myGLCD.setColor(0, 0, 0);
myGLCD.drawRect(795, 0, x-1, y);
myGLCD.setColor(0, 200, 20);
myGLCD.fillRect(795, y+162, x, 406);
myGLCD.setColor(0, 0, 0);
myGLCD.drawRect(795, y+160, x-1, 408);
}
else if( x<=670) {
// Zeichnet Blauen Winkel rechts vom Hinderniss
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(x+128, 0, x+150, y);
// Zeichnet Hinderniss
myGLCD.setColor(0, 200, 20);
myGLCD.fillRect(x+123, 1, x+3, y-1);
// Zeichnet die Schattierung der Hindernisse
myGLCD.setColor(0, 0, 0);
myGLCD.drawRect(x+125, 0, x, y);
// Zeichnet Blauen Winkel links vom Hinderniss
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(x-3, 0, x-6, y);
// Bodenhinderniss
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(x+128, y+160, x+150, 408);
myGLCD.setColor(0, 200, 20);
myGLCD.fillRect(x+123, y+162, x+3, 406);
myGLCD.setColor(0, 0, 0);
myGLCD.drawRect(x+125, y+160, x, 408);
myGLCD.setColor(114, 198, 206);
myGLCD.fillRect(x-3, y+160, x-8, 408);
}
// Zeichnet den Score
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(221, 216, 148);
myGLCD.setFont(BigFont);
myGLCD.printNumI(score, 250, 440);
}
// Zeichnet den Vogel
void drawBird(int y) {
// zeichnet der Vogel - bitmap
myGLCD.drawBitmap (50, y, 32, 32, bird01);
// Zeichnet markierungen um den Vogel herum
myGLCD.setColor(114, 198, 206);
myGLCD.fillRoundRect(50,y,85,y-6);
myGLCD.fillRoundRect(50,y+30,85,y+36);
}
//Spiel vorbei
void gameOver() {
delay(3000);
// Löscht den Bildschrim und schreibt den Text
myGLCD.clrScr();
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(BigFont);
myGLCD.print("GAME OVER", CENTER, 80);
myGLCD.print("Score:", 250, 160);
myGLCD.printNumI(score,400, 160);
myGLCD.print("Restarting...", CENTER, 240);
myGLCD.setFont(SevenSegNumFont);
myGLCD.printNumI(2,CENTER, 300);
delay(1000);
myGLCD.printNumI(1,CENTER, 300);
delay(1000);
// Schreibt die höchste Puntkzahl in die EEPROM
if (score > highestScore) {
highestScore = score;
EEPROM.write(0,highestScore);
}
// Setzt die Variablen zurück
xP=798;
yB=100;
fallRate=0;
score = 0;
lastSpeedUpScore = 0;
movingRate = 3;
gameStarted = false;
// Spiel starten von Neu
initiateGame();
}
Hope you can help me,
Peter