/*
Ziele:
-Bretter werden radom eingefügt.(in erreichbarer Höhe)
-Das Universum muss sich nach unten verschieben
-Kollision mit den Brettern
Bonus:
-Counter
-Highscore
-Nudelwahl / Menü
*****************************************************************************/
#include "Display.h"
#include "Sprites.h"
#include "Classes.h"
unsigned long systime, timestamp, timestamp1;
//Objekte erstellen:
//->(String name, byte width, byte height, int16_t xCoord, int16_t yCoord)
Noodle Penne ("Penne",30,64,120,160,nudelSprite);
//->(Name, width, heigth, xCoord, yCoord)
Board Board ("Board",66,10,120,160,plattformSprite);
//Button: (Name, Pinnummer)
Button LEFT ("LEFT",5);
Button RIGHT ("RIGHT",3);
//Muss noch in die Noodle Klasse:
void drawSprite(uint16_t *spriteArray, byte width, byte height, int16_t xCoord, int16_t yCoord, byte phase = 0, bool erase = false) {
if (erase) {
tft.fillRect(xCoord, yCoord, width, height, ILI9341_BLACK);
} else {
//uint16_t skip = phase * width * height;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
uint16_t color = spriteArray[x + y * width /*+ skip*/];
if (color != 0) {
tft.drawPixel(xCoord + x, yCoord + y, color);
}
}
}
}
}
/*
*/
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(A0));
tft.begin();
tft.setRotation(0);
Serial.println("Welcome to NoodleJump Demo");
Serial.println("*** Use arrow keys on your keyboard to navigate the Noodle. ***");
// Draw border and text
tft.drawRect(0, 0, tft.width(), tft.height(), tft.color565(80, 80, 80));
tft.setTextColor(ILI9341_RED);
tft.setTextSize(1);
tft.setCursor(120, 20);
tft.print("Noodle Jump");
tft.setTextColor(ILI9341_WHITE);
tft.println(" Demo");
/*
for (int i = 1; i < 6; i++ ) {
drawSprite(plattformSprite, 66, 10, random(0,240),random(0,320), 0, false);
}
*/
/*
// Draw random rocks at random coords
for (int rockCount = 0; rockCount < 20; rockCount++) {
byte randomRock = random(0, 5);
drawSprite(rocks[randomRock], rocksizes[randomRock][0], rocksizes[randomRock][1], random(0, tft.width()), random(0, tft.height()));
}*/
}
void loop() {
systime = millis();
if (systime - timestamp >= 30) {
timestamp = systime;
Penne.jump();
}
Board.drawSprite();
LEFT.readButton();
RIGHT.readButton();
if (systime - timestamp1 >= 50) {
timestamp1 = systime;
if (LEFT.getStatus()){
Penne.setPosition(-10);
}
if (RIGHT.getStatus()){
Penne.setPosition(10);
}
}
//Penne.checkPosition();
/*
if (systime - timestamp >= 50) {
timestamp = systime;
int button = readButtons();
if (button > -1) {
// Delete sprite at old coords
drawSprite(spaceshipSprite, 16, 16, spaceShipX, spaceShipY, 0, true);
// Increase / decrease coords depending on button pressed
switch (button) {
case DOWN:
spaceShipY += spaceShipSpeed;
break;
case RIGHT:
spaceShipX += spaceShipSpeed;
break;
case UP:
spaceShipY -= spaceShipSpeed;
break;
case LEFT:
spaceShipX -= spaceShipSpeed;
break;
}
// Redraw sprite at new coords
drawSprite(spaceshipSprite, 16, 16, spaceShipX, spaceShipY, button);
}
}*/
}