|
10 | 10 | * LCD: OLED SSD1309 128x64
|
11 | 11 | */
|
12 | 12 |
|
| 13 | +/* Hardware Connections */ |
| 14 | +//buttons |
| 15 | +#define JUMP_BUTTON 6 |
| 16 | +#define DUCK_BUTTON 5 |
| 17 | +//LCD |
| 18 | +#define LCD_CS 2 |
| 19 | +#define LCD_DC 3 |
| 20 | +#define LCD_RESET 4 |
| 21 | +//LCD_SDA -> 11 (SPI SCK) |
| 22 | +//LCD_SCL -> 13 (SPI MOSI) |
| 23 | + |
| 24 | +/* Misc. settings */ |
| 25 | +//#define AUTO_PLAY //uncomment to enable auto-play mode |
| 26 | +//#define RESET_HI_SCORE //uncomment to reset HI score, flash your device, than comment it back and flash again |
| 27 | + |
13 | 28 | /* Game Balance Settings */
|
14 | 29 | #define PLAYER_SAFE_ZONE_WIDTH 32 //minimum distance between obstacles (px)
|
15 | 30 | #define CACTI_RESPAWN_RATE 50 //lower -> more frequent, max 255
|
|
24 | 39 | #define TARGET_FPS_START 23
|
25 | 40 | #define TARGET_FPS_MAX 48 //gradually increase FPS to that value to make the game faster and harder
|
26 | 41 |
|
27 |
| -/* Hardware Connections */ |
28 |
| -//buttons |
29 |
| -#define JUMP_BUTTON 6 |
30 |
| -#define DUCK_BUTTON 5 |
31 |
| -//LCD |
32 |
| -#define LCD_CS 2 |
33 |
| -#define LCD_DC 3 |
34 |
| -#define LCD_RESET 4 |
35 |
| -//LCD_SDA -> 11 (SPI SCK) |
36 |
| -//LCD_SCL -> 13 (SPI MOSI) |
37 |
| - |
38 | 42 | /* Display Settings */
|
39 | 43 | #define LCD_HEIGHT 64U
|
40 | 44 | #define LCD_WIDTH 128U
|
@@ -192,9 +196,23 @@ void gameLoop(uint16_t &hiScore) {
|
192 | 196 | heartLive.eat();
|
193 | 197 | }
|
194 | 198 |
|
| 199 | +#ifndef AUTO_PLAY |
195 | 200 | //constrols
|
196 | 201 | if(isPressedJump()) trex.jump();
|
197 | 202 | trex.duck(isPressedDuck());
|
| 203 | +#else |
| 204 | + const int8_t trexXright = trex.bitmap->width + trex.position.x; |
| 205 | + //auto jump |
| 206 | + if( |
| 207 | + (cactus1.position.x <= trexXright + 5 && cactus1.position.x > trexXright) || |
| 208 | + (cactus2.position.x <= trexXright + 5 && cactus2.position.x > trexXright) || |
| 209 | + (pterodactyl1.position.y > 30 && pterodactyl1.position.x <= trexXright + 5 && pterodactyl1.position.x > trexXright) |
| 210 | + ) trex.jump(); |
| 211 | + //auto duck |
| 212 | + trex.duck( |
| 213 | + (pterodactyl1.position.y <= 30 && pterodactyl1.position.y > 20 && pterodactyl1.position.x <= trexXright + 15 && pterodactyl1.position.x > trex.position.x) |
| 214 | + ); |
| 215 | +#endif |
198 | 216 |
|
199 | 217 | //logic and animation step
|
200 | 218 | for(uint8_t i = 0; i < sprites.size(); ++i)
|
@@ -240,7 +258,9 @@ void setup() {
|
240 | 258 | spalshScreen();
|
241 | 259 | lcd.setAddressingMode(LCD_IF_VIRTUAL_WIDTH(SSD1309<SPIClass>::VerticalAddressingMode, SSD1309<SPIClass>::HorizontalAddressingMode));
|
242 | 260 | srand((randByte()<<8) | randByte());
|
243 |
| - //EEPROM.put(EEPROM_HI_SCORE, hiScore); //uncomment to set HI score to 0 |
| 261 | +#ifdef RESET_HI_SCORE |
| 262 | + EEPROM.put(EEPROM_HI_SCORE, hiScore); |
| 263 | +#endif |
244 | 264 | EEPROM.get(EEPROM_HI_SCORE, hiScore);
|
245 | 265 | if(hiScore == 0xFFFF) hiScore = 0;
|
246 | 266 | }
|
|
0 commit comments