mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-11-28 07:30:31 -05:00
Prepare for display orientation part 1 (#2661)
This commit is contained in:
parent
6f6d863a14
commit
a1d7cf2b86
85 changed files with 405 additions and 334 deletions
113
firmware/application/external/snake/ui_snake.hpp
vendored
113
firmware/application/external/snake/ui_snake.hpp
vendored
|
|
@ -32,36 +32,11 @@ enum {
|
|||
Black,
|
||||
};
|
||||
|
||||
extern const Color pp_colors[];
|
||||
extern Painter painter;
|
||||
extern bool but_RIGHT;
|
||||
extern bool but_LEFT;
|
||||
extern bool but_SELECT;
|
||||
|
||||
void cls();
|
||||
void background(int color);
|
||||
void fillrect(int x1, int y1, int x2, int y2, int color);
|
||||
void rect(int x1, int y1, int x2, int y2, int color);
|
||||
|
||||
#define wait(x) chThdSleepMilliseconds(x * 1000)
|
||||
|
||||
using Callback = void (*)(void);
|
||||
|
||||
class Ticker {
|
||||
public:
|
||||
Ticker() = default;
|
||||
void attach(Callback func, double delay_sec);
|
||||
void detach();
|
||||
};
|
||||
|
||||
#define SCREEN_WIDTH 240
|
||||
#define SCREEN_HEIGHT 320
|
||||
#define SNAKE_SIZE 10
|
||||
#define INFO_BAR_HEIGHT 25
|
||||
#define GAME_AREA_TOP (INFO_BAR_HEIGHT + 1)
|
||||
#define GAME_AREA_HEIGHT (SCREEN_HEIGHT - INFO_BAR_HEIGHT - 2)
|
||||
#define GRID_WIDTH ((SCREEN_WIDTH - 2) / SNAKE_SIZE)
|
||||
#define GRID_HEIGHT (GAME_AREA_HEIGHT / SNAKE_SIZE)
|
||||
#define STATE_MENU 0
|
||||
#define STATE_PLAYING 1
|
||||
#define STATE_GAME_OVER 2
|
||||
|
|
@ -71,35 +46,6 @@ class Ticker {
|
|||
#define COLOR_FOOD Red
|
||||
#define COLOR_BORDER White
|
||||
|
||||
extern Ticker game_timer;
|
||||
|
||||
extern int snake_x[GRID_WIDTH * GRID_HEIGHT];
|
||||
extern int snake_y[GRID_WIDTH * GRID_HEIGHT];
|
||||
extern int snake_length;
|
||||
extern int snake_dx;
|
||||
extern int snake_dy;
|
||||
extern int food_x;
|
||||
extern int food_y;
|
||||
extern int score;
|
||||
extern int game_state;
|
||||
extern bool initialized;
|
||||
|
||||
void game_timer_check();
|
||||
void init_game();
|
||||
void update_game();
|
||||
void draw_screen();
|
||||
void draw_snake();
|
||||
void draw_full_snake();
|
||||
void erase_tail(int x, int y);
|
||||
void draw_food();
|
||||
void erase_food();
|
||||
void draw_score();
|
||||
void draw_borders();
|
||||
void spawn_food();
|
||||
bool check_collision();
|
||||
void show_menu();
|
||||
void show_game_over();
|
||||
|
||||
class SnakeView : public View {
|
||||
public:
|
||||
SnakeView(NavigationView& nav);
|
||||
|
|
@ -112,12 +58,67 @@ class SnakeView : public View {
|
|||
void frame_sync();
|
||||
bool on_key(KeyEvent key) override;
|
||||
|
||||
void cls();
|
||||
void background(int color);
|
||||
void fillrect(int x1, int y1, int x2, int y2, int color);
|
||||
void rect(int x1, int y1, int x2, int y2, int color);
|
||||
void game_timer_check();
|
||||
void init_game();
|
||||
void update_game();
|
||||
void draw_screen();
|
||||
void draw_snake();
|
||||
void draw_full_snake();
|
||||
void erase_tail(int x, int y);
|
||||
void draw_food();
|
||||
void erase_food();
|
||||
void draw_score();
|
||||
void draw_borders();
|
||||
void spawn_food();
|
||||
bool check_collision();
|
||||
void show_menu();
|
||||
void show_game_over();
|
||||
void check_game_timer();
|
||||
|
||||
void attach(double delay_sec);
|
||||
void detach();
|
||||
|
||||
private:
|
||||
bool initialized = false;
|
||||
const Color pp_colors[9] = {
|
||||
Color::white(),
|
||||
Color::blue(),
|
||||
Color::yellow(),
|
||||
Color::purple(),
|
||||
Color::green(),
|
||||
Color::red(),
|
||||
Color::magenta(),
|
||||
Color::orange(),
|
||||
Color::black(),
|
||||
};
|
||||
NavigationView& nav_;
|
||||
Painter painter{};
|
||||
|
||||
std::vector<int> snake_x{}; //[GRID_WIDTH * GRID_HEIGHT];
|
||||
std::vector<int> snake_y{}; //[GRID_WIDTH * GRID_HEIGHT];
|
||||
int snake_length = 1;
|
||||
int snake_dx = 1;
|
||||
int snake_dy = 0;
|
||||
int food_x = 0, food_y = 0;
|
||||
int score = 0;
|
||||
int game_state = STATE_MENU;
|
||||
bool initialized = false;
|
||||
|
||||
int SCREEN_WIDTH = 0;
|
||||
int SCREEN_HEIGHT = 0;
|
||||
int GAME_AREA_HEIGHT = 0; //(SCREEN_HEIGHT - INFO_BAR_HEIGHT - 2);
|
||||
int GRID_WIDTH = 0; // ((SCREEN_WIDTH - 2) / SNAKE_SIZE);
|
||||
int GRID_HEIGHT = 0; //(GAME_AREA_HEIGHT / SNAKE_SIZE);
|
||||
|
||||
bool game_update_callback = false;
|
||||
double game_update_timeout = 0;
|
||||
uint32_t game_update_counter = 0;
|
||||
|
||||
Button dummy{
|
||||
{240, 0, 0, 0},
|
||||
{screen_width, 0, 0, 0},
|
||||
""};
|
||||
|
||||
MessageHandlerRegistration message_handler_frame_sync{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue