feat(pet): add animation frame
This commit is contained in:
@@ -17,10 +17,14 @@ class Pet {
|
||||
int8_t getEnergy() const;
|
||||
int8_t getCleanliness() const;
|
||||
String getReasonForDeath() const;
|
||||
|
||||
byte getAnimationFrame();
|
||||
private:
|
||||
int8_t hunger;
|
||||
int8_t joy;
|
||||
int8_t energy;
|
||||
int8_t cleanliness;
|
||||
String reasonForDeath;
|
||||
|
||||
byte lastAnimationFrame;
|
||||
};
|
||||
|
||||
+17
-4
@@ -4,7 +4,7 @@
|
||||
Display::Display() : lcd(LCD_I2C_ADDRESS, LCD_COLS, LCD_ROWS) {}
|
||||
|
||||
void Display::begin() {
|
||||
byte CUSTOM_CHAR_PET[] = {
|
||||
byte CUSTOM_CHAR_PET1[] = {
|
||||
B00100,
|
||||
B01110,
|
||||
B11111,
|
||||
@@ -14,10 +14,23 @@ void Display::begin() {
|
||||
B10001,
|
||||
B11111
|
||||
};
|
||||
byte CUSTOM_CHAR_PET2[] = {
|
||||
B00100,
|
||||
B01110,
|
||||
B11111,
|
||||
B10101,
|
||||
B11111,
|
||||
B10001,
|
||||
B10001,
|
||||
B11111
|
||||
};
|
||||
|
||||
lcd.init();
|
||||
lcd.backlight();
|
||||
lcd.createChar(0, CUSTOM_CHAR_PET); // Create a custom character for the pet
|
||||
lcd.backlight();
|
||||
|
||||
// Create a custom character for the pet
|
||||
lcd.createChar(0, CUSTOM_CHAR_PET1);
|
||||
lcd.createChar(1, CUSTOM_CHAR_PET2);
|
||||
}
|
||||
|
||||
void Display::clear() {
|
||||
@@ -45,7 +58,7 @@ void Display::drawPet(Pet &pet) {
|
||||
lcd.print("Cleanliness: " + String(pet.getCleanliness()));
|
||||
|
||||
lcd.setCursor(LCD_COLS - 2, LCD_ROWS / 2 - 1); // Position the pet
|
||||
lcd.write(byte(0)); // Draw the custom pet character
|
||||
lcd.write(pet.getAnimationFrame()); // Draw the custom pet character
|
||||
}
|
||||
|
||||
void Display::drawMenu(Menu &menu) {
|
||||
|
||||
+7
-1
@@ -1,7 +1,7 @@
|
||||
#include "pet.hpp"
|
||||
|
||||
Pet::Pet()
|
||||
: isAlive(true), hunger(0), joy(100), energy(100), cleanliness(100), reasonForDeath("") {}
|
||||
: isAlive(true), hunger(0), joy(100), energy(100), cleanliness(100), reasonForDeath(""), lastAnimationFrame(0) {}
|
||||
|
||||
void Pet::updateHunger(int8_t delta) {
|
||||
hunger += delta;
|
||||
@@ -82,3 +82,9 @@ int8_t Pet::getCleanliness() const {
|
||||
String Pet::getReasonForDeath() const {
|
||||
return reasonForDeath;
|
||||
}
|
||||
|
||||
byte Pet::getAnimationFrame() {
|
||||
// Alternate between two frames for a simple animation effect
|
||||
lastAnimationFrame = (lastAnimationFrame + 1) % 2;
|
||||
return lastAnimationFrame;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user