ArtemTechnologies

ATWatch - Arduino совместимая носимая платформа для обучения робототехнике и программированию на языке C++

Tamaguino

Официальная страница проекта

  1. /* Tamaguino
  2.   by Alojz Jakob <http://jakobdesign.com>
  3.  
  4.  ********** TAMAGUINO ***********
  5.    Tamagotchi clone for Arduino
  6.  ********************************
  7.  
  8. */
  9.  
  10. #include <SPI.h>
  11. #include <Wire.h>
  12. #include <Adafruit_GFX.h>
  13. #include <Adafruit_SH1106.h>
  14.  
  15. #define OLED_DC          26
  16. #define OLED_CS          31
  17. #define OLED_RESET       24
  18. Adafruit_SH1106 display(OLED_DC, OLED_RESET, OLED_CS);
  19.  
  20. const int button1Pin = 2;
  21. const int button2Pin = 12;
  22. const int button3Pin = 13;
  23.  
  24. const int ledPin = 0;
  25.  
  26. const int sound = 15;
  27.  
  28. int button1State = 0;
  29. int button2State = 0;
  30. int button3State = 0;
  31.  
  32.  
  33.  
  34. // splash 48x26
  35. const unsigned char splash1 [] PROGMEM = {
  36.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x39, 0xc0, 0x00,
  37.   0x00, 0x00, 0x00, 0x39, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38,
  38.   0x00, 0x00, 0x00, 0x00, 0x07, 0xb9, 0xce, 0x78, 0x0f, 0xc0, 0x0f, 0xf9, 0xcf, 0xfc, 0x1f, 0xe0,
  39.   0x1f, 0xf9, 0xcf, 0xfe, 0x3f, 0xf0, 0x3c, 0x79, 0xcf, 0x1e, 0x38, 0x78, 0x38, 0x39, 0xce, 0x0e,
  40.   0x70, 0x38, 0x38, 0x39, 0xce, 0x0e, 0x70, 0x38, 0x38, 0x39, 0xce, 0x0e, 0x70, 0x38, 0x38, 0x39,
  41.   0xce, 0x0e, 0x70, 0x38, 0x38, 0x39, 0xce, 0x0e, 0x70, 0x38, 0x3c, 0x79, 0xce, 0x0e, 0x78, 0x70,
  42.   0x1f, 0xf9, 0xce, 0x0e, 0x3f, 0xf0, 0x0f, 0xf9, 0xce, 0x0e, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00,
  43.   0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x10, 0x25, 0x37, 0x53, 0x90, 0xe1, 0xb8, 0x29, 0x22,
  44.   0x51, 0xd0, 0x93, 0x90, 0x19, 0x22, 0x52, 0x50, 0x92, 0x10, 0x11, 0x23, 0x73, 0xd0, 0xf1, 0x98,
  45.   0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  46. };
  47. //splash dino 80x40
  48. const unsigned char splash2 [] PROGMEM = {
  49.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50.   0x00, 0x1f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0xff, 0xe0, 0x00, 0x00,
  51.   0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
  52.   0xe1, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00,
  53.   0x00, 0x00, 0x00, 0x5e, 0xc1, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7d, 0x80, 0x2f,
  54.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  55.   0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00,
  56.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57.   0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00,
  58.   0x00, 0x00, 0x00, 0x00, 0x01, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x07, 0xf4,
  59.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf5, 0xe0, 0x1f, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
  60.   0xaa, 0xbc, 0x7f, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x55, 0x5f, 0xff, 0xa0, 0x00, 0x00,
  61.   0x00, 0x00, 0x00, 0xea, 0xaa, 0xaf, 0xff, 0x40, 0x00, 0x00, 0x00, 0x00, 0x03, 0xd5, 0x55, 0xff,
  62.   0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xab, 0xae, 0xbf, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00,
  63.   0x1f, 0x5f, 0xdf, 0xff, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xee, 0xfb, 0x6f, 0xf4, 0x00,
  64.   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xf7,
  65.   0xff, 0xff, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xa0, 0x00, 0x00, 0x00,
  66.   0x00, 0x1f, 0xff, 0xff, 0xff, 0xfd, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xdf, 0xff, 0xfe, 0xfe,
  67.   0x80, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xef, 0xef, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff,
  68.   0x9f, 0xdf, 0xff, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfc, 0x1f, 0xa1, 0xfc, 0x7f, 0x80, 0x00,
  69.   0x0f, 0xff, 0xff, 0xe0, 0x1f, 0xb0, 0x03, 0xbf, 0x80, 0x00, 0x1f, 0xff, 0x80, 0x00, 0x0f, 0xc0,
  70.   0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00,
  71.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72.   0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00,
  73.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74. };
  75.  
  76.  
  77. // front grass 32x10
  78. const unsigned char grass_front [] PROGMEM = {
  79.   0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x08, 0x89, 0xc0, 0x48, 0x5c, 0x50, 0x84,
  80.   0x9c, 0x48, 0x50, 0x22, 0x88, 0x80, 0x44, 0x22, 0x40, 0x84, 0x2e, 0x21, 0x49, 0x24, 0xa4, 0xb1,
  81. };
  82. //grass 2 (dino walking on) 4x8
  83. const unsigned char grass [] PROGMEM = {
  84.   0xff, 0xee, 0xbb, 0x55, 0xaa, 0x11,
  85. };
  86.  
  87. //trees
  88. const unsigned char trees [] PROGMEM = {
  89.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  90.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  91.   0x00, 0x10, 0x05, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  92.   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x15, 0x00,
  93.   0x00, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  94.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x40, 0x00, 0x55, 0x40, 0x00,
  95.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  96.   0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x15, 0x04, 0x40, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  97.   0x00, 0x02, 0xa0, 0x00, 0x00, 0x01, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  98.   0x00, 0x28, 0x84, 0x24, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, 0x82, 0x00,
  99.   0x00, 0x01, 0x10, 0x00, 0x04, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00,
  100.   0x41, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, 0x88, 0x82, 0x40, 0x91, 0x04, 0x24,
  101.   0x41, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  102.   0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x44, 0x44, 0x11, 0x04, 0x10, 0x11, 0x04, 0x01, 0x00, 0x00,
  103.   0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
  104.   0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x02, 0x10, 0x00, 0x80, 0x00, 0x00, 0x08, 0x00, 0x04,
  105.   0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x20, 0x00, 0x01, 0x00,
  106.   0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  107. };
  108.  
  109. const unsigned char mountains [] PROGMEM = {
  110.   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  111.   0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e,
  112.   0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
  113.   0x03, 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
  114.   0x07, 0x74, 0x07, 0x80, 0x10, 0x00, 0x00, 0x80, 0x00, 0x06, 0x80, 0x00, 0x00, 0x00, 0x00, 0xd5,
  115.   0x0e, 0xc2, 0x0d, 0xc0, 0x28, 0x01, 0x01, 0xc1, 0x00, 0x1f, 0x40, 0x00, 0x00, 0x00, 0x01, 0x28,
  116.   0x1d, 0x13, 0x1b, 0x60, 0x54, 0x03, 0x83, 0xa3, 0x80, 0x36, 0x20, 0x00, 0x00, 0x00, 0x06, 0xd0,
  117.   0x3a, 0x41, 0xb4, 0x30, 0xe2, 0xcc, 0xf7, 0x57, 0xc0, 0xd8, 0x10, 0x00, 0x00, 0x00, 0x19, 0x20,
  118.   0x68, 0x84, 0x49, 0x19, 0xa1, 0x36, 0x5d, 0x2a, 0xa1, 0xa0, 0x10, 0x00, 0x00, 0x00, 0xe6, 0x40,
  119.   0xd2, 0x10, 0xa4, 0x0c, 0x80, 0x8c, 0x1a, 0x15, 0x57, 0x40, 0x88, 0x00, 0x00, 0x1f, 0x38, 0x80,
  120.   0x49, 0x08, 0x00, 0x06, 0x02, 0xc0, 0x24, 0x18, 0x0b, 0x80, 0x05, 0x0b, 0x8c, 0xe0, 0x23, 0x00,
  121.   0xa0, 0x20, 0x00, 0x11, 0x00, 0x00, 0x48, 0x84, 0x84, 0x02, 0x20, 0x5d, 0xf3, 0x00, 0xcd, 0xc0,
  122.   0x50, 0x00, 0x04, 0x04, 0x01, 0x44, 0x00, 0x00, 0x08, 0x00, 0x00, 0x30, 0x04, 0x07, 0x10, 0x20,
  123.   0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x40, 0x40, 0x00, 0x10,
  124.   0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 0x01, 0x11, 0x01, 0x00, 0x00,
  125.   0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x20, 0x02,
  126. };
  127.  
  128.  
  129. const unsigned char cloud2 [] PROGMEM = {
  130.   0x04, 0x70, 0x18, 0x00, 0x6e, 0xfb, 0x7c, 0xee, 0xff, 0xff, 0xfd, 0xff, 0x6f, 0xfb, 0x38, 0xee,
  131.   0x07, 0x70, 0x52, 0x00,
  132. };
  133.  
  134.  
  135.  
  136. // walking sprites
  137. // walk right
  138. const unsigned char dinoWalk0 [] PROGMEM = {
  139.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  140.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  141.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  142.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  143.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  144.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x60, 0x00,
  145.   0x00, 0x00, 0x1f, 0xf1, 0xf0, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xb8, 0x00, 0x00, 0x00, 0x7b, 0xff,
  146.   0xfc, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x00, 0x00, 0x03, 0xff, 0x7f, 0xe0, 0x00, 0x00, 0x0f,
  147.   0xf7, 0xde, 0x00, 0x00, 0x00, 0x7f, 0xf8, 0x3c, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x7a, 0x00, 0x00,
  148. };
  149. const unsigned char dinoWalk1 [] PROGMEM = {
  150.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  151.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  152.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  153.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  154.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  155.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x60, 0x00,
  156.   0x00, 0x00, 0x1f, 0xf1, 0xf0, 0x00, 0x00, 0x00, 0x37, 0xff, 0xb8, 0x00, 0x00, 0x00, 0x7f, 0xff,
  157.   0xfc, 0x00, 0x00, 0x00, 0xff, 0x7f, 0xd8, 0x00, 0x00, 0x03, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x0f,
  158.   0xbf, 0xda, 0x00, 0x00, 0x00, 0x7f, 0xf8, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x00, 0x00,
  159. };
  160. const unsigned char dinoWalk2 [] PROGMEM = {
  161.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  162.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  163.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  164.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  165.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  166.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x60, 0x00,
  167.   0x00, 0x00, 0x1b, 0xf1, 0xf0, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xb8, 0x00, 0x00, 0x00, 0x7f, 0x7f,
  168.   0xfc, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x00, 0x00, 0x03, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x0f,
  169.   0xbf, 0xfa, 0x00, 0x00, 0x00, 0x7f, 0x78, 0x3c, 0x00, 0x00, 0x00, 0x00, 0xf4, 0x5e, 0x00, 0x00,
  170. };
  171. // walk left
  172. const unsigned char dinoWalk3 [] PROGMEM = {
  173.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  174.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  175.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  176.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  177.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  178.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0xe0, 0x00, 0x00,
  179.   0x00, 0x0f, 0x8f, 0xf8, 0x00, 0x00, 0x00, 0x1d, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xde,
  180.   0x00, 0x00, 0x00, 0x1b, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, 0xfe, 0xff, 0xc0, 0x00, 0x00, 0x00,
  181.   0x7b, 0xef, 0xf0, 0x00, 0x00, 0x00, 0x3c, 0x1f, 0xfe, 0x00, 0x00, 0x00, 0x5e, 0x3d, 0x00, 0x00,
  182. };
  183. const unsigned char dinoWalk4 [] PROGMEM = {
  184.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  185.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  186.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  187.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  188.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  189.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0xe0, 0x00, 0x00,
  190.   0x00, 0x0f, 0x8f, 0xf8, 0x00, 0x00, 0x00, 0x1d, 0xff, 0xec, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xfe,
  191.   0x00, 0x00, 0x00, 0x1b, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00,
  192.   0x5b, 0xfd, 0xf0, 0x00, 0x00, 0x00, 0x3c, 0x1f, 0xfe, 0x00, 0x00, 0x00, 0x18, 0x0c, 0x00, 0x00,
  193. };
  194. const unsigned char dinoWalk5 [] PROGMEM = {
  195.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  196.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  197.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  198.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  199.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  200.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0xe0, 0x00, 0x00,
  201.   0x00, 0x0f, 0x8f, 0xd8, 0x00, 0x00, 0x00, 0x1d, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x3f, 0xfe, 0xfe,
  202.   0x00, 0x00, 0x00, 0x1b, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00,
  203.   0x5f, 0xfd, 0xf0, 0x00, 0x00, 0x00, 0x3c, 0x1e, 0xfe, 0x00, 0x00, 0x00, 0x7a, 0x2f, 0x00, 0x00,
  204. };
  205.  
  206.  
  207. /* --------- GAME SPRITES ---------- */
  208. const unsigned char dinoJump [] PROGMEM = {
  209.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  210.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  211.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  212.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  213.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  214.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x60, 0x00,
  215.   0x00, 0x00, 0x1f, 0xf1, 0xf0, 0x00, 0x00, 0x00, 0x3b, 0xff, 0xb8, 0x00, 0x00, 0x00, 0x7f, 0xdf,
  216.   0xfc, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x00, 0x00, 0x03, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x0f,
  217.   0xff, 0xfe, 0x00, 0x00, 0x00, 0x7d, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x07, 0x80, 0x00,
  218.  
  219. };
  220.  
  221. const unsigned char obstacle1 [] PROGMEM = {
  222.   0x00, 0x00, 0x1e, 0x00, 0x2f, 0x00, 0x5e, 0x80, 0x5f, 0xc0, 0xb7, 0xc0,
  223. };
  224.  
  225. const unsigned char obstacle2 [] PROGMEM = {
  226.   0x14, 0x00, 0x08, 0x00, 0x52, 0x00, 0x34, 0x00, 0x69, 0x40, 0xf0, 0x80,
  227. };
  228.  
  229. const unsigned char poop [] PROGMEM = {
  230.   0x80, 0x88, 0x01, 0x81, 0x02, 0xe0, 0x27, 0x10, 0x0b, 0xf0, 0x1c, 0x08,
  231. };
  232.  
  233.  
  234. #define WALKSIZE 6
  235. //const unsigned char* const dinoWalk[WALKSIZE] PROGMEM = {
  236. const unsigned char* dinoWalk[WALKSIZE] = {
  237.   //dinoWalk0,dinoWalk0,dinoWalk1,dinoWalk1,dinoWalk2,dinoWalk2,
  238.   //dinoWalk3,dinoWalk3,dinoWalk4,dinoWalk4,dinoWalk5,dinoWalk5
  239.   dinoWalk0, dinoWalk1, dinoWalk2,
  240.   dinoWalk3, dinoWalk4, dinoWalk5
  241. };
  242. int walkPos = 0;
  243. int walkXPos = 0;
  244. bool walkAnimReverse = false;
  245. bool walkRight = false;
  246. int walkDirOffset = 2;
  247.  
  248.  
  249.  
  250. // EATING
  251.  
  252. const unsigned char eating1 [] PROGMEM = {
  253.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff,
  254.   0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xe0, 0x00, 0x00, 0x00,
  255.   0x7f, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x01, 0xff, 0xff, 0xfc, 0x00,
  256.   0x00, 0x03, 0x7c, 0x7f, 0xfe, 0x00, 0x00, 0x02, 0xf9, 0xff, 0xfe, 0x00, 0x00, 0x0c, 0xf3, 0xff,
  257.   0xff, 0x00, 0x00, 0x1f, 0xf4, 0x7f, 0xff, 0x80, 0x00, 0x7f, 0xf0, 0x7f, 0xff, 0xc0, 0x00, 0xff,
  258.   0xf8, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xe0,
  259.   0x1f, 0xe7, 0xff, 0xe0, 0xff, 0xe0, 0x3f, 0xdf, 0xff, 0xde, 0xff, 0xf0, 0x7f, 0xbf, 0xff, 0xbf,
  260.   0x7f, 0xf0, 0x7f, 0x7f, 0xfe, 0x77, 0xbf, 0xf8, 0x7f, 0x7f, 0xf9, 0xf7, 0xbf, 0xfc, 0x3f, 0xff,
  261.   0xe7, 0xef, 0xbf, 0xfe, 0x5f, 0xfe, 0x1f, 0x1f, 0xbf, 0xff, 0x67, 0xf1, 0xf9, 0x1f, 0xbf, 0xff,
  262.   0x38, 0x0f, 0xe8, 0x3f, 0xbf, 0xff, 0x1f, 0xff, 0xe0, 0x3f, 0xbf, 0xff, 0x0e, 0xfe, 0x40, 0xbf,
  263.   0x6f, 0xff, 0x04, 0x54, 0x00, 0xff, 0x57, 0xff, 0x00, 0x10, 0x01, 0xfe, 0xab, 0xff, 0x00, 0x18,
  264.   0x01, 0xfd, 0x55, 0xff, 0x00, 0x18, 0x05, 0xfa, 0xaa, 0xff, 0x00, 0x1d, 0x27, 0xf1, 0x55, 0x5f,
  265.   0x00, 0x0f, 0x7f, 0xe0, 0xaa, 0xaf, 0x00, 0x07, 0xff, 0x80, 0x55, 0x57, 0x00, 0x03, 0xfe, 0x00,
  266.   0x2a, 0xab, 0x00, 0x01, 0xf0, 0x00, 0x15, 0x55, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xaa, 0x00, 0x00,
  267.   0x00, 0x00, 0x05, 0x55, 0x00, 0x00, 0x00, 0x00, 0x02, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x01, 0x55,
  268.  
  269. };
  270. const unsigned char eating2 [] PROGMEM = {
  271.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff,
  272.   0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xe0, 0x00, 0x00, 0x00,
  273.   0x7f, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x01, 0xff, 0xff, 0xfc, 0x00,
  274.   0x00, 0x03, 0x7c, 0x7f, 0xfe, 0x00, 0x00, 0x02, 0xf9, 0xff, 0xfe, 0x00, 0x00, 0x0c, 0xf3, 0xff,
  275.   0xff, 0x00, 0x00, 0x1f, 0xf4, 0x7f, 0xff, 0x80, 0x00, 0x7f, 0xf0, 0x7f, 0xff, 0xc0, 0x00, 0xff,
  276.   0xf8, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xe0,
  277.   0x1f, 0xe7, 0xff, 0xe0, 0xff, 0xe0, 0x3f, 0xdf, 0xff, 0xde, 0xff, 0xf0, 0x7f, 0xbf, 0xff, 0xbf,
  278.   0x7f, 0xf0, 0x7f, 0x7f, 0xfe, 0x77, 0xbf, 0xf8, 0x7f, 0x7f, 0xf9, 0xf7, 0xbf, 0xfc, 0x3f, 0xff,
  279.   0xe7, 0xef, 0xbf, 0xfe, 0x5f, 0xfe, 0x1f, 0x1f, 0xbf, 0xff, 0x67, 0xf1, 0xf9, 0x1f, 0xbf, 0xff,
  280.   0x38, 0x0f, 0xe8, 0x3f, 0xbf, 0xff, 0x1f, 0xff, 0xe1, 0x7f, 0x3f, 0xff, 0x0e, 0xfe, 0x41, 0xfe,
  281.   0xef, 0xff, 0x04, 0xd4, 0x0b, 0xfd, 0x57, 0xff, 0x00, 0xd4, 0x0f, 0xfa, 0xab, 0xff, 0x00, 0x60,
  282.   0x9f, 0xf5, 0x55, 0xff, 0x00, 0x75, 0xff, 0xca, 0xaa, 0xff, 0x00, 0x3f, 0xff, 0x05, 0x55, 0x5f,
  283.   0x00, 0x1f, 0xfc, 0x02, 0xaa, 0xaf, 0x00, 0x07, 0xc0, 0x01, 0x55, 0x57, 0x00, 0x00, 0x00, 0x00,
  284.   0xaa, 0xab, 0x00, 0x00, 0x00, 0x00, 0x15, 0x55, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xaa, 0x00, 0x00,
  285.   0x00, 0x00, 0x05, 0x55, 0x00, 0x00, 0x00, 0x00, 0x02, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x01, 0x55,
  286.  
  287. };
  288. const unsigned char eating3 [] PROGMEM = {
  289.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff,
  290.   0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xe0, 0x00, 0x00, 0x00,
  291.   0x7f, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x01, 0xff, 0xff, 0xfc, 0x00,
  292.   0x00, 0x03, 0x7c, 0x7f, 0xfe, 0x00, 0x00, 0x02, 0xf9, 0xff, 0xfe, 0x00, 0x00, 0x0c, 0xf3, 0xff,
  293.   0xff, 0x00, 0x00, 0x1f, 0xf4, 0x7f, 0xff, 0x80, 0x00, 0x7f, 0xf0, 0x7f, 0xff, 0xc0, 0x00, 0xff,
  294.   0xf8, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xe0,
  295.   0x1f, 0xe7, 0xff, 0xe0, 0xff, 0xe0, 0x3f, 0xdf, 0xff, 0xde, 0xff, 0xf0, 0x7f, 0xbf, 0xff, 0xbf,
  296.   0x7f, 0xf0, 0x7f, 0x7f, 0xfe, 0x77, 0xbf, 0xf8, 0x7f, 0x7f, 0xf9, 0xf7, 0xbf, 0xfc, 0x3f, 0xff,
  297.   0xe7, 0xef, 0xbf, 0xfe, 0x5f, 0xfe, 0x1f, 0xdf, 0xbf, 0xff, 0x67, 0xf1, 0xff, 0x3f, 0xbf, 0xff,
  298.   0x38, 0x0f, 0xfc, 0xff, 0xbf, 0xff, 0x1f, 0xff, 0xf3, 0xff, 0x3f, 0xff, 0x0f, 0xff, 0xcf, 0xfe,
  299.   0xef, 0xff, 0x00, 0x38, 0x3f, 0xf9, 0x57, 0xff, 0x07, 0x83, 0xff, 0xea, 0xab, 0xff, 0x01, 0xff,
  300.   0xfe, 0x15, 0x55, 0xff, 0x00, 0xff, 0xf0, 0x0a, 0xaa, 0xff, 0x00, 0x3f, 0xc0, 0x05, 0x55, 0x5f,
  301.   0x00, 0x00, 0x00, 0x02, 0xaa, 0xaf, 0x00, 0x00, 0x00, 0x05, 0x55, 0x57, 0x00, 0x00, 0x00, 0x02,
  302.   0xaa, 0xab, 0x00, 0x00, 0x00, 0x01, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0x00, 0x00,
  303.   0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x01, 0x55,
  304.  
  305. };
  306.  
  307.  
  308. const unsigned char* eating[4] = {
  309.   eating1, eating2, eating3, eating2
  310. };
  311.  
  312. //const unsigned char apple0 [] PROGMEM = {
  313. const unsigned char apple [] PROGMEM = {
  314.   0x00, 0x01, 0xf0, 0x00, 0x07, 0xe0, 0x00, 0x0f, 0xe0, 0x3f, 0x1f, 0xc0, 0x00, 0xdf, 0x80, 0x00,
  315.   0x20, 0x00, 0x0f, 0xd7, 0xf0, 0x3f, 0xff, 0xfc, 0x7f, 0xff, 0xfe, 0x78, 0xff, 0xfe, 0xf0, 0x7f,
  316.   0xff, 0xe0, 0x7f, 0xff, 0xe0, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  317.   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xfe, 0x7f, 0xff, 0xfe, 0x3f, 0xff, 0xfc, 0x1f,
  318.   0xff, 0xf8, 0x0f, 0xff, 0xf0, 0x07, 0xc3, 0xe0,
  319. };
  320.  
  321.  
  322. const unsigned char steak [] PROGMEM = {
  323.   0x0f, 0xe0, 0x00, 0x3f, 0xf8, 0x00, 0x31, 0xfe, 0x00, 0x6e, 0x7f, 0x00, 0xd1, 0x7f, 0x80, 0xa0,
  324.   0xbf, 0x80, 0xa0, 0xbf, 0xc0, 0xa0, 0xbf, 0xc0, 0xd1, 0x3f, 0xc0, 0xae, 0xff, 0xe0, 0xd1, 0xff,
  325.   0xe0, 0xef, 0xff, 0xe0, 0x77, 0xff, 0xf0, 0x7b, 0xff, 0xd0, 0x3d, 0xff, 0x78, 0x1e, 0xf9, 0xfe,
  326.   0x0f, 0x67, 0xff, 0x07, 0x7f, 0xff, 0x03, 0x9f, 0xfc, 0x03, 0xc3, 0xf9, 0x01, 0xf8, 0xc3, 0x00,
  327.   0xff, 0x1e, 0x00, 0x1f, 0xfe, 0x00, 0x01, 0xfc,
  328. };
  329.  
  330.  
  331.  
  332. //ground
  333. int grassXPos = 0;
  334. float treesXPos = -20;
  335. //sky
  336. float couldsXPos = 0;
  337. const int sunRadius = 3;
  338. bool sunOrMoon = false;
  339. const int moonShadow = 2;
  340. float sunXPos = -2 * sunRadius;
  341. //clouds
  342. const int cloud1Width = 32;
  343. float cloud1XPos = display.width() + cloud1Width;
  344.  
  345.  
  346. int stars [6][2];
  347.  
  348.  
  349.  
  350.  
  351. // menus
  352. bool menuOpened = false;
  353. int menu = 0;
  354. int subMenu = 1;
  355. bool menuDepth = false;
  356. bool justOpened = false;
  357. #define MENUSIZE 8
  358. #define STRING_SIZE 11
  359.  
  360. const char mainMenu[MENUSIZE][8][STRING_SIZE] PROGMEM = {
  361.   {"food", "apple", "steak", "water", NULL},
  362.   {"game", NULL},
  363.   {"sleep", NULL},
  364.   {"clean", NULL},
  365.   {"doctor", NULL},
  366.   {"discipline", NULL},
  367.   {"stats", "hunger", "happiness", "health", "discipline", "weight", "age", NULL},
  368.   { "settings", "sound",
  369.     //"something",
  370.     NULL
  371.   },
  372. };
  373.  
  374. /* ------- PET STATS ------- */
  375.  
  376. float hunger = 100;
  377. float happiness = 100;
  378. float health = 100;
  379. float discipline = 100;
  380. float weight = 1;
  381. float age = 0;
  382.  
  383. //settings
  384. bool soundEnabled = true;
  385.  
  386. int action = 0;
  387. int setting = 0;
  388.  
  389. bool notification = false;
  390. int notificationBlink = 0;
  391. bool dead = false;
  392.  
  393. bool sleeping = false;
  394.  
  395. //game
  396. bool game = false;
  397. bool paused = false;
  398. bool gameOver = false;
  399. int score = 0;
  400. int hiScore = 0;
  401. int level = 0;
  402. bool newHiScore = false;
  403. bool jumping = false;
  404. bool jumpUp = true;
  405. int jumpPos = 0;
  406. bool obstacle1show = false;
  407. bool obstacle2show = false;
  408. int obstacle1XPos = 0;
  409. int obstacle2XPos = 0;
  410.  
  411.  
  412. float poopometer = 0;
  413. int poops [3] = {
  414.   0, 0, 0,
  415. };
  416.  
  417. #define ACTIVATED HIGH
  418.  
  419. void setup() {
  420.   pinMode(button1Pin, INPUT);
  421.   pinMode(button2Pin, INPUT);
  422.   pinMode(button3Pin, INPUT);
  423.  
  424.   //digitalWrite(button1Pin, HIGH);
  425.   //digitalWrite(button2Pin, HIGH);
  426.   //digitalWrite(button3Pin, HIGH);
  427.   // or just
  428.   // pinMode(button1Pin, INPUT_PULLUP)
  429.   // etc
  430.  
  431.   pinMode(sound, OUTPUT);
  432.  
  433.   pinMode(ledPin, OUTPUT);
  434.  
  435.   randomSeed(analogRead(0));
  436.  
  437.   display.begin(SH1106_SWITCHCAPVCC);
  438.   display.clearDisplay();
  439.  
  440.   // splash
  441.   display.setTextColor(WHITE);
  442.   //display.println(F("jakobdesign presents"));
  443.   display.print(F(" jakobdesign presents"));
  444.   display.drawBitmap(15, 24, splash1 , 48, 26, WHITE);
  445.   display.drawBitmap(48, 24, splash2 , 80, 40, WHITE);
  446.   display.display();
  447.  
  448.   //splash tone
  449.  
  450.   tone(sound, 500, 200);
  451.   delay(200);
  452.   tone(sound, 1000, 200);
  453.   delay(400);
  454.   tone(sound, 700, 200);
  455.   delay(200);
  456.   tone(sound, 1100, 200);
  457.  
  458.   delay(2200);
  459.   // end splash
  460.  
  461.  
  462.   display.clearDisplay();
  463.  
  464. }
  465.  
  466.  
  467.  
  468. void loop() {
  469.  
  470.   button1State = digitalRead(button1Pin);
  471.   button2State = digitalRead(button2Pin);
  472.   button3State = digitalRead(button3Pin);
  473.  
  474.   //char* str = "";
  475.  
  476.   if (!dead) {
  477.     /* -------- MODIFY PET STATS -------- */
  478.     // TODO: different gradients regarding to age
  479.     if (sleeping) {
  480.       hunger -= 0.00005;
  481.       poopometer += 0.00005;
  482.       if (happiness - 0.0001 > 0) {
  483.         happiness -= 0.0001;
  484.       }
  485.       health -= 0.00005 + countPoops() * 0.0001;
  486.       if (discipline - 0.0001 > 0) {
  487.         discipline -= 0.0001;
  488.       }
  489.     } else {
  490.       hunger -= 0.00025;
  491.       poopometer += 0.00025;
  492.       if (happiness - 0.0002 > 0) {
  493.         happiness -= 0.0002;
  494.       }
  495.       health -= 0.0001 + countPoops() * 0.0001;
  496.       if (discipline - 0.0002 > 0) {
  497.         discipline -= 0.0002;
  498.       }
  499.       //discipline-=0.02;
  500.     }
  501.     age += 0.0000025;
  502.  
  503.     //diarrhea :) for testing
  504.     //poopometer+=0.005;
  505.  
  506.     //health-=1;
  507.     //health-=countPoops()*0.0001;
  508.     //health-=countPoops()*0.05;
  509.  
  510.     if (poopometer >= 10) {
  511.       poopometer = countPoops();
  512.       poops[round(poopometer)] = random(20, display.width() + 32);
  513.       if (soundEnabled) {
  514.         tone(sound, 200, 50);
  515.       }
  516.       poopometer = 0;
  517.     }
  518.  
  519.     if ((hunger > 19.99975 && hunger < 20.00025) || (happiness > 19.9998 && happiness < 20.0002) || (health > 19.9999 && health < 20.0001) && soundEnabled) {
  520.       if (soundEnabled) {
  521.         tone(sound, 200, 50);
  522.       }
  523.     }
  524.  
  525.  
  526.     if (hunger <= 20 || countPoops() > 0 || happiness <= 20 || health <= 20) {
  527.       notification = true;
  528.     }
  529.     if (hunger > 20 && countPoops() == 0 && happiness > 20 && health > 20) {
  530.       notification = false;
  531.       digitalWrite(ledPin, LOW);
  532.     }
  533.  
  534.     if (hunger <= 0 || health <= 0 || happiness <= 0) {
  535.       dead = true;
  536.       if (soundEnabled) {
  537.         tone(sound, 500, 500);
  538.         delay(550);
  539.         tone(sound, 400, 500);
  540.         delay(550);
  541.         tone(sound, 300, 600);
  542.       }
  543.     }
  544.  
  545.  
  546.     display.clearDisplay();
  547.     display.setCursor(0, 0);
  548.  
  549.  
  550.     /* ------- BUTTON PRESS ACTIONS ------- */
  551.  
  552.     /* ------- BUTTON 1 - MENU ------- */
  553.     if (button1State == ACTIVATED) {
  554.  
  555.       // JUMP IN GAME
  556.       if (game) {
  557.  
  558.         if (!jumping && !paused) {
  559.           if (soundEnabled) {
  560.             tone(sound, 200, 50);
  561.           }
  562.           jumping = true;
  563.         }
  564.  
  565.       } else {
  566.         // MENU
  567.  
  568.         if (soundEnabled) {
  569.           tone(sound, 300, 80);
  570.         }
  571.  
  572.         if (!menuOpened) {
  573.           menuOpened = true;
  574.         } else {
  575.           if (menuDepth) {
  576.  
  577.             if ((const char*)pgm_read_word(&(mainMenu[menu][subMenu + 1])) == NULL) {
  578.               subMenu = 1;
  579.             } else {
  580.               ++subMenu;
  581.             }
  582.             setting = 100 * (menu + 1) + subMenu;
  583.           } else {
  584.             if (menu == MENUSIZE - 1) {
  585.               menu = 0;
  586.             } else {
  587.               ++menu;
  588.             }
  589.  
  590.             if ((const char*)pgm_read_word(&(mainMenu[menu][1])) != NULL) {
  591.               subMenu = 1;
  592.  
  593.               justOpened = true;
  594.             }
  595.             setting = 100 * (menu + 1) + subMenu;
  596.           }
  597.         }
  598.  
  599.         delay(60);
  600.  
  601.       }
  602.  
  603.     }
  604.     /* ------- BUTTON 2 - SELECT ------- */
  605.     if (button2State == ACTIVATED) {
  606.  
  607.       if (game) {
  608.         if (!gameOver) {
  609.           paused = !paused;
  610.           if (soundEnabled) {
  611.             tone(sound, 600, 80);
  612.           }
  613.           delay(60);
  614.         }
  615.  
  616.       } else {
  617.  
  618.         if (soundEnabled) {
  619.           tone(sound, 600, 80);
  620.         }
  621.  
  622.         if (menuOpened) {
  623.  
  624.           if (subMenu != 1 && (const char*)pgm_read_word(&(mainMenu[menu][1][0])) != NULL) {
  625.             action = 100 * (menu + 1) + subMenu;
  626.           }
  627.           if (subMenu == 1 && (const char*)pgm_read_word(&(mainMenu[menu][1][0])) == NULL) {
  628.             action = 100 * (menu + 1) + subMenu;
  629.           }
  630.           if (subMenu == 1 && (const char*)pgm_read_word(&(mainMenu[menu][1][0])) != NULL && menuDepth) {
  631.             action = 100 * (menu + 1) + subMenu;
  632.           }
  633.           if ((const char*)pgm_read_word(&(mainMenu[menu][1][0])) != NULL) {
  634.             setting = 100 * (menu + 1) + subMenu;
  635.             menuDepth = true;
  636.           }
  637.  
  638.         } else {
  639.           action = NULL;
  640.  
  641.           menuOpened = true;
  642.           menuDepth = true;
  643.           subMenu = 1;
  644.           menu = 6;
  645.           action = 701;
  646.           setting = 701;
  647.         }
  648.         justOpened = false;
  649.  
  650.         delay(60);
  651.  
  652.       }
  653.  
  654.     }
  655.     /* ------- BUTTON 3 - BACK ------- */
  656.     if (button3State == ACTIVATED) {
  657.       if (soundEnabled) {
  658.         tone(sound, 1000, 80);
  659.       }
  660.  
  661.       if (game || gameOver) {
  662.         walkPos = 0;
  663.         walkXPos = 0;
  664.         walkAnimReverse = false;
  665.         walkRight = true;
  666.         walkDirOffset = 0;
  667.         treesXPos = -20;
  668.         grassXPos = 0;
  669.         obstacle1show = false;
  670.         obstacle2show = false;
  671.         jumping = false;
  672.         jumpPos = 0;
  673.         jumpUp = true;
  674.         game = false;
  675.         score = 0;
  676.         newHiScore = false;
  677.         gameOver = false;
  678.         level = 0;
  679.         paused = false;
  680.       } else {
  681.         if (!menuDepth) {
  682.           menuOpened = false;
  683.           menu = 0;
  684.           setting = 0;
  685.         } else {
  686.           menuDepth = false;
  687.           setting = 100 * (menu + 1) + 1;
  688.         }
  689.         action = NULL;
  690.         subMenu = 1;
  691.       }
  692.  
  693.  
  694.       delay(60);
  695.     }
  696.  
  697.  
  698.  
  699.     /* ------- SCENERY AND WALKING ------- */
  700.  
  701.     //draw sun
  702.     sunXPos += 0.1;
  703.     if (sunXPos > display.width() + 2 * sunRadius) {
  704.       sunXPos = -2 * sunRadius;
  705.       sunOrMoon = !sunOrMoon;
  706.     }
  707.     if (sleeping) {
  708.       sunOrMoon = true;
  709.     }
  710.  
  711.     if (sleeping) {
  712.       sunOrMoon = true;
  713.     }
  714.  
  715.     if (!sunOrMoon) {
  716.       display.fillCircle(sunXPos, 2 * sunRadius, sunRadius, WHITE);
  717.     } else {
  718.       display.fillCircle(sunXPos, 2 * sunRadius, sunRadius, WHITE);
  719.       display.fillCircle(sunXPos - moonShadow, 2 * sunRadius, sunRadius, BLACK);
  720.       //if(walkPos == 5){
  721.       if (round(cloud1XPos) % 5 == 0) {
  722.         for (int i = 0; i < 6; i++) {
  723.           stars[i][0] = random(0, display.width());
  724.           stars[i][1] = random(0, 10);
  725.         }
  726.       } else {
  727.         for (int i = 0; i < 6; i++) {
  728.  
  729.           display.drawPixel(stars[i][0], stars[i][1], WHITE);
  730.         }
  731.       }
  732.     }
  733.  
  734.     //cloud 1
  735.     cloud1XPos -= 0.3;
  736.     if (cloud1XPos < -cloud1Width) {
  737.       cloud1XPos = display.width() + cloud1Width;
  738.     }
  739.     display.drawBitmap(cloud1XPos, 5, cloud2 , cloud1Width, 5, WHITE);
  740.  
  741.  
  742.     //mountains
  743.     display.drawBitmap(0, 7, mountains , 128, 16, WHITE);
  744.  
  745.     //walk and move ground perspective
  746.  
  747.     if (game) {
  748.  
  749.  
  750.       /* ------ GAME -----*/
  751.       level = round(score / 10);
  752.  
  753.       if (jumping && !gameOver && !paused) {
  754.         if (jumpUp) {
  755.           jumpPos = jumpPos + 1 + level;
  756.           if (jumpPos >= 12) {
  757.             jumpUp = false;
  758.           }
  759.         } else {
  760.           //jumpPos--;
  761.           jumpPos = jumpPos - 1 - level;
  762.           if (jumpPos <= 0) {
  763.             jumpUp = true;
  764.             jumping = false;
  765.             if (soundEnabled) {
  766.               tone(sound, 100, 50);
  767.             }
  768.             score += 1;
  769.           }
  770.         }
  771.       }
  772.  
  773.  
  774.       if (!gameOver && !paused) {
  775.         if (walkAnimReverse) {
  776.           walkPos -= 1;
  777.           if (walkPos == -1) {
  778.             walkPos = 0;
  779.             walkAnimReverse = false;
  780.           }
  781.         } else {
  782.           walkPos += 1;
  783.           if (walkPos == 3) {
  784.             walkPos = 2;
  785.             walkAnimReverse = true;
  786.           }
  787.         }
  788.  
  789.  
  790.  
  791.         walkXPos += 2;
  792.         grassXPos += 4;
  793.         treesXPos = treesXPos + 1 + level;
  794.         obstacle1XPos = obstacle1XPos + 2 + level;
  795.         obstacle2XPos = obstacle2XPos + 2 + level;
  796.  
  797.  
  798.         if (!jumping &&
  799.             (
  800.               (obstacle1show && display.width() - obstacle1XPos >= 20 && display.width() - obstacle1XPos <= 46)
  801.               ||
  802.               (obstacle2show && display.width() - obstacle2XPos >= 20 && display.width() - obstacle2XPos <= 46)
  803.             )
  804.            ) {
  805.           gameOver = true;
  806.           jumping = true;
  807.           jumpPos = -2;
  808.           if (soundEnabled) {
  809.             tone(sound, 500, 40);
  810.             delay(50);
  811.             tone(sound, 350, 40);
  812.             delay(50);
  813.             tone(sound, 200, 60);
  814.           }
  815.  
  816.           if (score > hiScore) {
  817.             hiScore = score;
  818.             newHiScore = true;
  819.           }
  820.           if (happiness + 15 < 100) {
  821.             happiness += 15;
  822.           } else {
  823.             happiness = 100;
  824.           }
  825.           health -= 1;
  826.           if (weight - score * 0.0025 > 5) {
  827.             weight -= score * 0.0025;
  828.           }
  829.  
  830.  
  831.         }
  832.       }
  833.  
  834.       if (walkXPos == display.width()) {
  835.         walkXPos = 0;
  836.       }
  837.       if (grassXPos == display.width()) {
  838.         grassXPos = 0;
  839.       }
  840.       if (treesXPos == display.width()) {
  841.         treesXPos = -128;
  842.       }
  843.  
  844.       if (jumping) {
  845.         display.drawBitmap(10, 26 - jumpPos, dinoJump , 48, 24, WHITE);
  846.       } else {
  847.         display.drawBitmap(10, 26, dinoWalk[walkPos] , 48, 24, WHITE);
  848.       }
  849.  
  850.       for (int i = 0; i < display.width() / 4 + 1; i++) {
  851.         display.drawBitmap(-walkXPos + i * 8, 50, grass , 8, 6, WHITE);
  852.       }
  853.  
  854.  
  855.       // obstacles 1
  856.  
  857.       if (obstacle1XPos - 16 >= display.width()) {
  858.         obstacle1XPos = 0;
  859.         obstacle1show = false;
  860.       }
  861.       if (!obstacle1show && random(1, 10) == 1 && obstacle2XPos > 40) {
  862.         obstacle1show = true;
  863.         obstacle1XPos = 0;
  864.       }
  865.       if (obstacle1show) {
  866.         display.drawBitmap(display.width() - obstacle1XPos, 44, obstacle1 , 16, 6, WHITE);
  867.       }
  868.  
  869.       // obstacles 2
  870.       if (obstacle2XPos - 16 >= display.width()) {
  871.         obstacle2XPos = 0;
  872.         obstacle2show = false;
  873.       }
  874.       if (!obstacle2show && random(1, 10) == 1 && obstacle1XPos > 40) {
  875.         obstacle2show = true;
  876.         obstacle2XPos = 0;
  877.       }
  878.  
  879.       if (obstacle2show) {
  880.         display.drawBitmap(display.width() - obstacle2XPos, 44, obstacle2 , 16, 6, WHITE);
  881.       }
  882.  
  883.  
  884.  
  885.  
  886.       //draw front grass
  887.       for (int i = 0; i < display.width() / 16 + 1; i++) {
  888.         display.drawBitmap(-grassXPos + i * 32, 60, grass_front , 32, 8, WHITE);
  889.       }
  890.       //draw trees
  891.       display.drawBitmap(-treesXPos, 23, trees , 112, 20, WHITE);
  892.  
  893.       if (!gameOver) {
  894.         display.setCursor(0, 56);
  895.         display.setTextColor(WHITE);
  896.         display.print(F("lvl: "));
  897.         display.print(level);
  898.         display.setCursor(64, 56);
  899.         display.setTextColor(WHITE);
  900.         display.print(F("pts: "));
  901.         display.print(score);
  902.       }
  903.  
  904.       if (paused && round(cloud1XPos) % 2 == 0) {
  905.         display.fillRect(24, 11, 80, 15, BLACK);
  906.         display.fillRect(25, 12, 78, 13, WHITE);
  907.         display.setCursor(47, 15);
  908.         display.setTextColor(BLACK);
  909.         display.println(F("PAUSED"));
  910.       }
  911.  
  912.       /* ---------- END GAME ----------*/
  913.  
  914.     } else {
  915.  
  916.       /* ------ NO GAME -----*/
  917.       if (!sleeping) {
  918.         display.drawBitmap(walkXPos, 26, dinoWalk[walkPos + walkDirOffset] , 48, 24, WHITE);
  919.       } else {
  920.         display.drawBitmap(walkXPos, 29, dinoWalk[walkPos + walkDirOffset] , 48, 24, WHITE);
  921.         if (walkRight) {
  922.           if (round(cloud1XPos) % 3 == 0) {
  923.             display.setCursor(walkXPos + 48, 36);
  924.             display.print(F("Z"));
  925.           } else {
  926.             display.setCursor(walkXPos + 46, 38);
  927.             display.print(F("z"));
  928.           }
  929.         } else {
  930.           if (round(cloud1XPos) % 3 == 0) {
  931.             display.setCursor(walkXPos - 4, 36);
  932.             display.print(F("Z"));
  933.           } else {
  934.             display.setCursor(walkXPos - 2, 38);
  935.             display.print(F("z"));
  936.           }
  937.         }
  938.       }
  939.       if (walkRight) {
  940.         if (!sleeping) {
  941.           walkXPos += 1;
  942.           grassXPos += 2;
  943.           treesXPos += 0.5;
  944.         }
  945.         if (walkXPos > 80) {
  946.           walkRight = false;
  947.           walkDirOffset = 3;
  948.         }
  949.       } else {
  950.         if (!sleeping) {
  951.           walkXPos -= 1;
  952.           grassXPos -= 2;
  953.           treesXPos -= 0.5;
  954.         }
  955.         if (walkXPos < 0) {
  956.           walkRight = true;
  957.           walkDirOffset = 0;
  958.         }
  959.       }
  960.  
  961.       //draw grass (ground)
  962.       for (int i = 0; i < 2 * display.width() / 4; i++) {
  963.         display.drawBitmap(-walkXPos + i * 8, 50, grass , 8, 6, WHITE);
  964.       }
  965.       // draw poops
  966.       for (int i = 0; i < 3; i++) {
  967.         if (poops[i] > 0) {
  968.           display.drawBitmap(-walkXPos + poops[i], 44, poop , 16, 6, WHITE);
  969.         }
  970.       }
  971.       //draw front grass
  972.       for (int i = 0; i < 2 * display.width() / 16; i++) {
  973.         display.drawBitmap(-grassXPos + i * 32, 56, grass_front , 32, 8, WHITE);
  974.       }
  975.       //draw trees
  976.       display.drawBitmap(-treesXPos, 23, trees , 112, 20, WHITE);
  977.  
  978.  
  979.  
  980.       if (!sleeping) {
  981.         if (walkAnimReverse) {
  982.           --walkPos;
  983.           if (walkPos == -1) {
  984.             walkPos = 0;
  985.             walkAnimReverse = false;
  986.           }
  987.         } else {
  988.           ++walkPos;
  989.           if (walkPos == 3) {
  990.             walkPos = 2;
  991.             walkAnimReverse = true;
  992.           }
  993.         }
  994.       }
  995.  
  996.     }
  997.  
  998.  
  999.     /* ------- MENUS AND ACTIONS ------- */
  1000.     //render menu
  1001.     if (menuOpened and !game) {
  1002.       display.fillRect(0, 0, display.width(), 30, BLACK);
  1003.       display.drawRect(0, 0, display.width(), 29, WHITE);
  1004.       display.fillRect(1, 1, display.width() - 2, 27, BLACK);
  1005.       display.drawRect(0, 0, display.width(), 12, WHITE);
  1006.       display.setCursor(8, 2);
  1007.       display.setTextSize(1);
  1008.       if (menuDepth) {
  1009.         display.fillRect(0, 0, display.width(), 12, WHITE);
  1010.         display.fillRect(1, 18, 1, 5, WHITE);
  1011.         display.fillRect(2, 19, 1, 3, WHITE);
  1012.         display.fillRect(3, 20, 1, 1, WHITE);
  1013.         display.setTextColor(BLACK, WHITE);
  1014.       } else {
  1015.         display.fillRect(1, 3, 1, 5, WHITE);
  1016.         display.fillRect(2, 4, 1, 3, WHITE);
  1017.         display.fillRect(3, 5, 1, 1, WHITE);
  1018.         display.setTextColor(WHITE);
  1019.       }
  1020.       char oneItem [STRING_SIZE];
  1021.       memcpy_P (&oneItem, &mainMenu[menu][0], sizeof oneItem);
  1022.       //display.println(getItem(menu,0));
  1023.       display.println(oneItem);
  1024.       if (subMenu) {
  1025.         display.setTextColor(WHITE);
  1026.         display.setCursor(8, 16);
  1027.         char subItem [STRING_SIZE];
  1028.         memcpy_P (&subItem, &mainMenu[menu][subMenu], sizeof subItem);
  1029.         //display.println(getItem(menu,subMenu));
  1030.         display.println(subItem);
  1031.       }
  1032.     }
  1033.  
  1034.     //do actions
  1035.  
  1036.     if (action > 0) {
  1037.  
  1038.  
  1039.       if ((action == 101 || action == 102 || action == 103) && !sleeping && random(1, (11 - round(discipline / 10))) == 1 ) {
  1040.         //95-100 discipline = 100% chance to feed
  1041.         //85-95 discipline = 50% chance
  1042.         //75-85 discipline = 33.33% chance
  1043.         //65-75 discipline = 25% chance
  1044.         //55-65 discipline = 20% chance
  1045.         //45-55 discipline = 16.67% chance
  1046.         //35-45 discipline = 14.28% chance
  1047.         //25-35 discipline = 12.5% chance
  1048.         //15-25 discipline = 12.5% chance
  1049.         //5-15 discipline = 10% chance
  1050.         //0-5 discipline = 9% chance
  1051.  
  1052.         //animate eating
  1053.  
  1054.         display.fillRect(0, 0, display.width(), display.height(), BLACK);
  1055.         for (int j = 0; j < 3; j++) {
  1056.           for (int i = 0; i < 4; i++) {
  1057.             display.clearDisplay();
  1058.             switch (action) {
  1059.               case 101:
  1060.                 //apple
  1061.                 display.drawBitmap(50, 40, apple, 24, 24, WHITE);
  1062.                 if (j > 0) display.fillCircle(76, 54, 12, BLACK);
  1063.                 if (j == 2) display.fillCircle(47, 55, 12, BLACK);
  1064.                 break;
  1065.               case 102:
  1066.                 //steak
  1067.                 display.drawBitmap(50, 40, steak, 24, 24, WHITE);
  1068.                 if (j > 0) display.fillCircle(76, 59, 13, BLACK);
  1069.                 if (j == 2) display.fillCircle(60, 63, 13, BLACK);
  1070.                 break;
  1071.               case 103:
  1072.                 //water ripples
  1073.                 display.drawCircle(80, 55, 1 + 1 * i, WHITE);
  1074.                 display.drawCircle(80, 55, 5 + 2 * i, WHITE);
  1075.                 display.drawCircle(80, 55, 10 + 4 * i, WHITE);
  1076.                 break;
  1077.  
  1078.  
  1079.             }
  1080.             display.drawBitmap(80, 24, eating[i], 48, 40, WHITE);
  1081.             delay(150);
  1082.             display.display();
  1083.           }
  1084.         }
  1085.  
  1086.  
  1087.  
  1088.         switch (action) {
  1089.           //apple
  1090.           case 101:
  1091.             if (hunger + 10 > 100) {
  1092.               hunger = 100;
  1093.               weight += 0.1;
  1094.             } else {
  1095.               hunger += 10;
  1096.             }
  1097.             if (health + 1 <= 100) {
  1098.               health += 1;
  1099.             }
  1100.             poopometer += 0.02;
  1101.             break;
  1102.           //steak
  1103.           case 102:
  1104.             if (hunger + 20 > 100) {
  1105.               hunger = 100;
  1106.               weight += 0.2;
  1107.             } else {
  1108.               hunger += 20;
  1109.               weight += 0.1;
  1110.             }
  1111.             if (health - 1 > 0) {
  1112.               health -= 1;
  1113.             }
  1114.             poopometer += 0.05;
  1115.             break;
  1116.           //water
  1117.           case 103:
  1118.             if (hunger + 5 <= 100) {
  1119.               hunger += 5;
  1120.             }
  1121.             poopometer += 0.01;
  1122.             break;
  1123.  
  1124.         }
  1125.       } else {
  1126.         if (action == 101 || action == 102 || action == 103) {
  1127.           if (soundEnabled) {
  1128.             tone(sound, 500, 200);
  1129.             delay(250);
  1130.           }
  1131.         }
  1132.       }
  1133.  
  1134.       switch (action) {
  1135.         case 201:
  1136.           //game
  1137.           if (!sleeping && health > 20) {
  1138.             game = true;
  1139.             walkPos = 0;
  1140.             walkXPos = 0;
  1141.             walkAnimReverse = false;
  1142.             walkRight = false;
  1143.             walkDirOffset = 2;
  1144.             treesXPos = -20;
  1145.             grassXPos = 0;
  1146.           }
  1147.           break;
  1148.         case 301:
  1149.           //sleep
  1150.           sleeping = !sleeping;
  1151.           if (!sleeping) {
  1152.             sunOrMoon = false;
  1153.           } else {
  1154.             for (int i = 0; i < 6; i++) {
  1155.               stars[i][0] = random(0, display.width());
  1156.               stars[i][1] = random(0, 10);
  1157.             }
  1158.           }
  1159.  
  1160.           break;
  1161.         case 401:
  1162.           //bath
  1163.           resetPoops();
  1164.           break;
  1165.         case 501:
  1166.           //doctor
  1167.           if (health < 60) {
  1168.             health = 100;
  1169.             for (int i = 0; i < 5; i++) {
  1170.               display.clearDisplay();
  1171.               if (i % 2 != 0) {
  1172.                 display.fillRect(32, 23, 64, 16, WHITE);
  1173.                 display.fillRect(56, 0, 16, 64, WHITE);
  1174.               }
  1175.               display.display();
  1176.               delay(300);
  1177.             }
  1178.           }
  1179.  
  1180.           break;
  1181.         case 601:
  1182.           //discipline
  1183.           if (action == 601 && !sleeping) {
  1184.             if (discipline + 12 <= 100) {
  1185.               discipline += 12;
  1186.             } else {
  1187.               discipline = 100;
  1188.             }
  1189.             if (happiness - 3 > 0) {
  1190.               happiness -= 3;
  1191.             }
  1192.             delay(150);
  1193.             for (int i = 0; i < 5; i++) {
  1194.               if (soundEnabled) {
  1195.                 tone(sound, 200 * i, 100);
  1196.               }
  1197.               display.setCursor(100 + 3 * i, 32);
  1198.               display.print(F("!"));
  1199.               display.display();
  1200.               delay(150);
  1201.             }
  1202.  
  1203.           }
  1204.           break;
  1205.  
  1206.         case 801:
  1207.           soundEnabled = !soundEnabled;
  1208.           break;
  1209.       }
  1210.       action = 0;
  1211.     }
  1212.  
  1213.     //display settings
  1214.     if (setting > 0 and !game) {
  1215.       display.setCursor(8, 16);
  1216.       if (setting == 201) {
  1217.         display.println(F("increase happiness"));
  1218.       }
  1219.       if (setting == 301) {
  1220.         display.println(F("get some rest"));
  1221.       }
  1222.       if (setting == 401) {
  1223.         display.println(F("keep it healthy"));
  1224.       }
  1225.       if (setting == 501) {
  1226.         display.println(F("when health is bad"));
  1227.       }
  1228.       if (setting == 601) {
  1229.         display.println(F("get smarter"));
  1230.       }
  1231.       if (setting == 701 || setting == 702 || setting == 703 || setting == 704) {
  1232.         display.drawRect(70, 17, 52, 7, WHITE);
  1233.       }
  1234.       if (setting == 701) {
  1235.         drawBar(hunger);
  1236.       }
  1237.       if (setting == 702) {
  1238.         drawBar(happiness);
  1239.       }
  1240.       if (setting == 703) {
  1241.         drawBar(health);
  1242.       }
  1243.       if (setting == 704) {
  1244.         drawBar(discipline);
  1245.       }
  1246.       if (setting == 705 || setting == 706 || setting == 801) {
  1247.         display.setCursor(80, 16);
  1248.       }
  1249.       if (setting == 705) {
  1250.         //display.setCursor(80,16);
  1251.         display.print(weight, 1);
  1252.         display.println(F(" t"));
  1253.       }
  1254.       if (setting == 706) {
  1255.         display.print(age, 1);
  1256.         display.println(F(" y."));
  1257.       }
  1258.       if (setting == 801) {
  1259.         if (soundEnabled) {
  1260.           display.println(F("on"));
  1261.         } else {
  1262.           display.println(F("off"));
  1263.         }
  1264.       }
  1265.     }
  1266.  
  1267.     //display notification
  1268.     if (notification) {
  1269.       ++notificationBlink;
  1270.       if (notificationBlink == 10) {
  1271.         notificationBlink = 0;
  1272.       }
  1273.       if (notificationBlink != 1) {
  1274.         display.drawRect(117, 28, 11, 11, WHITE);
  1275.         display.setTextColor(WHITE);
  1276.         digitalWrite(ledPin, LOW);
  1277.       } else {
  1278.         display.fillRect(117, 28, 11, 11, WHITE);
  1279.         display.setTextColor(BLACK);
  1280.         digitalWrite(ledPin, HIGH);
  1281.       }
  1282.       display.setCursor(120, 30);
  1283.       display.println(F("!"));
  1284.       if (dead) {
  1285.         digitalWrite(ledPin, LOW);
  1286.       }
  1287.     }
  1288.  
  1289.     // GAME OVER
  1290.     if (gameOver) {
  1291.  
  1292.  
  1293.  
  1294.       display.fillRect(15, 11, 98, 43, BLACK);
  1295.       display.drawRect(16, 12, 96, 41, WHITE);
  1296.       display.fillRect(16, 12, 96, 13, WHITE);
  1297.       display.setCursor(36, 15);
  1298.       display.setTextColor(BLACK);
  1299.       display.println(F("GAME OVER"));
  1300.       display.setTextColor(WHITE);
  1301.       display.setCursor(21, 29);
  1302.       if (newHiScore) {
  1303.         display.println(F("NEW HI-SCORE!"));
  1304.         display.setCursor(21, 40);
  1305.       } else {
  1306.         display.println(F("SCORE:"));
  1307.         display.setCursor(21, 40);
  1308.       }
  1309.       display.println(score);
  1310.  
  1311.  
  1312.  
  1313.     }
  1314.  
  1315.     display.display();
  1316.  
  1317.   } else {
  1318.     //dead...
  1319.     display.clearDisplay();
  1320.     display.setCursor(0, 0);
  1321.     display.setTextColor(WHITE);
  1322.     display.println(F("Pet died...\n\nPress button 1\nto restart"));
  1323.     display.display();
  1324.  
  1325.     if (button1State == HIGH) {
  1326.       if (soundEnabled) {
  1327.         tone(sound, 300, 80);
  1328.         delay(200);
  1329.       }
  1330.       noTone(sound);
  1331.       asm volatile ("  jmp 0");
  1332.     }
  1333.   }
  1334. }
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344. void drawBar(float value) {
  1345.   display.fillRect(72, 19, 48 * value / 100, 3, WHITE);
  1346. }
  1347.  
  1348. char* getItem(int menu, int index) {
  1349.   char oneItem [STRING_SIZE];
  1350.   memcpy_P (&oneItem, &mainMenu[menu][index], sizeof oneItem);
  1351.   return oneItem;
  1352. }
  1353.  
  1354. int countPoops() {
  1355.   int poopsCnt = 0;
  1356.   for (int i = 0; i < 3; i++) {
  1357.     if (poops[i] > 0) {
  1358.       ++poopsCnt;
  1359.     }
  1360.   }
  1361.   return poopsCnt;
  1362. }
  1363.  
  1364. void resetPoops() {
  1365.   for (int i = 0; i < 3; i++) {
  1366.     poops[i] = 0;
  1367.   }
  1368. }