Hi guys
I'm working on a game for my game console and libraries and I'm having trouble saving and retrieving the current player structure data when saved and loaded. as it stands I can save and load but the load is not what was saved. For example.....
I want to save player structure....
struct Player
{
int player_x;
int player_y;
int w;
int h;
int room;
int player_direction;
int player_directionRepeat;
};
Player player = { 160, 170, 16, 16, 3, 2, 0};
serial says it saved but when I load the game after saving I end up with the player in a room of the same size but no room graphics and I actually have to move the player before he appears on the screen. Also the players x and y coordinates wont save or load.
The last part is that I need the save to save current player data.
void setup() {
while (!Serial && (millis() < 4000)) ;
Serial.begin(115200);
tft.begin();
tft.setRotation(3);
tft.fillScreen(BLACK);
//tft.setFrameRate(60);
tft.persistence = false;
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
if (!ss1.begin(0x49)) {
Serial.println("ERROR!");
while (1);
}
if (!ss2.begin(0x4a)) {
Serial.println("ERROR!");
while (1);
}
else {
Serial.println("seesaw started");
Serial.print("version: ");
Serial.println(ss1.getVersion(), HEX);
}
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
ss1.pinModeBulk(button_mask, INPUT_PULLUP);
ss1.setGPIOInterrupts(button_mask, 1);
pinMode(IRQ_PIN1, INPUT);
/////////////////////////////////////////////////////////
ss2.pinModeBulk(button_mask2, INPUT_PULLUP);
ss2.setGPIOInterrupts(button_mask2, 1);
pinMode(IRQ_PIN2, INPUT);
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
if (!EEPROM.begin(EEPROM_SIZE))
{
Serial.println("failed to initialise EEPROM"); delay(1000000);
}
Serial.println(" bytes read from Flash . Values are:");
for (int i = 0; i < EEPROM_SIZE; i++)
{
Serial.print(byte(EEPROM.read(i))); Serial.print(" ");
}
Serial.println();
Serial.println("writing random n. in memory");
tft.useFrameBuffer(use_fb);
}
byte saveKey = 121;
int val = byte(random(10020));
void save()
{
int address = 0;
EEPROM.put(4, saveKey);
Serial.print(val); Serial.print(" ");
EEPROM.put(28, player);
Serial.print(val); Serial.print(" ");
Serial.print("saved");
}
bool checkLoad()
{
byte nr;
EEPROM.get(0, nr);
Serial.print("checkload");
return (nr == saveKey);
}
void load()
{
EEPROM.get(28, player);
Serial.print(val); Serial.print(" ");
Serial.print("loaded");
}
vRect rectA {0, 0, 136, 20};
Rect rectB {0, 20, 136, 40};
Rect rectC {0, 60, 136, 40};
Rect rectD {0, 100, 136, 40};
Rect rectE {0, 140, 136, 40};
Rect rectF {0, 180, 136, 40};
Rect rectG {0, 220, 136, 20};
Rect rectH {cursora.cursorA_x, cursora.cursorA_y, 32, 32};
/////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
tft.fillRoundRect(0, 0, 136, 240, 4, WHITE);
tft.fillRoundRect(4, 4, 128, 232, 4, BLUE);
tft.setCursor(24, 24);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("Item");
tft.setCursor(24, 64);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("Equip");
tft.setCursor(24, 104);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("Weird");
tft.setCursor(24, 144);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("Stats");
tft.setCursor(24, 184);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("Save");
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
int y = ss1.analogRead(2);
int x = ss1.analogRead(3);
/// if(tft.Bpressed(BTN_UP)){
if (x > 600 && last_x < 600) {
tft.writeRectNBPP(cursora.cursorA_x, cursora.cursorA_y, 32, 32, 4, cursor3, palette);
cursora.cursor_direction = 1;
cursora.cursorA_y -= 40;
}
if (cursora.cursorA_y <= 27) {
cursora.cursorA_y = 27;
}
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////Down///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// if(tft.Bpressed(BTN_DOWN)){
if (x < 400 && last_x > 400) {
tft.writeRectNBPP(cursora.cursorA_x, cursora.cursorA_y, 32, 32, 4, cursor3, palette);
cursora.cursor_direction = 1;
cursora.cursorA_y += 40;
}
if (cursora.cursorA_y >= 188) {
cursora.cursorA_y = 188;
}
last_x = x;
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
if (cursora.cursor_direction == 1) {
tft.writeRectNBPP(cursora.cursorA_x, cursora.cursorA_y, 32, 32, 4, cursor3, palette);
}
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////exit menu////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
if (!digitalRead(IRQ_PIN2)) {
uint32_t buttons = ss2.digitalReadBulk(button_mask2);
if (! (buttons & (1 << BUTTON_A))) {
state = STATE_Player;
}oid Menu() {