commit b68302b1300ad74f915d2c20b6f61abd9d19d982
parent 43077fd9a80eb52f92ba44cb532eeaff88d45e38
Author: bsandro <email@bsandro.tech>
Date: Sun, 29 May 2022 01:45:56 +0300
DPI scale fixes
Diffstat:
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/main.c b/main.c
@@ -16,10 +16,11 @@
#define GAME_WIN_HEIGHT 600
#define GAME_FPS 60
#define GAME_FALL_ACCEL 0.85 // pixels per second^2 essentially
-#define GAME_BG_SCROLL_VELOCITY 0.3
-#define GAME_SCROLL_VELOCITY 0.4
+#define GAME_BG_SCROLL_VELOCITY 0.05
+#define GAME_SCROLL_VELOCITY 0.2
#define GAME_COLUMN_WIDTH 90
#define GAME_COLUMN_HEIGHT 200
+#define GAME_BOOST_ACCEL -500
static float s_dpi_scale;
@@ -74,9 +75,10 @@ bool check_game_over(struct game_t *game) {
}
void draw_game(uint64_t ftime, struct game_t *game) {
- game->ship.velocity += game->ship.accel * ftime;
+ game->ship.velocity += game->ship.accel * ftime * s_dpi_scale;
game->ship.rect.y += (ftime * game->ship.velocity / 1000.0);
- int bg_offset = ftime * GAME_BG_SCROLL_VELOCITY; // background position offset
+ int bg_offset = ftime * GAME_BG_SCROLL_VELOCITY * s_dpi_scale; // background position offset
+ int col_offset = ftime * GAME_SCROLL_VELOCITY * s_dpi_scale;
game->bg_x = (game->bg_x - bg_offset) % game->bg.rect.w; // can be only %width max
if (check_game_over(game)) {
@@ -106,7 +108,7 @@ void draw_game(uint64_t ftime, struct game_t *game) {
// columns
for (int i = 0; i < game->columns_count; ++i) {
SDL_Rect *column = game->columns + i;
- column->x -= bg_offset;
+ column->x -= col_offset;
if (column->x + column->w < 0) {
// column should reappear from the right side
place_column(&game->columns, game->columns_count, column);
@@ -251,7 +253,7 @@ int main(int argc, char *argv[]) {
// menu
struct menu_t menu = {0};
menu.game = &game;
- menu.font = TTF_OpenFont("assets/APL386.ttf", 70);
+ menu.font = TTF_OpenFont("assets/APL386.ttf", 30 * s_dpi_scale);
assert(menu.font != NULL);
// main game loop
@@ -267,7 +269,7 @@ int main(int argc, char *argv[]) {
}
if (event.key.keysym.sym == SDLK_SPACE) {
if (game.state == GAME_STATE_RUNNING) {
- game.ship.velocity = -600;
+ game.ship.velocity = GAME_BOOST_ACCEL * s_dpi_scale;
} else { // reset game
game.state = GAME_STATE_RUNNING;
game.ship.velocity = 0;