//Libraries used
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//Figuren
// 'Torro_Logo', 75x52px
const unsigned char bitmap_Torro_Logo [] PROGMEM = {
0xff, 0x00, 0x07, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x0f, 0xe0, 0xfc, 0x00, 0xf7, 0xff, 0xff, 0xff,
0xfe, 0xf0, 0x03, 0xe0, 0xf8, 0x01, 0xf7, 0xff, 0xff, 0xff, 0xfe, 0xf8, 0x01, 0xe0, 0xf0, 0x00,
0x77, 0xff, 0xff, 0xff, 0xfe, 0xe0, 0x00, 0xe0, 0xe0, 0x00, 0x37, 0xff, 0xff, 0xff, 0xfe, 0xc0,
0x00, 0x60, 0xc0, 0x07, 0x97, 0xff, 0xff, 0xff, 0xfe, 0x9e, 0x00, 0x20, 0x80, 0x1f, 0xd7, 0xff,
0xff, 0xff, 0xfe, 0xbf, 0x80, 0x00, 0x80, 0x3f, 0xc7, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xc0, 0x00,
0x80, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xf0, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x80, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x80, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xe0, 0x00, 0x80, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xe0, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0xfe, 0x00,
0x00, 0xff, 0xe0, 0x1f, 0xf8, 0x00, 0x07, 0xe0, 0xff, 0x00, 0x00, 0x7f, 0xf0, 0x3f, 0xf8, 0x00,
0x0f, 0xe0, 0xff, 0xe0, 0x00, 0x1f, 0xf0, 0x3f, 0xe0, 0x00, 0x7f, 0xe0, 0xff, 0xfc, 0x00, 0x01,
0xf0, 0x3e, 0x00, 0x01, 0xff, 0xe0, 0xff, 0xfe, 0x00, 0x00, 0x70, 0x38, 0x00, 0x03, 0xff, 0xe0,
0xff, 0xff, 0x00, 0x00, 0x30, 0x30, 0x00, 0x0f, 0xff, 0xe0, 0xff, 0xff, 0xc0, 0x00, 0x30, 0x30,
0x00, 0x1f, 0xff, 0xe0, 0xff, 0xff, 0xf0, 0x00, 0x30, 0x30, 0x00, 0x7f, 0xff, 0xe0, 0xff, 0xff,
0xf8, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0xe0, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xf0, 0x00,
0x00, 0x00, 0x07, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xf0, 0x00, 0x08, 0x40, 0x07, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xf0, 0x00, 0x0c, 0x60, 0x07, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xf8, 0x00, 0x0c, 0x60,
0x07, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xf8, 0x80, 0x1c, 0x70, 0x07, 0xff, 0xff, 0xe0, 0xff, 0xff,
0xf8, 0x80, 0x0c, 0x60, 0x07, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xfc, 0xc0, 0x00, 0x00, 0x0f, 0xff,
0xff, 0xe0, 0xff, 0xff, 0xfc, 0x40, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xfe, 0x60,
0x00, 0x00, 0x3f, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0x30, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x01,
0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xaf,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfa, 0xff, 0xe0, 0xff, 0xac, 0x27, 0x80, 0xfe, 0xff, 0xdf, 0xfa,
0xff, 0xe0, 0xff, 0xad, 0xaf, 0xb6, 0xfc, 0x7f, 0xdf, 0xfa, 0xff, 0xe0, 0xff, 0xfd, 0xef, 0xb6,
0xfe, 0xff, 0xdf, 0xff, 0xff, 0xe0, 0xff, 0xfc, 0x6f, 0xb6, 0x86, 0x86, 0x10, 0x8f, 0xff, 0xe0,
0xff, 0xfd, 0xef, 0xbe, 0xb6, 0xb6, 0xd6, 0xaf, 0xff, 0xe0, 0xff, 0xfd, 0xeb, 0xbe, 0xb6, 0xb6,
0xd6, 0xbf, 0xff, 0xe0, 0xff, 0xfc, 0x23, 0xbe, 0x82, 0x82, 0x10, 0xbf, 0xff, 0xe0, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0
};
// 'Torro', 17x10px
const unsigned char bitmap_Torro [] PROGMEM = {
0x0f, 0xfc, 0x00, 0x3f, 0xfe, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x06, 0x30, 0x00, 0xc7,
0x71, 0x80, 0xf3, 0x67, 0x80, 0xf8, 0x0f, 0x80, 0xf9, 0x4f, 0x80, 0xfc, 0x0f, 0x80
};
// 'Mann', 10x10px
const unsigned char bitmap_Mann [] PROGMEM = {
0xe1, 0xc0, 0xc0, 0xc0, 0x61, 0x80, 0x73, 0x80, 0x00, 0x00, 0xf3, 0xc0, 0xf3, 0xc0, 0xc0, 0xc0,
0xde, 0xc0, 0x1e, 0x00
};
// 'Herz', 10x10px
const unsigned char bitmap_Herz [] PROGMEM = {
0xcc, 0xc0, 0xb3, 0x40, 0x7f, 0x80, 0x7f, 0x80, 0x7f, 0x80, 0x7f, 0x80, 0xbf, 0x40, 0xde, 0xc0,
0xed, 0xc0, 0xf3, 0xc0
};
// 'Mann2', 10x10px
const unsigned char bitmap_Mann2 [] PROGMEM = {
0xf1, 0xc0, 0x61, 0x80, 0x71, 0x80, 0xbb, 0x40, 0xc0, 0xc0, 0xe1, 0xc0, 0xe1, 0xc0, 0xed, 0xc0,
0xed, 0xc0, 0xc9, 0xc0
};
// 'Mann3', 10x10px
const unsigned char bitmap_Mann3 [] PROGMEM = {
0xe3, 0xc0, 0x61, 0x80, 0x63, 0x80, 0xb7, 0x40, 0xc0, 0xc0, 0xe1, 0xc0, 0xe1, 0xc0, 0xed, 0xc0,
0xed, 0xc0, 0xe4, 0xc0
};
//gamestate = where in the game are we, beginning or end
bool gameState = LOW;
//Joystick
#define VERT_PIN A2 // Vertical
#define HORZ_PIN A3 // Horizontal
#define SEL_PIN 2 // Pushbutton
//Display
#define SCREEN_I2C_ADDR 0x3c // 0x3c ist die i2c address
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RST_PIN -1 // Reset pin (-1 if not available)
// Torro_Logo
int xTorro_Logo = 30;
int yTorro_Logo = 10;
// the player = Torro
float xTorro = 64;
float yTorro =53;
int wTorro = 17;
int hTorro = 10;
// falling Herz
int xHerz = random(0,111);
float yHerz = 0;
int wHerz = 10;
int hHerz = 10;
// falling Mann
int xMann = random(0,111);
float yMann = 0;
int wMann = 10;
int hMann = 10;
// falling Mann2
int xMann2 = random(0,111);
float yMann2 = 0;
int wMann2 = 10;
int hMann2 = 10;
// falling Mann3
int xMann3 = random(0,111);
float yMann3 = 0;
int wMann3 = 10;
int hMann3 = 10;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST_PIN); // code line to active the screen
void setup ()
{
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
delay(1000);
//INTRO (Display Logo)
gameState;
display.drawBitmap(xTorro_Logo ,yTorro_Logo ,bitmap_Torro_Logo , 75, 52, bitmap_Torro_Logo, WHITE);
display.display();
delay(2000);
display.clearDisplay();
// Display static text
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(4, 10);
display.println("El Matador");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(20, 50);
display.println("Game Time");
delay(2000);
display.display ();
// joystick als input festegesetzt
pinMode(VERT_PIN, INPUT);
analogWrite(VERT_PIN, LOW);
pinMode(HORZ_PIN, INPUT);
analogWrite(HORZ_PIN, LOW);
pinMode(SEL_PIN, INPUT);
digitalWrite(SEL_PIN, LOW);
//setup to generate random number, only if A0 is not connected
randomSeed(analogRead(0));
}
void loop ()
{
display.clearDisplay();
// calling functions
joystickControl();
fall();
rectRect ();
display.display();
}// end of VOID_LOOP()
void joystickControl()
{
display.drawBitmap(xTorro ,yTorro ,bitmap_Torro , 17, 10, bitmap_Torro, WHITE);
int joystickV = map(analogRead(VERT_PIN), 0,1023,-1,1);
int joystickH = map(analogRead(HORZ_PIN), 0,1023, -1, 1);
bool currSelPressed = digitalRead(SEL_PIN);
// controlling of the Torro
switch (currSelPressed) //switch-function gameState HIGH or LOW
{ case HIGH:
if (gameState != currSelPressed)
{gameState = HIGH;}
break;
case LOW:
if (gameState == currSelPressed)
{gameState = LOW;}
break;}
switch (joystickV) //switch-function for up/down movement
{case 1: //hoch
if( 50 < yTorro)
{yTorro-=3;}
break;
case -1: //runter
if (yTorro < 54)
{yTorro+=3;}
break; }
switch (joystickH) //switch-function for right/left movement
{case 1: //links
if (0 < xTorro)
{xTorro-=3;}
break;
case -1: //rechts
if (xTorro < 111)
{xTorro+=3;}
break;}
}
void fall () {
// Figure: Mann fall
display.drawBitmap(xMann,yMann,bitmap_Mann, 10, 10, bitmap_Mann, WHITE);
yMann += 0.25;
if (yMann == 54) // fall until catch or game over
{yMann = 0;}
if (yMann == 0) // start a new fall
{xMann = random(25,65);}
// Figure: Mann2 fall
display.drawBitmap(xMann2,yMann2,bitmap_Mann2, 10, 10, bitmap_Mann2, WHITE);
yMann2 += 0.75;
if (yMann2 == 54) // fall until catch or game over
{yMann2 = 0;}
if (yMann2 == 0) // start a new fall
{xMann2 = random(10, 55);}
// Figure: Mann3 fallen
display.drawBitmap(xMann3,yMann3,bitmap_Mann3, 10, 10, bitmap_Mann3, WHITE);
yMann3++;
if (yMann3 == 54) // fall until catch or game over
{yMann3 = 0;}
if (yMann3 == 0) // start a new fall
{xMann3 = random(55,100);}
// Figure: Herz fall
display.drawBitmap(xHerz,yHerz,bitmap_Herz, 10, 10, bitmap_Herz, WHITE);
yHerz+= 1.5;
if (yHerz == 54) // fall until catch or game over
{yHerz = 0;}
if (yHerz == 0) // start a new fall
{xHerz = random(0,111);}
}
// Collision
boolean rectRect()
{
if (xTorro + wTorro >= xMann && // r1 right edge past r2 left
xTorro <= xMann + wMann && // r1 left edge past r2 right
yTorro + hTorro >= yMann && // r1 top edge past r2 bottom
yTorro <= yMann + hMann)
{return true;}
return false;} // placing it out of the bracket( has true value) makes it to " if not the case described above then false")