Skip to content

Commit

Permalink
Add Dino ignore big cactus combo feature
Browse files Browse the repository at this point in the history
  • Loading branch information
moon-jam authored and john0312 committed Aug 17, 2024
1 parent ebc581b commit 91cb3f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
32 changes: 23 additions & 9 deletions fw/Core/Hitcon/App/DinoApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Logic/RandomPool.h>
#include <Service/Sched/Scheduler.h>
#include <Util/uint_to_str.h>
#include <Secret/secret.h>

#include <cmath>

Expand All @@ -17,6 +18,8 @@ namespace hitcon {
namespace app {
namespace dino {

int combo_button_ctr = 0;

DinoApp dino_app;

DinoApp::DinoApp()
Expand All @@ -41,6 +44,17 @@ void DinoApp::OnEntry() {
void DinoApp::OnExit() { scheduler.DisablePeriodic(&_routine_task); }

void DinoApp::OnButton(button_t button) {
if (button == COMBO_BUTTON_DINO[combo_button_ctr]) {
combo_button_ctr++;
} else {
combo_button_ctr = (button == COMBO_BUTTON_DINO[0]) ? 1 : 0;
}
if (combo_button_ctr == COMBO_BUTTON_DINO_LEN) {
// surprise
combo_button_ctr = (button == COMBO_BUTTON_DINO[0]) ? 1 : 0;
_no_big_cactus = true;
}

switch (button & BUTTON_VALUE_MASK) {
case BUTTON_BACK:
badge_controller.change_app(&main_menu);
Expand Down Expand Up @@ -84,27 +98,27 @@ void DinoApp::Routine(void* unused) {
if (_obstacle_interval > DINO_OBS_LEAST_DISTANCE) {
if ((_obstacle_interval > DISPLAY_WIDTH * 2) ||
(g_fast_random_pool.GetRandom() % _generate_obs_rate == 0)) {
switch (g_fast_random_pool.GetRandom() % 4) {
switch (g_fast_random_pool.GetRandom() % (_no_big_cactus ? 3 : 4)) {
case 0: // bird
writeObsByte(DISPLAY_WIDTH, bird_bitmap[0]);
writeObsByte(DISPLAY_WIDTH + 1, bird_bitmap[1]);
writeObsByte(DISPLAY_WIDTH + 2, bird_bitmap[2]);
_obstacle_interval = -6;
break;
case 1: // big cactus
writeObsByte(DISPLAY_WIDTH, big_cactus_bitmap[0]);
writeObsByte(DISPLAY_WIDTH + 1, big_cactus_bitmap[1]);
writeObsByte(DISPLAY_WIDTH + 2, big_cactus_bitmap[2]);
_obstacle_interval = -5;
break;
case 2: // small tall cactus
case 1: // small tall cactus
writeObsByte(DISPLAY_WIDTH, small_tall_cactus_bitmap[0]);
_obstacle_interval = -3;
break;
case 3: // small short cactus
case 2: // small short cactus
writeObsByte(DISPLAY_WIDTH, small_short_cactus_bitmap[0]);
_obstacle_interval = -3;
break;
case 3: // big cactus
writeObsByte(DISPLAY_WIDTH, big_cactus_bitmap[0]);
writeObsByte(DISPLAY_WIDTH + 1, big_cactus_bitmap[1]);
writeObsByte(DISPLAY_WIDTH + 2, big_cactus_bitmap[2]);
_obstacle_interval = -5;
break;
default:
my_assert(false);
}
Expand Down
1 change: 1 addition & 0 deletions fw/Core/Hitcon/App/DinoApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DinoApp : public App {
uint8_t _game_over : 1;
uint8_t _dino_ani_frame : 1;
int8_t _dino_jump_vel : 3;
bool _no_big_cactus = false;
enum dino_actions { DINO_RUN, DINO_JUMP, DINO_CRUNCH } _dino_state;
void Routine(void* unused);
bool dinoDied();
Expand Down
4 changes: 4 additions & 0 deletions fw/Core/Hitcon/Secret/secret.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ constexpr button_t COMBO_BUTTON[] = {
BUTTON_UP, BUTTON_UP, BUTTON_DOWN, BUTTON_DOWN, BUTTON_LEFT,
BUTTON_RIGHT, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_BRIGHTNESS, BUTTON_MODE,
};
constexpr button_t COMBO_BUTTON_DINO[] = {
BUTTON_DOWN, BUTTON_DOWN, BUTTON_RIGHT, BUTTON_RIGHT, BUTTON_OK
};
constexpr size_t COMBO_BUTTON_LEN = sizeof(COMBO_BUTTON) / sizeof(button_t);
constexpr size_t COMBO_BUTTON_DINO_LEN = sizeof(COMBO_BUTTON_DINO) / sizeof(button_t);
extern int combo_button_ctr;

constexpr uint8_t kGameAchievementData[] = {
Expand Down

0 comments on commit 91cb3f1

Please sign in to comment.