/*
Project is also available in vscode:
https://github.com/sleepingpolice-afk/PetSim
Welcome to Virtual Pet Simulator!
Features:
- Pets, idle state, sleeping state, AFK state
- Klik pushbutton biru untuk kasih makan
- Warning: Bisa mati
- Kalau spam makan juga mati (reason: overweight)
- Bisa mining coin dengan pencet pushbutton kuning
- Tahan pushbutton kuning selama ~2 detik untuk buka status
- Status isinya health bar, hunger bar, jumlah koin yang dimiliki, dan stok obat
- Pada saat berada di window Status, tekan tombol hijau untuk membeli obat yang harganya 4 koin
- Pada saat pet nya dalam kondisi Idle (tidak tidur atau mati atau AFK), tekan pushbutton hijau untuk memberi obat jika stoknya masih ada
- Jika hunger bar dan health bar mencapai 0, maka pet akan mati.
- Ultrasonic sensor digunakan untuk kondisi AFK, yaitu jika majikan tidak berada 1 meter di depan sensor, maka anjing akan AFK alias tidur.
- Update: Now ada suara
Gameover song credit by: https://github.com/robsoncouto/arduino-songs
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
// 'icons8-angry-dog-50', 50x50px
const unsigned char epd_bitmap_icons8_angry_dog_50 [] PROGMEM = {
0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0xf6, 0x00,
0x00, 0x00, 0x00, 0x00, 0x38, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xe6, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00,
0x60, 0x67, 0x80, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7f,
0xff, 0x80, 0x00, 0x00, 0x00, 0x60, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0xe0,
0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x70, 0x00, 0x00,
0x00, 0xe0, 0x00, 0x10, 0x38, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x3e, 0x1e, 0x00, 0x00, 0x01, 0x80,
0x00, 0x3f, 0x0f, 0xfc, 0x00, 0x01, 0x80, 0x00, 0x1f, 0x03, 0xff, 0x80, 0x03, 0x00, 0x00, 0x0c,
0x00, 0x0f, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03,
0xc0, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x06,
0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x0e, 0x00, 0x00, 0x00, 0x7f, 0xff, 0x80, 0x0c, 0x00, 0x00,
0x01, 0xff, 0xfe, 0x00, 0x0c, 0x00, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x0c, 0x00, 0x00, 0x07, 0x39,
0x98, 0x00, 0x1c, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
0x38, 0x00, 0x00, 0x0c, 0xee, 0x60, 0x00, 0x30, 0x00, 0x00, 0x0f, 0xff, 0xf0, 0x00, 0x30, 0x00,
0x00, 0x0f, 0xff, 0xf8, 0x00, 0x70, 0x00, 0x00, 0x0f, 0xff, 0xf8, 0x00, 0x60, 0x00, 0x00, 0x00,
0x00, 0x70, 0x00, 0x60, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0xc0, 0x00, 0x00, 0x07, 0xff, 0xc0,
0x00, 0xc0, 0x00, 0x00, 0x1f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 368)
const int epd_bitmap_allArray_LEN = 1;
const unsigned char* epd_bitmap_allArray[1] = {
epd_bitmap_icons8_angry_dog_50
};
// 'icons8-dog-50', 50x50px
const unsigned char doggieicons8_dog_50 [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1f, 0xe0,
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x1f, 0x00, 0x00,
0x00, 0x00, 0x03, 0x03, 0x87, 0xc0, 0x00, 0x00, 0x00, 0x03, 0x03, 0x81, 0xc0, 0x00, 0x00, 0x00,
0x03, 0x03, 0x81, 0x80, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x80, 0x78, 0x00, 0x00, 0x03, 0x00,
0x03, 0x80, 0xfc, 0x00, 0x00, 0x06, 0x00, 0x03, 0x00, 0xce, 0x00, 0x00, 0x06, 0x00, 0x03, 0x00,
0xc7, 0x00, 0x00, 0x06, 0x01, 0xfe, 0x00, 0xe3, 0xff, 0xff, 0xfe, 0x01, 0xfe, 0x00, 0x71, 0xff,
0xff, 0xff, 0x81, 0x80, 0x00, 0x38, 0x00, 0x00, 0x01, 0xe1, 0x80, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x79, 0x80, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x07, 0x80,
0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x0c,
0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x0c, 0x00, 0x00,
0x00, 0x01, 0x80, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0c, 0x3f, 0xff, 0xff, 0x86, 0x00, 0x00,
0x0c, 0x3f, 0xff, 0xff, 0x86, 0x00, 0x00, 0x0c, 0x30, 0xc0, 0x01, 0x86, 0x00, 0x00, 0x0c, 0x30,
0x60, 0x01, 0x86, 0x00, 0x00, 0x0c, 0x38, 0x70, 0x01, 0x86, 0x00, 0x00, 0x0c, 0x38, 0x30, 0x01,
0x86, 0x00, 0x00, 0x0c, 0x3c, 0x38, 0x01, 0x86, 0x00, 0x00, 0x0c, 0x3c, 0x18, 0x01, 0x86, 0x00,
0x00, 0x0c, 0x36, 0x0c, 0x01, 0x86, 0x00, 0x00, 0x0c, 0x37, 0x0e, 0x01, 0x86, 0x00, 0x00, 0x0c,
0x33, 0x06, 0x01, 0x86, 0x00, 0x00, 0x0c, 0x33, 0x87, 0x01, 0x86, 0x00, 0x00, 0x0c, 0x31, 0x83,
0x01, 0x86, 0x00, 0x00, 0x0c, 0x30, 0xc3, 0x01, 0x86, 0x00, 0x00, 0x0e, 0x70, 0xe7, 0x01, 0xce,
0x00, 0x00, 0x07, 0xe0, 0x7e, 0x00, 0xfc, 0x00, 0x00, 0x03, 0xc0, 0x3c, 0x00, 0x78, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 368)
const int doggieallArray_LEN = 1;
const unsigned char* doggieallArray[1] = {
doggieicons8_dog_50
};
// 'sleep', 32x32px
const unsigned char dogsleepsleep [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0e, 0x60,
0x00, 0x00, 0x0c, 0x60, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x80, 0x00,
0x0c, 0x00, 0xe3, 0x00, 0x10, 0x00, 0x7c, 0xc0, 0x20, 0x00, 0x40, 0x20, 0x20, 0x00, 0x80, 0x10,
0x40, 0x01, 0x80, 0x10, 0x40, 0x01, 0x00, 0x10, 0x40, 0x01, 0x08, 0x10, 0x40, 0x02, 0x08, 0x88,
0x40, 0x02, 0x08, 0x0c, 0x40, 0x02, 0x08, 0x04, 0x60, 0x03, 0x18, 0x0a, 0x27, 0xff, 0xe7, 0x0e,
0x30, 0x00, 0x41, 0xfc, 0x18, 0x00, 0x41, 0x00, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 144)
const int dogsleepallArray_LEN = 1;
const unsigned char* dogsleepallArray[1] = {
dogsleepsleep
};
// 'icons8-no-hidden-fees-50', 50x50px
const unsigned char bokekicons8_no_hidden_fees_50 [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x7c,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0x80, 0x00,
0x00, 0x00, 0xe0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x01, 0x80, 0x0c, 0x00, 0xe0, 0x00, 0x00, 0x03,
0x00, 0x0c, 0x01, 0xf0, 0x00, 0x00, 0x07, 0x00, 0x0c, 0x03, 0xb8, 0x00, 0x00, 0x06, 0x00, 0x7f,
0x07, 0x18, 0x00, 0x00, 0x0c, 0x00, 0xff, 0xce, 0x0c, 0x00, 0x00, 0x0c, 0x01, 0xc1, 0x9c, 0x0c,
0x00, 0x00, 0x18, 0x01, 0xc0, 0x38, 0x06, 0x00, 0x00, 0x18, 0x01, 0x80, 0x70, 0x06, 0x00, 0x00,
0x18, 0x03, 0x80, 0xe0, 0x06, 0x00, 0x00, 0x30, 0x01, 0x81, 0xc0, 0x03, 0x00, 0x00, 0x30, 0x01,
0xc3, 0x80, 0x03, 0x00, 0x00, 0x30, 0x01, 0xe7, 0x00, 0x03, 0x00, 0x00, 0x30, 0x00, 0xce, 0x00,
0x03, 0x00, 0x00, 0x30, 0x00, 0x1c, 0xc0, 0x03, 0x00, 0x00, 0x30, 0x00, 0x39, 0xe0, 0x03, 0x00,
0x00, 0x30, 0x00, 0x70, 0xf0, 0x03, 0x00, 0x00, 0x30, 0x00, 0xe0, 0x70, 0x03, 0x00, 0x00, 0x18,
0x01, 0xc0, 0x70, 0x06, 0x00, 0x00, 0x18, 0x03, 0x80, 0x70, 0x06, 0x00, 0x00, 0x18, 0x07, 0x00,
0x70, 0x06, 0x00, 0x00, 0x0c, 0x0e, 0x40, 0x60, 0x0c, 0x00, 0x00, 0x0c, 0x1c, 0xff, 0xe0, 0x0c,
0x00, 0x00, 0x06, 0x38, 0x7f, 0xc0, 0x18, 0x00, 0x00, 0x07, 0x70, 0x1e, 0x00, 0x38, 0x00, 0x00,
0x03, 0xe0, 0x0c, 0x00, 0x30, 0x00, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x60, 0x00, 0x00, 0x00, 0xe0,
0x00, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x70, 0x00, 0x03, 0xb8, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x0f,
0x1c, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x7c, 0x0e, 0x00, 0x00, 0x00, 0x03, 0xff, 0xf0, 0x07, 0x00,
0x00, 0x00, 0x00, 0x7f, 0x80, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 368)
const int toomb_LEN = 1;
const unsigned char* bokekallArray[1] = {
bokekicons8_no_hidden_fees_50
};
// 'black-tombstone-on-grave-with-text-rip-line-icon-halloween-grave-outline-pictogram-headstone-with-cross-and-text-rest-in-peace-linear-icon-editable-stroke-isolated-illustration-vector', 70x74px
const unsigned char tombblack_tombstone_on_grave_with_text_rip_line_icon_halloween_grave_outline_pictogram_headstone_with_cross_and_text_rest_in_peace_linear_icon_editable_stroke_isolated_illustration_vector [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e,
0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xe0, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0x80,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x00,
0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x08, 0x7c, 0x30, 0xf0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x18,
0x64, 0x30, 0x98, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10, 0x64, 0x30, 0x98, 0x20, 0x00, 0x00, 0x00,
0x00, 0x30, 0x38, 0x30, 0xf0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0xe0, 0x10, 0x00,
0x00, 0x00, 0x00, 0x20, 0x30, 0x30, 0x80, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x68, 0x30, 0x80,
0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x6c, 0x30, 0x80, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x18, 0x60, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x3e,
0xe0, 0x30, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x23, 0x80, 0x30, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x20, 0x00, 0xfc, 0x19, 0x80, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x30, 0x00, 0xc0, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x30, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x30, 0x00,
0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
0x30, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x01, 0x90, 0xc0, 0x00, 0x00, 0x01, 0xa0, 0x00, 0x00, 0x00, 0xd3, 0x00, 0x00,
0x00, 0x00, 0xec, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x3c,
0x00, 0x00, 0x00, 0x07, 0x30, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00,
0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x01, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x0c, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x0f,
0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 688)
const int tomballArray_LEN = 1;
const unsigned char* tomballArray[1] = {
tombblack_tombstone_on_grave_with_text_rip_line_icon_halloween_grave_outline_pictogram_headstone_with_cross_and_text_rest_in_peace_linear_icon_editable_stroke_isolated_illustration_vector
};
// 'meds', 80x80px
const unsigned char needmedsmeds [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00,
0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xfb, 0x00, 0x00, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0xfe, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e,
0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x7f, 0xff, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
0x7f, 0xfe, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x80, 0x3f, 0xfc, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x1f, 0xfc,
0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0c, 0x07, 0xe0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x03, 0xc0, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01, 0x80,
0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0x01, 0xc0, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x03, 0xc0, 0x0e, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x06, 0x60, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
0x9c, 0x38, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x1f, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 816)
const int needmedsallArray_LEN = 1;
const unsigned char* needmedsallArray[1] = {
needmedsmeds
};
// 'jake', 50x50px
const unsigned char jakijake [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0x80, 0x00, 0x00, 0x00,
0x00, 0xf8, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x78, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x3c, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x07,
0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x70, 0x00, 0x00, 0x01, 0xc0, 0x00,
0x00, 0x61, 0xe0, 0x00, 0xf0, 0xc0, 0x00, 0x00, 0xc7, 0xf8, 0x03, 0xfc, 0xe0, 0x00, 0x00, 0xc7,
0x18, 0x03, 0x8c, 0x60, 0x00, 0x01, 0x8e, 0x0c, 0x07, 0x06, 0x30, 0x00, 0x01, 0x8e, 0x0f, 0xff,
0x06, 0x30, 0x00, 0x01, 0x8e, 0x0f, 0xff, 0x06, 0x30, 0x00, 0x03, 0x0f, 0x1e, 0x0f, 0x8e, 0x18,
0x00, 0x03, 0x07, 0xf8, 0x03, 0xfc, 0x18, 0x00, 0x03, 0x07, 0xf0, 0x01, 0xfc, 0x18, 0x00, 0x03,
0x01, 0xf1, 0xf1, 0xf0, 0x18, 0x00, 0x03, 0x00, 0x63, 0xf8, 0xc0, 0x18, 0x00, 0x03, 0x30, 0x63,
0xf8, 0xc1, 0x98, 0x00, 0x01, 0xb0, 0x61, 0xf0, 0xc1, 0xb0, 0x00, 0x01, 0xf0, 0x61, 0xb0, 0xc1,
0xf0, 0x00, 0x00, 0x70, 0x61, 0xb0, 0xc1, 0xc0, 0x00, 0x00, 0x30, 0x73, 0xb9, 0xc1, 0x80, 0x00,
0x00, 0x70, 0x33, 0x19, 0x81, 0xc0, 0x00, 0x00, 0xf0, 0x3f, 0x1f, 0x81, 0xe0, 0x00, 0x01, 0xf0,
0x1e, 0x0f, 0x01, 0xf0, 0x00, 0x03, 0xb0, 0x00, 0x00, 0x01, 0xb8, 0x00, 0x07, 0x30, 0x00, 0x00,
0x01, 0x9c, 0x00, 0x0e, 0x70, 0x00, 0x00, 0x01, 0xce, 0x00, 0x0c, 0xf0, 0x00, 0x00, 0x01, 0xe6,
0x00, 0x0c, 0xf0, 0x00, 0x00, 0x01, 0xe6, 0x00, 0x0e, 0x70, 0x00, 0x00, 0x01, 0xce, 0x00, 0x07,
0x30, 0x00, 0x00, 0x01, 0x9c, 0x00, 0x03, 0xb0, 0x00, 0x00, 0x01, 0xb8, 0x00, 0x01, 0xf0, 0x00,
0x00, 0x01, 0xf0, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x70, 0x00, 0x00, 0x01,
0xc0, 0x00, 0x00, 0x30, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x30, 0x00, 0x00, 0x01, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 368)
const int jakiallArray_LEN = 1;
const unsigned char* jakiallArray[1] = {
jakijake
};
#define RED 0xFF0000
#define pintrig 4
#define pinecho 3
//For the song
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_AS4 466
#define REST 0
// change this to make the song slower or faster
int tempo = 160;
// change this to whichever pin you want to use
int buzzer = 2;
int melody[] = {
// Super Mario Bros theme
// Score available at https://musescore.com/user/2123/scores/2145
// Theme by Koji Kondo
//game over sound
NOTE_C5,-4, NOTE_G4,-4, NOTE_E4,4,
NOTE_A4,-8, NOTE_B4,-8, NOTE_A4,-8, NOTE_GS4,-8, NOTE_AS4,-8, NOTE_GS4,-8,
NOTE_G4,8, NOTE_D4,8, NOTE_E4,-2,
};
// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes = sizeof(melody) / sizeof(melody[0]) / 2;
// this calculates the duration of a whole note in ms
int wholenote = (60000 * 4) / tempo;
int divider = 0, noteDuration = 0;
//Adafruit_SSD1306 tft(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//Adafruit_SSD1306 tft(OLED_RESET);
//Variables go here
unsigned long startTime;
unsigned long hunger;
unsigned long deathtimer;
unsigned long holdTime;
unsigned long medicinebtnhold;
unsigned long previoushunger = 0;
unsigned long spamtime;
unsigned long prevspamtime;
int hungerbtn = 7;
int hungerstate = 0;
int previousHungerState = HIGH;
int coinbtn = 6;
int coinstate = 0;
int coinprevstate = HIGH;
int medicinebtn = 5;
int medicinestate = 0;
int prevmedicinestate = HIGH;
int prevdogstate = 1;
int healthbar;
int hungerbar;
int medstock = 0;
int spamclick = 0;
int coins = 5;
//Variables end here
//functions go here
void clearTopHalf() {
int screenWidth = tft.width();
int screenHeight = tft.height();
int halfHeight = screenHeight / 2;
tft.fillRect(0, 0, screenWidth, halfHeight, ILI9341_BLACK); // Clear top half
}
void clearBottomHalf() {
int screenWidth = tft.width();
int screenHeight = tft.height();
int halfHeight = screenHeight / 2;
tft.fillRect(0, halfHeight, screenWidth, halfHeight, ILI9341_BLACK); // Clear bottom half
}
void angrydog();
void idledog();
void sleepingdog();
void gameover(int cause);
void getfood();
void getmeds();
void pethungry();
void currentstatus();
void bokek();
void playsong();
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.print("Successfully Started\n");
randomSeed(analogRead(A0));
pinMode(hungerbtn, INPUT_PULLUP);
pinMode(coinbtn, INPUT_PULLUP);
pinMode(medicinebtn, INPUT_PULLUP);
pinMode(pintrig, OUTPUT);
pinMode(pinecho, INPUT);
//tft.begin(SSD1306_SWITCHCAPVCC, 0x3c);
tft.begin();
tone(buzzer, 440, 200);
delay(200);
tone(buzzer, 330, 200);
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(0, 0);
tft.println("This is your pet.");
delay(2000);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
int randomindex = random(0, 5);
//Serial.println(randomindex);
char* randomname[5] = {
"Wesley", "Gio", "John Cena", "Black", "Asu"
}; // Define the array of names
tft.print("His name is ");
tft.print(randomname[randomindex]); // Print the random name
delay(500);
angrydog();
delay(2000);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.println("Pet him.");
delay(1000);
tft.setCursor(3/4*SCREEN_WIDTH, 32);
tft.setTextSize(3);
tft.println("or else...");
//tft.fillScreen(ILI9341_BLACK);
delay(3000);
tft.fillScreen(ILI9341_BLACK);
//debugg
healthbar = 2;
hungerbar = 2;
}
void loop() {
digitalWrite(pintrig, LOW);
delayMicroseconds(2);
digitalWrite(pintrig, HIGH);
delayMicroseconds(10);
digitalWrite(pintrig, LOW);
int duration = pulseIn(pinecho, HIGH);
long distance = duration / 58.2;
//Serial.println(distance);
if(distance < 100)
{
if(prevdogstate == 0)
{
prevdogstate = 1;
tft.fillScreen(ILI9341_BLACK);
}
//hungerstate = digitalRead(hungerbtn);
hunger = millis();
if (hunger - previoushunger >= 10000)
{
previoushunger = hunger;
hungerbar--;
}
if(hungerbar <= 0)
{
clearTopHalf();
pethungry();
}
if(digitalRead(hungerbtn) == LOW)
{
spamclick++;
clearTopHalf();
tft.setTextSize(2);
tft.setCursor(0, 0);
tft.println("Fed.");
getfood();
delay(1000);
clearTopHalf();
}
if(spamclick > 1)
{
gameover(3);
}
if (digitalRead(hungerbtn) == LOW && previousHungerState == HIGH) {
//Serial.println("Hunger button pressed.");
spamtime = millis(); // Reset spam timer when button is pressed
}
prevspamtime = spamtime;
coinstate = digitalRead(coinbtn);
if(coinstate == LOW && coinprevstate == HIGH)
{
coins = coins + 1;
tone(buzzer, 1568, 200);
delay(50);
tone(buzzer, 2093, 100);
holdTime = millis();
tft.setTextSize(2);
tft.setCursor(120, 300);
tft.println("+1 Coin");
delay(100);
clearBottomHalf();
}
else if((millis() - holdTime >= 1500) && coinstate == LOW)
{
coins--;
tone(buzzer, 831, 150);
currentstatus();
while(digitalRead(coinbtn) == LOW)
{
delay(10);
}
}
coinprevstate = coinstate;
idledog();
// Check if 3 seconds have passed since last button press
if (millis() - spamtime >= 3500) {
if(spamclick > 0)
{
spamclick--;
}
spamtime = millis();
}
medicinestate = digitalRead(medicinebtn);
if(medicinestate == LOW)
{
getmeds();
}
if(healthbar <= 0)
{
gameover(2);
}
}
else
{
if(prevdogstate == 1)
{
clearTopHalf();
}
prevdogstate = 0;
sleepingdog();
Serial.println("The pet is sleeping");
}
delay(100); //Small delay to prevent excessive CPU usage
}
void angrydog() {
//tft.fillScreen(ILI9341_BLACK);
tft.drawBitmap(20, 60, epd_bitmap_icons8_angry_dog_50, 50, 50, ILI9341_WHITE);
}
void idledog()
{
int rng;
rng = random(1000);
int rng2 = random(1, 3);
if(rng > 0 && rng < 980)
{
//clearTopHalf();
tft.drawBitmap(90, 40, doggieicons8_dog_50, 50, 50, ILI9341_WHITE);
//delay(3000);
}
else if(rng >= 996 && rng <= 1000)
{
clearTopHalf();
if(rng2 == 1)
{
tft.drawBitmap(random(20, 160), random(20, 120), dogsleepsleep, 32, 32, ILI9341_WHITE);
}
else
{
tft.drawBitmap(random(20, 160), random(20, 120), jakijake, 50, 50, ILI9341_WHITE);
}
delay(3000);
clearTopHalf();
}
}
void sleepingdog()
{
//tft.fillScreen(ILI9341_BLACK);
tft.drawBitmap(48, 16, dogsleepsleep, 32, 32, ILI9341_WHITE);
}
void deaddog()
{
tft.drawBitmap(89, 45, tombblack_tombstone_on_grave_with_text_rip_line_icon_halloween_grave_outline_pictogram_headstone_with_cross_and_text_rest_in_peace_linear_icon_editable_stroke_isolated_illustration_vector, 70, 74, ILI9341_WHITE);
}
void medsdog()
{
tft.drawBitmap(89, 45, needmedsmeds, 80, 80, ILI9341_WHITE);
}
void gameover(int cause)
{
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setCursor(0, 0);
tft.println("Your pet has died.");
tft.print("Cause: ");
switch (cause)
{
case 1:
tft.println("Starvation");
break;
case 2:
tft.println("Sickness");
break;
case 3:
tft.println("Overweight");
break;
}
deaddog();
playsong();
while(1)
{
delay(2000);
}
}
void getfood()
{
hungerbar = hungerbar + 3;
if (hungerbar > 10) {
hungerbar = 10;
}
tone(buzzer, 262, 200);
int number = random(1, 11);
//Serial.println(number); debug
if (number > 7 && healthbar > 0) {
healthbar--;
tft.setTextSize(2);
tft.println("The food is poisonous");
delay(1500);
}
}
void getmeds()
{
if(medstock > 0)
{
tft.setTextSize(2);
tft.setCursor(0, 0);
clearTopHalf();
tft.println("Gave a med");
tone(buzzer, 932, 200);
medsdog();
healthbar = healthbar + 3;
medstock--;
if(healthbar > 10)
{
healthbar = 10;
}
delay(1500);
clearTopHalf();
//clearBottomHalf();
}
else
{
clearTopHalf();
tft.setTextSize(2);
tft.setCursor(0, 0);
tft.print("Out of stock\n");
tone(buzzer, 262, 50);
delay(100);
tone(buzzer, 247, 50);
delay(100);
tone(buzzer, 233, 50);
delay(100);
tone(buzzer, 220, 180);
bokek();
delay(1500);
tft.fillScreen(ILI9341_BLACK);
}
}
void pethungry()
{
tft.setCursor(0, 0);
tft.setTextSize(2);
tft.println("Your pet is hungry");
delay(1000);
tft.println("Feed him.");
delay(500);
tft.println("Press Blue btn to feed");
deathtimer = millis();
while(millis() - deathtimer < 15000)
{
//tft.fillScreen(ILI9341_BLACK);
hungerstate = digitalRead(hungerbtn);
if(hungerstate == HIGH && (millis() - deathtimer == 6000) )
{
clearTopHalf();
tft.setCursor(0, 0);
tft.println("Your pet is dying...");
delay(1000);
tft.println("Feed him?");
delay(500);
}
else if(hungerstate == LOW)
{
getfood();
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.println("Your pet is happy.");
delay(4000);
tft.fillScreen(ILI9341_BLACK);
return;
}
}
int cause = 1; //starvation death
gameover(cause);
}
void currentstatus()
{
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setCursor(0, 0);
tft.print("Coins: ");
tft.setTextColor(ILI9341_YELLOW);
tft.print(coins);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(0, 32);
tft.print("HGR: ");
if(hungerbar <= 2)
{
tft.setTextColor(ILI9341_RED);
}
for(int i=0; i<hungerbar; i++)
{
tft.print("|");
}
tft.setTextColor(ILI9341_WHITE);
tft.print("\nHLT: ");
if(healthbar <= 2)
{
tft.setTextColor(ILI9341_RED);
}
for(int i=0; i<healthbar; i++)
{
tft.print("|");
}
tft.setTextColor(ILI9341_WHITE);
tft.print("\nMeds Stock: ");
tft.print(medstock);
tft.print("\n\nPress Green to buy \nmeds\nfor 4 coins");
unsigned long waitTime;
medicinestate = digitalRead(medicinebtn);
waitTime = millis();
while(millis() - waitTime < 3000)
{
if(digitalRead(medicinebtn) == LOW)
{
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
if(coins < 4)
{
tft.println("Need 4 coins.");
}
else
{
coins = coins - 4;
medstock++;
tft.setTextSize(2);
tft.println("Bought a medicine\n for 4 coins");
tone(buzzer, 523, 30);
delay(40);
tone(buzzer, 523, 40);
}
delay(2000);
break;
}
}
if(millis() - startTime >= 3000)
{
delay(2000);
tft.fillScreen(ILI9341_BLACK);
return;
}
}
void bokek()
{
//tft.fillScreen(ILI9341_BLACK);
tft.drawBitmap(50, 60, bokekicons8_no_hidden_fees_50, 50, 50, ILI9341_WHITE);
}
void playsong()
{
// iterate over the notes of the melody.
// Remember, the array is twice the number of notes (notes + durations)
// no need to repeat the melody.
for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {
// calculates the duration of each note
divider = melody[thisNote + 1];
if (divider > 0) {
// regular note, just proceed
noteDuration = (wholenote) / divider;
} else if (divider < 0) {
// dotted notes are represented with negative durations!!
noteDuration = (wholenote) / abs(divider);
noteDuration *= 1.5; // increases the duration in half for dotted notes
}
// we only play the note for 90% of the duration, leaving 10% as a pause
tone(buzzer, melody[thisNote], noteDuration * 0.9);
// Wait for the specief duration before playing the next note.
delay(noteDuration);
// stop the waveform generation before the next note.
noTone(buzzer);
}
}