/** * Update the end screen. */ bool updateEnd() { static long start = millis(); static bool flipped = false; long time = millis() - start; if (!flipped && time > 1000) { tft.invertDisplay(true); flipped = true; } else if (flipped && time > 2000) { tft.invertDisplay(false); flipped = false; start = millis(); } if (buttonAPressed()) return true; return false; }
void MCP::readButtons() { uint8_t buttonFuture(mcpRead(CHIP_SELECT_PIN, GPIOB, (3 << 1))); buttonFuture &= BUTTON_MASK; if (buttonState != buttonFuture) { // Change detected boolean button1pressed(((buttonState & BUTTON1) == 0x00) && ((buttonFuture & BUTTON1) != 0x00)); boolean button2pressed(((buttonState & BUTTON2) == 0x00) && ((buttonFuture & BUTTON2) != 0x00)); if (button1pressed != button2pressed) { if (button1pressed) { buttonAPressed(); } else { buttonBPressed(); } //} else if (buttonBpressed) { //Serial.println(F("Both Buttons pressed.")); } buttonState = buttonFuture; } }
/** * Update the aim screen. * @returns bool true if the player has fired, false otherwise */ bool updateAim() { float vert = joyReadF(true), horiz = joyReadF(false); bool updated = false; if(vert < -joyThreshold && aimY > 0) { aimY--; updated = true; } else if(vert > joyThreshold && aimY < MAP_SIZE - 1) { aimY++; updated = true; } if(horiz < -joyThreshold && aimX > 0) { aimX--; updated = true; } else if(horiz > joyThreshold && aimX < MAP_SIZE - 1) { aimX++; updated = true; } if (updated) { renderMap(&enemyMap); renderCursor(aimX, aimY); } if(buttonAPressed() && getState(enemyMap.squares[indexFromPos(aimX, aimY)]) == Map::UNKNOWN) { // Fire the shot! listenUntil(ENQ); sendPosition(aimX, aimY); // Get back a response bool hit = false; Ship::TYPES type = Ship::NONE; getResponse(&hit, &type); Serial.print("Hit: ");//DEBUG Serial.println(hit);//DEBUG Serial.print("Type: ");//DEBUG Serial.println(getTypeName(type));//DEBUG if (hit) { if (type != Ship::NONE) { String name = getTypeName(type); enemyMap.ships[getShipIndex(type)].health = 0; String message[] = {"You sunk the enemy's", name + "!"}; renderMessage(message, 2); } else { String message[] = {"You hit!"}; renderMessage(message, 1); } } else { String message[] = {"You missed!"}; renderMessage(message, 1); } setState(&enemyMap.squares[indexFromPos(aimX, aimY)], hit ? Map::HIT : Map::MISS); renderMap(&enemyMap); renderCursor(aimX, aimY); while (!buttonAPressed()) {} return true; } return false; }