#include <SPI.h>
#include <GrafxT3.h>
#include <SD.h>
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 7
#define TFT_SCK 13
#define TFT_MISO 39
#define TFT_MOSI 11
GrafxT3 tft = GrafxT3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO, &SPIN);
uint8_t use_fb = 1;
uint8_t use_clip_rect = 0;
uint8_t use_set_origin = 0;
int player_x = 160;
int player_y = 110;
int player_direction = 2;
int x=-0,y=0;
const byte square[] PROGMEM = {32,32,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111,
B11111111,B11111111,B11111111,B11111111};
void setup() {
Serial.begin(38400);
long unsigned debug_start = millis();
while (!Serial && ((millis() - debug_start) <= 5000));
Serial.println("serial ok, testing lib...");
tft.begin();
tft.setFrameRate(62);
tft.persistence = false;
SPI.setMISO(39);
// tft.useFrameBuffer(use_fb);
}
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void loop(void) {
tft.fillScreen(BLACK);
tft.updateAll();
//updates the GameR (the display, the sound, the buttons, everyyhing)
//returns true when it's time to render a new frame (20 times/second)
if(tft.buttons.repeat(BTN_UP,1)){
tft.drawBitmap(player_x, player_y, square,32,32,RED);
player_direction = 1;
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
if(tft.buttons.repeat(BTN_DOWN,1)){
tft.drawBitmap(player_x, player_y, square,32,32,GREEN);
player_direction = 2;
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
if(tft.buttons.repeat(BTN_LEFT,1)){
tft.drawBitmap(player_x, player_y, square,32,32,BLUE);
player_direction = 3;
}
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
if(tft.buttons.repeat(BTN_RIGHT,1)){
tft.drawBitmap(player_x, player_y, square,32,32,YELLOW);
player_direction = 4;
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
if(tft.buttons.repeat(BTN_S,1)){
tft.drawBitmap(player_x, player_y, square,32,32,PURPLE);
player_direction = 5;
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
if(tft.buttons.repeat(BTN_X,1)){
tft.drawBitmap(player_x, player_y, square,32,32,PINK);
player_direction = 6;
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
if(tft.buttons.repeat(BTN_Y,1)){
tft.drawBitmap(player_x, player_y, square,32,32,LIGHTBROWN);
player_direction = 7;
}
/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
if(tft.buttons.repeat(BTN_A,1)){
tft.drawBitmap(player_x, player_y, square,32,32,LIGHTGREY);
player_direction = 8;
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
if(tft.buttons.repeat(BTN_B,1)){
tft.drawBitmap(player_x, player_y, square,32,32,CYAN);
player_direction = 9;
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
if(tft.buttons.repeat(BTN_T,1)){
tft.drawBitmap(player_x, player_y, square,32,32,MAGENTA);
player_direction = 10;
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
///////////////// PLAYER DIRECTION ////////////////////////
if (player_direction == 1){
tft.drawBitmap(player_x, player_y, square,32,32,RED);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
else if (player_direction == 2){
tft.drawBitmap(player_x, player_y, square,32,32,GREEN);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
else if (player_direction == 3){
tft.drawBitmap(player_x, player_y, square,32,32,BLUE);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
else if (player_direction == 4){
tft.drawBitmap(player_x, player_y, square,32,32,YELLOW);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
else if (player_direction == 5){
tft.drawBitmap(player_x, player_y, square,32,32,PURPLE);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
else if (player_direction == 6){
tft.drawBitmap(player_x, player_y, square,32,32,PINK);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
else if (player_direction == 7){
tft.drawBitmap(player_x, player_y, square,32,32,LIGHTBROWN);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
else if (player_direction == 8){
tft.drawBitmap(player_x, player_y, square,32,32,LIGHTGREY);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
else if (player_direction == 9){
tft.drawBitmap(player_x, player_y, square,32,32,CYAN);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
else if (player_direction == 10){
tft.drawBitmap(player_x, player_y, square,32,32,MAGENTA);
}
tft.updateScreen();
}