#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include "pitches.h"
// JOSTICK CONFIGURATION
#define VERT_PIN A1 // Vertical
#define HORZ_PIN A2 // Horizontal
#define SEL_PIN 2 // Pushbutton
// BUZZER CONFIGURATION
#define BuzzPin 7 // Buzzer for sound
// ADAFRUIT DISPLAY CONFIGURATION
#define TFT_SCK 52
#define TFT_MISO 50
#define TFT_MOSI 51
#define TFT_DC 8
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCK, TFT_MISO);
// declaration of range depending on randomly chosen zone
int zone [4] = {random(9,56),random(80,136),random(160,216),random(240,287)};
int ZoneMann;
int ZoneMann2;
int ZoneMann3;
int ZoneHerz;
// FIGUREN (array von bitmap)
// 'Torro', 23x20px
const uint16_t bitmap_Torro [] PROGMEM = {
0x0000, 0x0000, 0x93e0, 0xff0c, 0xe8e4, 0x8802, 0x8802, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x8802, 0x8802, 0xe8e4, 0xff0c, 0x93e0, 0x0000, 0x0000, 0x0000, 0xff0c, 0xff0c, 0xe8e4, 0xe8e4, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xe8e4, 0xe8e4, 0xff0c, 0xff0c, 0x0000, 0x93e0, 0xff0c,
0xff0c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0xff0c, 0xff0c, 0x93e0, 0x93e0, 0xff0c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xff0c, 0x93e0, 0xff0c, 0xff0c, 0x0000, 0x0000,
0x0000, 0x0000, 0x8286, 0x8286, 0x8286, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8286, 0x8286, 0x8286, 0x0000, 0x0000, 0x0000,
0x0000, 0xff0c, 0xff0c, 0xff0c, 0x0000, 0x0000, 0x0000, 0x8286, 0x8286, 0x8286, 0x8286, 0x8286, 0x8286, 0x8286, 0x8286, 0x8286,
0x8286, 0x8286, 0x8286, 0x8286, 0x8286, 0x8286, 0x0000, 0x0000, 0x0000, 0xff0c, 0xff0c, 0x8286, 0xff0c, 0xbbca, 0xbbca, 0xbbca,
0x8286, 0x8286, 0x8286, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0x8286, 0x8286, 0x8286, 0xbbca, 0xbbca, 0xbbca, 0xff0c, 0x8286,
0xff0c, 0xff0c, 0x8286, 0xff0c, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0x8286, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0x8286,
0xbbca, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0xff0c, 0x8286, 0xff0c, 0x0000, 0x93e0, 0x8286, 0x8286, 0x8286, 0x8286, 0xbbca, 0x8802,
0x8802, 0x8802, 0x8802, 0xbbca, 0x8802, 0x8802, 0x8802, 0x8802, 0xbbca, 0xbbca, 0x8286, 0x8286, 0x8286, 0x93e0, 0x0000, 0x0000,
0x0000, 0x0000, 0x8286, 0x0000, 0x8286, 0xbbca, 0xbbca, 0xf800, 0xffeb, 0x8802, 0xbbca, 0x8802, 0xffeb, 0xf800, 0xbbca, 0xbbca,
0x8286, 0x0000, 0x8286, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8286, 0xbbca, 0xbbca, 0xbbca, 0xf800,
0x8802, 0xbbca, 0x8802, 0xf800, 0xbbca, 0xbbca, 0xbbca, 0x8286, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x8286, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0x8802, 0xbbca, 0x8802, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0x8286, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8286, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0x8802, 0xbbca,
0x8802, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0x8286, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x8286, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0xbbca, 0x8286, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8286, 0xbbca, 0x8286, 0x8286, 0x8286, 0x8286, 0x8286,
0xbbca, 0x8286, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x8286, 0xbbca, 0xfe43, 0x8286, 0x8286, 0x8286, 0xfe43, 0xbbca, 0x8286, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8286, 0xfe43, 0x7800, 0x8286, 0x8286, 0x8286, 0x7800, 0xfe43, 0x8286,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe43,
0x8286, 0x8286, 0x8286, 0x8286, 0x8286, 0xfe43, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe43, 0x0000, 0x0000, 0x0000, 0xfe43, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe43,
0xfe43, 0xfe43, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
// 'Mann', 23x20px
const uint16_t bitmap_Mann [] PROGMEM = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3a59, 0x3a59, 0x3a59, 0x3a59, 0x3a59, 0x3a59, 0x3a59, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xfd0a, 0xffff, 0xfd0a, 0xffff, 0xfd0a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd0a, 0xfd0a, 0xfd0a,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0xfd0a, 0x0000, 0xfd0a, 0xfd0a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd0a, 0xffff,
0xffff, 0xffff, 0xfd0a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd0a, 0xfcd6, 0xfcd6, 0xfcf7, 0xfd0a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a,
0xfd0a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd0a, 0xfd0a, 0xfd0a, 0x0000, 0x0000, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0x0000,
0x0000, 0x0000, 0x0000, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0x0000,
0x0000, 0x0000, 0x0000, 0xfd0a, 0xfd0a, 0xfd0a, 0xf800, 0xf800, 0x0000, 0x197f, 0xf800, 0xf800, 0xf800, 0xf800, 0x18df, 0x0000,
0xf800, 0xf800, 0xfd0a, 0xfd0a, 0xfd0a, 0xfd0a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd0a, 0xfd0a, 0xf800, 0xf800, 0xf800,
0x197f, 0xf800, 0xf800, 0x0000, 0xf800, 0x18df, 0xf800, 0xf800, 0xf800, 0xfd0a, 0xfd0a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0xf800, 0xf800, 0xf800, 0xf800, 0x197f, 0xf800, 0xf800, 0xf800, 0xf800, 0x18df, 0xf800, 0xf800, 0xf800,
0xf800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf800, 0xf800, 0xf800, 0x197f, 0xf800,
0xf800, 0x0000, 0xf800, 0x18df, 0xf800, 0xf800, 0xf800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0xf800, 0xf800, 0x197f, 0xf800, 0xf800, 0xf800, 0xf800, 0x18df, 0xf800, 0xf800, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf800, 0xf800, 0x197f, 0xf800, 0xf800, 0x0000,
0xf800, 0x18df, 0xf800, 0xf800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0xf800, 0xf800, 0x197f, 0xf800, 0xf800, 0xf800, 0xf800, 0x18df, 0xf800, 0xf800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x197f, 0x197f, 0x197f, 0x197f, 0x197f, 0x197f, 0x197f, 0x18df,
0x197f, 0x18df, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7ef,
0xf7ef, 0x197f, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0x18df, 0xf7ef, 0xf7ef, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7ef, 0xf7ef, 0x197f, 0xf7ef, 0x0000, 0x0000, 0xf7ef, 0x18df, 0xf7ef, 0xf7ef,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7ef, 0xf7ef, 0x197f,
0x0000, 0x0000, 0x0000, 0x0000, 0x18df, 0xf7ef, 0xf7ef, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x18bf, 0x18bf, 0xfd05, 0xfd05, 0xfd05, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd05, 0xfd05, 0xfd05, 0x18bf, 0x18bf,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x18bf, 0x18bf, 0x18bf, 0xfd05, 0xfd05, 0x0000, 0x0000,
0x0000, 0x0000, 0xfd05, 0xfd05, 0x18bf, 0x18bf, 0x18bf, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
// 'Mann2', 23x20px
const uint16_t bitmap_Mann2 [] PROGMEM = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xe8e4, 0xe8e4, 0xe8e4, 0xe8e4, 0xe8e4, 0xe8e4, 0xe8e4, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xfe15, 0x3a59, 0xfdf5, 0x3a59, 0xfdf5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfeb8, 0xfeb8, 0xfe15,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfdf5, 0xfdf5, 0xfdf5, 0xfdf5, 0xfdf5, 0xfe15, 0xfdf5, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0xfe15, 0x0000, 0xff19, 0xff19, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xff19, 0xffff,
0xffff, 0xffff, 0xfdf5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfeb8, 0xff19, 0xff19, 0xff19, 0xff19, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xff19, 0xfcd6, 0xfcd6, 0xfcf7, 0xfdf5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xff19, 0xff19, 0xff19, 0xfdd3, 0xff19, 0xff19, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe15, 0xff19, 0xff19, 0xfe15,
0xfdf5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xff19, 0xff19, 0xfe15, 0x0000, 0x0000, 0xfdd3, 0xff19, 0xff19, 0xfdd3, 0x0000,
0x0000, 0x0000, 0x0000, 0xfe15, 0xfe15, 0xfe15, 0xfe15, 0x0000, 0x0000, 0x0000, 0x0000, 0xfdd3, 0xfdd3, 0xff19, 0xfe15, 0x0000,
0x0000, 0x0000, 0x0000, 0xfdd3, 0xff19, 0xfdd3, 0xf800, 0xf800, 0x0000, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0x0000,
0xf800, 0xf800, 0xfdd3, 0xff37, 0xff19, 0xfe15, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xff19, 0xff19, 0xf800, 0xf800, 0xf800,
0xf800, 0xf800, 0xf800, 0x0000, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xfdd3, 0xff19, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800,
0xf800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800,
0xf800, 0x0000, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0x0000,
0xf800, 0xf800, 0xf800, 0xf800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0xf800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef,
0xf7ef, 0xf7ef, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7ef,
0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef, 0x0000, 0x0000, 0xf7ef, 0xf7ef, 0xf7ef, 0xf7ef,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7ef, 0xf7ef, 0xf7ef,
0x0000, 0x0000, 0x0000, 0x0000, 0xf7ef, 0xf7ef, 0xf7ef, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0xfa02, 0xfd05, 0xfd05, 0xfd05, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd05, 0xfd05, 0xfd05, 0xfa02, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfa02, 0xfa02, 0xfd05, 0xfd05, 0xfd05, 0x0000, 0x0000,
0x0000, 0x0000, 0xfd05, 0xfd05, 0xfd05, 0xfa02, 0xfa02, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
// 'Herz', 23x20px
const uint16_t bitmap_Herz [] PROGMEM = {
0x0000, 0x0000, 0x0000, 0x31df, 0x457f, 0x459f, 0x459f, 0x459f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x459f, 0x459f,
0x459f, 0x457f, 0xcf5f, 0x2cea, 0x0000, 0x0000, 0x0000, 0x0000, 0x459f, 0x350c, 0x350d, 0xbf39, 0x352c, 0x456b, 0x350b, 0x350c,
0x0000, 0x0000, 0x0000, 0x0000, 0x350d, 0x2cea, 0x350c, 0x7e52, 0x350d, 0x350c, 0x55b0, 0x350c, 0x0000, 0x0000, 0x352c, 0x350d,
0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xa72d, 0x0000, 0x0000, 0x350c, 0xc774, 0xa72d, 0xa72d, 0xa72d, 0x350c,
0xa72d, 0xa72d, 0xa72d, 0xa72d, 0x0000, 0x9e03, 0x9e25, 0xe797, 0x9e25, 0xa624, 0x9e03, 0x9e25, 0xa604, 0x9e04, 0xa72d, 0x350c,
0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xa72d, 0xaf2e, 0x0000, 0xfffd, 0xeeeb, 0xeecb, 0xeeeb,
0xeecb, 0xeecb, 0xd688, 0xa624, 0x9e24, 0xa72e, 0xa72d, 0xa72c, 0xa72d, 0x9f0b, 0xa624, 0x9de3, 0xa6c9, 0x9e04, 0xa624, 0xa625,
0xffff, 0xa72c, 0x0000, 0xeeec, 0xeeeb, 0xeeeb, 0xeecb, 0xeeeb, 0xf732, 0xeecc, 0xeeec, 0xeecb, 0xeeeb, 0xeecb, 0xeecb, 0xeecb,
0xeecb, 0xeecb, 0xeecb, 0xce87, 0xeecb, 0xeeed, 0xeeeb, 0xeecb, 0xffba, 0xeecb, 0xeeeb, 0xeeec, 0xeeeb, 0xeeec, 0xeeec, 0xeeeb,
0xeecb, 0xeeec, 0xeecb, 0xf732, 0xeecb, 0xeeeb, 0xeeeb, 0xeecb, 0xeeeb, 0xeecb, 0xeeec, 0xeeec, 0xeeeb, 0xeecb, 0xeeeb, 0xeeeb,
0xeeeb, 0xeecb, 0xeecb, 0xeecb, 0xeeec, 0xeecb, 0xeeec, 0xeecb, 0xeeeb, 0xeeeb, 0xeeeb, 0xf732, 0xeeeb, 0xeecb, 0xeeeb, 0xeecb,
0xf755, 0xeecb, 0xeecb, 0xed04, 0xeca3, 0xecc3, 0xecc3, 0x0000, 0xecc3, 0xeca3, 0xf4a3, 0xeca3, 0xeca2, 0xeca3, 0xeeca, 0xeecb,
0xeecb, 0xeeeb, 0xeecb, 0xeecb, 0xeecb, 0xec82, 0xeca3, 0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xfef6, 0xfbc2, 0xfbe2, 0x0000, 0x0000,
0xfd89, 0xfd89, 0xfd89, 0xfd69, 0xfd88, 0xfd89, 0xfd26, 0xeba1, 0xecc3, 0xeba1, 0xeca3, 0xfd69, 0xfd89, 0xfd89, 0xfeb7, 0xffde,
0xfbe3, 0xfd89, 0xf926, 0xfe72, 0xf946, 0x0000, 0x0000, 0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xfd89,
0xfd89, 0xfd89, 0xfed5, 0xfd89, 0xfd89, 0xfa87, 0xf986, 0xf986, 0xfa74, 0xfa33, 0xfa54, 0x0000, 0x0000, 0x0000, 0x0000, 0xf966,
0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xfd89, 0xf986, 0xf8c6, 0xf9a6, 0xf966, 0xfa54, 0xfa74, 0xfa74, 0xfa74,
0xfa74, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf986, 0xf966, 0xf986, 0xf986, 0xf986, 0xf9a6, 0xffdf, 0xfd89, 0xf9a6,
0xfa54, 0xfa74, 0xfa74, 0xfa54, 0xf2f5, 0xfa74, 0xc875, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfa74,
0xfa74, 0xf987, 0xf986, 0xf9a7, 0xfa74, 0xfa74, 0xfa74, 0xfa74, 0xfa74, 0xfa74, 0xfa74, 0xfa75, 0xda98, 0xc895, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfa74, 0xfa74, 0xf9ad, 0xf966, 0xf946, 0xfa74, 0xfa74, 0xfa74, 0xfa54, 0xfa54,
0xc895, 0xf9f3, 0xc8b4, 0xd27f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf88d, 0xc855,
0xc8b5, 0xc875, 0xc895, 0xfa74, 0xffdf, 0xc8d8, 0xd27f, 0xd25f, 0xd27f, 0xd27f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xd25f, 0xd27f, 0xd27f, 0xd27f, 0xc875, 0xd27f, 0xd27f, 0xd27f, 0xd25f, 0xd25f,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xd27f, 0xc875, 0xffdf, 0xd25f, 0x31de, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x31de, 0x29df, 0x31ff, 0x29df, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5ddf,
0x5ddf, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
// 'Mann3', 23x20px
const uint16_t bitmap_Mann3 [] PROGMEM = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7903, 0x7903, 0x7903, 0x7903, 0x7903, 0x7903, 0x7903, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7903,
0x8200, 0x4be4, 0x8200, 0x43e6, 0x8200, 0x7903, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8200, 0x8200, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7903, 0x8200, 0x8200, 0x8200, 0x8200, 0x8200, 0x7903, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x8200, 0x0000, 0x8200, 0x8200, 0x0000, 0x8200, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7903, 0x8200, 0xffff,
0xffff, 0xffff, 0x8200, 0x7903, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8200, 0x8200, 0x8200, 0x8200, 0x8200, 0x8200, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x7903, 0x0000, 0x8200, 0x8200, 0x8200, 0x0000, 0x7903, 0x0000, 0x0000, 0x0000, 0x0000, 0x8200,
0x8200, 0x8200, 0x0000, 0x0000, 0x8200, 0x8200, 0x8200, 0x0000, 0x0000, 0xfd79, 0x0000, 0x0000, 0x0000, 0xfd79, 0xfd79, 0xfd79,
0x0000, 0x0000, 0xfd79, 0x0000, 0x0000, 0x8200, 0x8200, 0x8200, 0x0000, 0x0000, 0x0000, 0x0000, 0x8200, 0x8200, 0x8200, 0xfd79,
0xfd79, 0xfd79, 0x0000, 0x0000, 0xfd79, 0x0000, 0xfd79, 0x0000, 0xfd79, 0xfd79, 0xfd79, 0x8200, 0x8200, 0x8200, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8200, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79,
0xfd79, 0xfd79, 0xfd79, 0xfd79, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd79, 0xfd79,
0xfd79, 0xfd79, 0xfd79, 0x0000, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd79, 0xfd79,
0xfd79, 0x0000, 0xfd79, 0xfd79, 0xfd79, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd79, 0xfd79, 0xfd79, 0xfd79,
0xfd79, 0xfd79, 0xfd79, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79,
0xfd79, 0xfd79, 0xfd79, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd79, 0xfd79,
0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8200, 0x0000, 0x0000, 0x0000, 0x0000, 0x8200, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8200, 0x8200,
0x0000, 0x0000, 0x0000, 0x0000, 0x8200, 0x8200, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0xfd79, 0x8200, 0x8200, 0x8200, 0x0000, 0x0000, 0x0000, 0x0000, 0x8200, 0x8200, 0x8200, 0xfd79, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0x0000, 0x0000,
0x0000, 0x0000, 0xfd79, 0xfd79, 0xfd79, 0xfd79, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
// SCORE, LIVES, GAMESTATE
const unsigned int yInfo = 0;
const unsigned int wInfo = 25;
const unsigned int hInfo = 17;
const unsigned int xScore = 80;
const unsigned int xLives = 293;
unsigned int score = 0;
unsigned int lives = 3;
bool gameState = false;
// X,Y,W,H FIGURES
//Starting Position for all falling figures
unsigned int figureWidth = 23;
unsigned int figureHeight = 20;
unsigned int startingPosition = 27;
// Torro_Logo
unsigned int xTorro_Logo = 50;
unsigned int yTorro_Logo = 50;
//The player = Torro
unsigned int xTorro = 155;
unsigned int yTorro =210;
#define MOVE_TORRO 17
//Herz
unsigned int xHerz = random(0,300);
unsigned int yHerz = startingPosition;
#define MOVE_HERZ 13
//Mann
unsigned int xMann = random(0,300);
unsigned int yMann = startingPosition;
#define MOVE_MANN 10
//Mann2
unsigned int xMann2 = random(0,300);
unsigned int yMann2 = startingPosition;
#define MOVE_MANN2 5
//Mann3
unsigned int xMann3 = random(0,300);
unsigned int yMann3 = startingPosition;
#define MOVE_MANN3 9
// CANVAS CONFIGURATION
GFXcanvas16 canvas_figuren(figureWidth, figureHeight);
void setup() {
// SCREEN INITIATION
tft.begin(); //initialize screen
tft.setRotation(3); //rotate screen
tft.fillScreen(0x0000); //make beginning screen black
canvas_figuren.fillScreen(0x0000); //make initial canvas black
// INTRO
tft.setTextSize(4);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(30, 20);
tft.println("Game Time!");
tft.setTextSize(4);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(30, 85);
tft.println("Ready?!");
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(30, 140);
tft.println("Move joystick!");
tft.setCursor(30, 160);
tft.println("Catch matadors!");
tft.setCursor(30, 180);
tft.println("You're the bull!");
tft.setCursor(30, 200);
tft.println("Oleeee...");
delay(1200);
tft.fillScreen(ILI9341_BLACK);
// JOYSTICK INPUT
pinMode(VERT_PIN, INPUT);
analogWrite(VERT_PIN, LOW);
pinMode(HORZ_PIN, INPUT);
analogWrite(HORZ_PIN, LOW);
pinMode(SEL_PIN, INPUT_PULLUP);
digitalWrite(SEL_PIN, LOW);
// RANDOM NUMBER SETUP
randomSeed(analogRead(0));
// STATIC ELEMENTS ON SCREEN
tft.setTextSize(2);
tft.setTextColor(ILI9341_RED);
tft.setCursor(0, 0);
tft.print("Score: ");
tft.print(score);
tft.setCursor(210, 0);
tft.print("Lives: ");
tft.print(lives);
tft.setTextSize(1);
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(125,3);
tft.print("El Matador");
//Statiks Frame
tft.fillRect(0,18,317,3,ILI9341_RED); //upper Hori.
tft.fillRect(3,21,317,3,ILI9341_YELLOW); //middle Hori.
tft.fillRect(6,24,317,3,ILI9341_RED); //lower Hori.
tft.fillRect(0,21,3,240,ILI9341_RED); //outter Verti. left
tft.fillRect(3,24,3,240,ILI9341_YELLOW); //middle Verti. left
tft.fillRect(6,24,3,240,ILI9341_RED); //inner Verti. left
tft.fillRect(317,18,3,240,ILI9341_RED); //outter Verti. right
tft.fillRect(314,24,3,240,ILI9341_YELLOW); // middle Verti. right
tft.fillRect(311,24,3,240,ILI9341_RED); // inner Verti. right
Serial.begin(9600);
}
void loop() {
// Calling functions:
joystickControl();
fall();
CollisionMann ();
CollisionMann2 ();
CollisionMann3();
CollisionHerz ();
// Check for game over
if (lives <= 0)
{gameOver();
return;}
}
// SCORE_LIVES FUNCTION
void scoreUpdate() {
tft.setTextSize(2);
tft.setTextColor(ILI9341_RED);
tft.setCursor(xScore, yInfo);
tft.print(score);
}
void livesUpdate(){
tft.setTextSize(2);
tft.setTextColor(ILI9341_RED);
tft.setCursor(xLives, yInfo);
tft.print(lives);
}
// SOUND FUNCTION
void soundCollision(){
tone(BuzzPin,NOTE_D4 ,20);
}
void soundGameOver () {
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4};
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4};
for (int i = 0; i < 8; i++){
int noteDuration = 1000 / noteDurations[i];
tone(BuzzPin, melody[i], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
}
}
// JOYSTICK FUNCTION
void joystickControl() {
int joystickV = map(analogRead(VERT_PIN), 0,1023,-1,1);
int joystickH = map(analogRead(HORZ_PIN), 0,1023, -1, 1);
canvas_figuren.drawRGBBitmap(0, 0, bitmap_Torro, figureWidth, figureHeight);
// moving of the Torro
switch (joystickH) //switch-function for right/left movement
{case 1: //links
if (10 < xTorro)
{xTorro-=MOVE_TORRO;
tft.fillRect(xTorro + figureWidth, yTorro, MOVE_TORRO, figureHeight, 0x0000);
tft.drawRGBBitmap(xTorro ,yTorro ,canvas_figuren.getBuffer(), figureWidth, figureHeight);} //canvas adjusted
break;
case -1: //rechts
if (xTorro < 275)
{xTorro+=MOVE_TORRO;
tft.fillRect(xTorro - MOVE_TORRO, yTorro, MOVE_TORRO, figureHeight, 0x0000);
tft.drawRGBBitmap(xTorro ,yTorro ,canvas_figuren.getBuffer(), figureWidth, figureHeight);} //canvas adjusted
break;}
}
// FALL FUNCTION
void fall () {
//Figure: Mann fall
canvas_figuren.drawRGBBitmap(0, 0, bitmap_Mann, figureWidth, figureHeight);
if (yMann > 240) // fall until catch or game over
{yMann = startingPosition;}
if(yMann == startingPosition) // start a new fall
{ZoneMann = random(0,4);
xMann = zone [ZoneMann];}
yMann += MOVE_MANN;
tft.fillRect(xMann, yMann - MOVE_MANN, figureWidth, MOVE_MANN, 0x0000);
tft.drawRGBBitmap(xMann,yMann, canvas_figuren.getBuffer(), figureWidth, figureHeight);
//Figure: Mann2 fall
canvas_figuren.drawRGBBitmap(0, 0, bitmap_Mann2, figureWidth, figureHeight);
if (yMann2 > 500) // fall until catch or declared limit of fall
{yMann2 = startingPosition;}
if(yMann2 == startingPosition) // start a new fall
{do {ZoneMann2 = random(0,4);}
while (ZoneMann2 == ZoneMann);
xMann2 = zone[ZoneMann2];
}
yMann2 += MOVE_MANN2;
tft.fillRect(xMann2, yMann2 - MOVE_MANN2, figureWidth, MOVE_MANN2, 0x0000);
tft.drawRGBBitmap(xMann2,yMann2,canvas_figuren.getBuffer(), figureWidth, figureHeight);
//Figure: Mann3 fall
canvas_figuren.drawRGBBitmap(0, 0, bitmap_Mann3, figureWidth, figureHeight);
if (yMann3 > 280) // fall until catch or game over
{yMann3 = startingPosition;}
if(yMann3 == startingPosition) // start a new fall
{do {ZoneMann3 = random (0,4);}
while (ZoneMann3 == ZoneMann2 ||
ZoneMann3 == ZoneMann);
xMann3 = zone[ZoneMann3];}
yMann3 += MOVE_MANN3;
tft.fillRect(xMann3, yMann3 - MOVE_MANN3, figureWidth, MOVE_MANN3, 0x0000);
tft.drawRGBBitmap(xMann3,yMann3, canvas_figuren.getBuffer(), figureWidth, figureHeight);
//Figure: Herz fall
canvas_figuren.drawRGBBitmap(0, 0, bitmap_Herz, figureWidth, figureHeight);
if (yHerz > 1400) // fall until catch or declared limit of fall
{yHerz = startingPosition;}
if(yHerz == startingPosition) // start a new fall
{do {ZoneHerz = random(0,4);}
while (ZoneHerz == ZoneMann3 ||
ZoneHerz == ZoneMann2 ||
ZoneHerz == ZoneMann);
xHerz = zone[ZoneHerz];}
yHerz+= MOVE_HERZ;
tft.fillRect(xHerz, yHerz - MOVE_HERZ, figureWidth, MOVE_HERZ, 0x0000);
tft.drawRGBBitmap(xHerz,yHerz,canvas_figuren.getBuffer(), figureWidth, figureHeight);
}
// COLLISION FUNCTION
//Collision Mann
boolean CollisionMann() {
if (xTorro + figureWidth >= xMann && // figure1 right edge past figure2 left edge
xTorro <= xMann + figureWidth && // figure1 left edge past figure2 right edge
yMann + figureHeight >= yTorro) // figure2 within range of figure 1 on y-axis
{score++;
soundCollision();
tft.fillRect(xScore,yInfo, wInfo, hInfo, 0x0000);
tft.fillRect(xMann, yMann, figureWidth, figureHeight, 0x0000);
scoreUpdate();
yMann = startingPosition;
return true;
}
else
if (yMann > 240)
{lives--;
tft.fillRect(xLives, yInfo, wInfo, hInfo, 0x0000);
livesUpdate();
yMann = startingPosition;}
return false;
}
//Collision Mann2
boolean CollisionMann2() {
if (xTorro + figureWidth >= xMann2 && // figure1 right edge past figure2 left edge
xTorro <= xMann2 + figureWidth && // figure1 left edge past figure2 right edge
yMann2 + figureHeight >= yTorro) // figure2 within range of figure 1 on y-axis
{score++;
soundCollision();
tft.fillRect(xScore,yInfo, wInfo, hInfo , 0x0000);
tft.fillRect(xMann2, yMann2, figureWidth, figureHeight, 0x0000);
scoreUpdate();
yMann2 = startingPosition;
return true;
}
else
if (yMann2 > 240)
{lives--;
tft.fillRect(xLives, yInfo, wInfo, hInfo, 0x0000);
livesUpdate();
yMann2 = startingPosition;}
return false;
}
//Collision Mann3
boolean CollisionMann3() {
if (xTorro + figureWidth >= xMann3 && // figure1 right edge past figure2 left edge
xTorro <= xMann3 + figureWidth && // figure1 left edge past figure2 right edge
yMann3 + figureHeight >= yTorro) // figure2 within range of figure 1 on y-axis
{score++;
soundCollision();
tft.fillRect(xScore,yInfo, wInfo, hInfo , 0x0000);
tft.fillRect(xMann3, yMann3, figureWidth, figureHeight, 0x0000);
scoreUpdate();
yMann3 = startingPosition;
return true;
}
else
if (yMann3 > 240)
{lives--;
tft.fillRect(xLives, yInfo, wInfo, hInfo, 0x0000);
livesUpdate();
yMann3 = startingPosition;}
return false;
}
//Collision Herz
boolean CollisionHerz () {
if (xTorro + figureWidth >= xHerz && // figure1 right edge past figure2 left edge
xTorro <= xHerz + figureWidth && // figure1 left edge past figure2 right edge
yHerz + figureHeight >= yTorro) // figure2 within range of figure 1 on y-axis
{lives++;
soundCollision();
tft.fillRect(xHerz, yHerz, figureWidth, figureHeight, 0x0000);
tft.fillRect(xLives, yInfo, wInfo, hInfo, 0x0000);
livesUpdate();
yHerz = startingPosition;
return true;
}
return false;
}
// GAME OVER FUNCTION
void gameOver() {
//realize gameover
soundGameOver();
tft.fillScreen(0x0000);
tft.setTextSize(3);
tft.setCursor(0, 50);
tft.println("Game Over!");
tft.print("Final Score: ");
tft.print(score);
tft.setCursor(0,170);
tft.setTextSize(2);
tft.setTextColor(ILI9341_RED);
tft.print("Better luck next time");
tft.setCursor(0, 190);
tft.print("Press button to play again!");
canvas_figuren.drawRGBBitmap(0, 0, bitmap_Torro, figureWidth, figureHeight);
tft.drawRGBBitmap(125 ,120 ,canvas_figuren.getBuffer(), figureWidth, figureHeight);
delay(1000); // Wait before restarting
// select how to continue
int joystickV = map(analogRead(VERT_PIN), 0,1023,-1,1);
int joystickH = map(analogRead(HORZ_PIN), 0,1023, -1, 1);
stateSEL = digitalRead(SEL_PIN);
int selectPos = 49;
switch (joystickH) //switch-function for right/left movement
{case -1: //rechts
if (selectPos = 49; selectPos == 49; selectPos = 174)
{tft.drawrRect(49,99,102,102,ILI9341_BLACK);
tft.drawrRect(selectPos,99,102,102,ILI9341_YELLOW);
break;
case 1: //links
if (selectPos = 174; selectPos == 174; selectPos = 49)
{tft.drawrRect(174,99,102,102,ILI9341_BLACK);
tft.drawrRect(selectPos,99,102,102,ILI9341_YELLOW);
break;}
}
}
bool stateSEL = digitalRead(SEL_PIN);
if (stateSEL == HIGH) {
//while button not pressed nothing is happening
//end of game screen (play again or restart/return to main menu)
tft.fillScreen(0x0000);
tft.fillRect(50, 100, 100, 100,ILI9341_BLUE);
tft.fillRect(175, 100, 100, 100,ILI9341_RED);
tft.setCursor(55,105);
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
tft.print("Return to ");
tft.print("main menu");
tft.setCursor(155,105);
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
tft.print("Try again");
while (stateSEL == HIGH) {
Serial.println("Button not pressed, waiting for action");
tft.drawRect(selectPos,99,102,102,ILI9341_YELLOW);
}
// hold button to restart the game
else {
Serial.println("Button pressed, restarting game");
if (statSEL == LOW && selectPos == 174){
tft.fillScreen(0x0000); //black out screen
lives = 3; // Reset lives
score = 0; // Reset score
yMann = yMann2 = yMann3 = yHerz = startingPosition; // Reset positions
tft.setTextSize(2); // insert static elements
tft.setTextColor(ILI9341_RED);
tft.setCursor(0, 0);
tft.print("Score: ");
tft.print(score);
tft.setCursor(210, 0);
tft.print("Lives: ");
tft.print(lives);
tft.setTextSize(1);
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(125,3);
tft.print("El Matador");
tft.fillRect(0,18,317,3,ILI9341_RED); //upper Hori
tft.fillRect(3,21,317,3,ILI9341_YELLOW); //middle Hori
tft.fillRect(6,24,317,3,ILI9341_RED); //lower Hori
tft.fillRect(0,21,3,240,ILI9341_RED); //outter Verti left
tft.fillRect(3,24,3,240,ILI9341_YELLOW); //middle Verti left
tft.fillRect(6,24,3,240,ILI9341_RED); //inner Verti left
tft.fillRect(317,18,3,240,ILI9341_RED); //outter Verti right
tft.fillRect(314,24,3,240,ILI9341_YELLOW); // middle Verti right
tft.fillRect(311,24,3,240,ILI9341_RED); // inner Verti right
}
}
}