Prepare for display orientation part 1 (#2661)

This commit is contained in:
Totoo
2025-05-22 17:24:53 +02:00
committed by GitHub
parent 6f6d863a14
commit a1d7cf2b86
85 changed files with 405 additions and 334 deletions

View File

@@ -12,8 +12,8 @@ namespace ui::external_app::breakout {
Ticker game_timer;
int paddle_x = (SCREEN_WIDTH - PADDLE_WIDTH) / 2;
float ball_x = SCREEN_WIDTH / 2;
int paddle_x = 0;
float ball_x = 0;
float ball_y = GAME_AREA_BOTTOM - PADDLE_HEIGHT - BALL_SIZE - 1;
float ball_dx = 1.5f;
float ball_dy = -2.0f;
@@ -105,7 +105,7 @@ void game_timer_check() {
}
void init_game() {
paddle_x = (SCREEN_WIDTH - PADDLE_WIDTH) / 2;
paddle_x = (screen_width - PADDLE_WIDTH) / 2;
score = 0;
lives = 3;
level = 1;
@@ -157,7 +157,7 @@ void draw_screen() {
}
void draw_borders() {
rect(0, GAME_AREA_TOP - 1, SCREEN_WIDTH, GAME_AREA_TOP, COLOR_BORDER);
rect(0, GAME_AREA_TOP - 1, screen_width, GAME_AREA_TOP, COLOR_BORDER);
}
void draw_bricks() {
@@ -218,14 +218,14 @@ void move_paddle_left() {
}
void move_paddle_right() {
if (paddle_x < SCREEN_WIDTH - PADDLE_WIDTH) {
if (paddle_x < screen_width - PADDLE_WIDTH) {
fillrect(paddle_x, PADDLE_Y, paddle_x + PADDLE_WIDTH, PADDLE_Y + PADDLE_HEIGHT, COLOR_BACKGROUND);
if (ball_attached) {
fillrect(ball_x, ball_y, ball_x + BALL_SIZE, ball_y + BALL_SIZE, COLOR_BACKGROUND);
}
paddle_x += 10;
if (paddle_x > SCREEN_WIDTH - PADDLE_WIDTH) paddle_x = SCREEN_WIDTH - PADDLE_WIDTH;
if (paddle_x > screen_width - PADDLE_WIDTH) paddle_x = screen_width - PADDLE_WIDTH;
if (ball_attached) {
ball_x = paddle_x + (PADDLE_WIDTH / 2) - (BALL_SIZE / 2);
@@ -277,8 +277,8 @@ void update_game() {
if (ball_x < 0) {
ball_x = 0;
ball_dx = -ball_dx;
} else if (ball_x > SCREEN_WIDTH - BALL_SIZE) {
ball_x = SCREEN_WIDTH - BALL_SIZE;
} else if (ball_x > screen_width - BALL_SIZE) {
ball_x = screen_width - BALL_SIZE;
ball_dx = -ball_dx;
}
@@ -381,7 +381,7 @@ void init_menu() {
auto style_blue = *ui::Theme::getInstance()->fg_blue;
auto style_cyan = *ui::Theme::getInstance()->fg_cyan;
int16_t screen_width = 240;
int16_t screen_width = ui::screen_width;
int16_t title_x = (screen_width - 17 * 8) / 2;
int16_t divider_width = 24 * 8;
int16_t divider_x = (screen_width - divider_width) / 2;
@@ -428,7 +428,7 @@ void init_game_over() {
auto style_red = *ui::Theme::getInstance()->fg_red;
auto style_yellow = *ui::Theme::getInstance()->fg_yellow;
int16_t screen_width = 240;
// int16_t screen_width = screen_width;
int16_t title_width = 9 * 8;
int16_t title_x = (screen_width - title_width) / 2;
int16_t score_text_width = (16 + std::to_string(score).length()) * 8;
@@ -484,6 +484,8 @@ void reset_game() {
BreakoutView::BreakoutView(NavigationView& nav)
: nav_{nav} {
paddle_x = (screen_width - PADDLE_WIDTH) / 2;
ball_x = screen_width / 2;
add_children({&dummy});
game_timer.attach(&game_timer_check, 1.0 / 60.0);
}

View File

@@ -56,8 +56,6 @@ class Ticker {
void detach();
};
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
#define PADDLE_WIDTH 40
#define PADDLE_HEIGHT 10
#define BALL_SIZE 8
@@ -141,7 +139,7 @@ class BreakoutView : public View {
NavigationView& nav_;
Button dummy{
{240, 0, 0, 0},
{screen_width, 0, 0, 0},
""};
MessageHandlerRegistration message_handler_frame_sync{