Skip to content

Commit 841f17c

Browse files
committed
add autoplay mode
1 parent 91639bf commit 841f17c

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

t-rex-duino/t-rex-duino.ino

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
* LCD: OLED SSD1309 128x64
1111
*/
1212

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+
1328
/* Game Balance Settings */
1429
#define PLAYER_SAFE_ZONE_WIDTH 32 //minimum distance between obstacles (px)
1530
#define CACTI_RESPAWN_RATE 50 //lower -> more frequent, max 255
@@ -24,17 +39,6 @@
2439
#define TARGET_FPS_START 23
2540
#define TARGET_FPS_MAX 48 //gradually increase FPS to that value to make the game faster and harder
2641

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-
3842
/* Display Settings */
3943
#define LCD_HEIGHT 64U
4044
#define LCD_WIDTH 128U
@@ -192,9 +196,23 @@ void gameLoop(uint16_t &hiScore) {
192196
heartLive.eat();
193197
}
194198

199+
#ifndef AUTO_PLAY
195200
//constrols
196201
if(isPressedJump()) trex.jump();
197202
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
198216

199217
//logic and animation step
200218
for(uint8_t i = 0; i < sprites.size(); ++i)
@@ -240,7 +258,9 @@ void setup() {
240258
spalshScreen();
241259
lcd.setAddressingMode(LCD_IF_VIRTUAL_WIDTH(SSD1309<SPIClass>::VerticalAddressingMode, SSD1309<SPIClass>::HorizontalAddressingMode));
242260
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
244264
EEPROM.get(EEPROM_HI_SCORE, hiScore);
245265
if(hiScore == 0xFFFF) hiScore = 0;
246266
}

0 commit comments

Comments
 (0)