Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snake dev #134

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions fw/Core/Hitcon/App/SnakeApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,7 @@ SnakeApp::SnakeApp()
INTERVAL) {}

/* TODO:
* 1. (done) queue task only once
* 2. random snake begin
* 3. event when _len = 128
* 4. store score
* 6. add OnButton when game over
* 7. (done 1ms) measure Routine time
* 8. (done) add Ready... scrolling text
* 9. (done) implement multi-player mode
* 10. xboard on connect/disconnect event
* 11. check connection status
* 12. (done) add menu to choose game mode
* 13. dynamic interval?
* 14. show win/lose and score when game over
*/
Expand All @@ -63,8 +53,9 @@ void SetMultiplayer() { snake_app.mode = MODE_MULTIPLAYER; }

void SnakeApp::OnExit() { scheduler.DisablePeriodic(&_routine_task); }

void SnakeApp::OnButton(button_t button) {
void SnakeApp::OnEdgeButton(button_t button) {
direction_t btn_direction = NONE;
if (button & BUTTON_KEYUP_BIT) return;

switch (button & BUTTON_VALUE_MASK) {
case BUTTON_RIGHT:
Expand Down Expand Up @@ -92,7 +83,6 @@ void SnakeApp::OnButton(button_t button) {
}
break;
case BUTTON_BACK:
case BUTTON_LONG_BACK:
if (mode == MODE_MULTIPLAYER) {
uint8_t code = PACKET_GAME_LEAVE;
g_xboard_logic.QueueDataForTx(&code, 1, SNAKE_RECV_ID);
Expand All @@ -106,6 +96,8 @@ void SnakeApp::OnButton(button_t button) {
_direction = btn_direction;
}

void SnakeApp::OnButton(button_t button) {}

bool SnakeApp::OnSnake(uint8_t index) {
bool on_snake = false;

Expand Down Expand Up @@ -153,8 +145,10 @@ void SnakeApp::InitGame() {
_direction = DIRECTION_RIGHT;
_last_direction = DIRECTION_RIGHT;
_len = 2;
_body[0] = 36;
_body[1] = 35;
uint8_t row = g_fast_random_pool.GetRandom() % (DISPLAY_HEIGHT - 4) + 2;
uint8_t col = g_fast_random_pool.GetRandom() % (DISPLAY_WIDTH - 4) + 1;
_body[0] = row * DISPLAY_WIDTH + col;
_body[1] = _body[0] - 1;
_score = 0;
GenerateFood();
}
Expand Down
1 change: 1 addition & 0 deletions fw/Core/Hitcon/App/SnakeApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SnakeApp : public App {
void OnExit() override;
void OnButton(button_t button) override;
void OnXBoardRecv(void* arg);
void OnEdgeButton(button_t button) override;
};

extern SnakeApp snake_app;
Expand Down
Loading