Skip to content

Commit

Permalink
Fixed score and percentage at level completed when scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
twojstaryzdomu committed Jul 20, 2022
1 parent e3ffd68 commit f88cb7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
5 changes: 3 additions & 2 deletions p2/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern struct options_t g_options;
#define STRING_SPR_W 16
#define STRING_SPR_H 11
#define CHARACTER_OFFSET 241
#define DIGITS_OFFSET 0x1C70

#define CHEATS_NO_HIT (1 << 0)
#define CHEATS_UNLIMITED_LIFES (1 << 1)
Expand Down Expand Up @@ -417,8 +418,8 @@ extern void video_draw_panel(const uint8_t *src);
extern void video_draw_panel_number(int offset, int num);
extern void video_draw_number(int offset, int num);
extern void video_draw_character_spr(int offset, uint8_t chr);
extern void video_draw_string2(int offset, const char *str);
extern void video_draw_centred_string(const char *s, bool clip);
extern void video_draw_format_string(int offset, const char *format, ...);
extern void video_draw_string_centred(const char *s, bool clip);
extern void video_draw_tile(const uint8_t *src, int x, int y);
extern void video_convert_tiles(uint8_t *data, int len);
extern void video_load_front_tiles();
Expand Down
21 changes: 4 additions & 17 deletions p2/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,7 @@ static void level_draw_messages() {
if (g_message.get())
g_message.timestamp = g_sys.get_timestamp();
if (g_message.get())
video_draw_centred_string(g_message.get(), 0);
video_draw_string_centred(g_message.get(), 0);
}

static void level_resize() {
Expand Down Expand Up @@ -3667,31 +3667,18 @@ static void level_player_death_animation() {

static void level_completed_bonuses_animation_draw_score() {
const int score_digits = _score_8_digits ? 8 : 7;
video_draw_string2(0x230, "SCORE");
int score = g_vars.score * 10;
for (int i = 0; i < score_digits; ++i) {
const int digit = score % 10;
score /= 10;
video_draw_number(0x23C + (score_digits - 1 - i) * 16 / 8, digit);
}
video_draw_format_string(0x230, "SCORE %0.*d", score_digits, score);
if (g_res.dos_demo) {
return;
}
video_draw_string2(0x410, "LEVEL COMPLETED");
int percentage = 100;
const int total = g_vars.level_complete_secrets_count + g_vars.level_complete_bonuses_count;
if (total != 0) {
const int current = g_vars.level_current_secrets_count + g_vars.level_current_bonuses_count;
percentage = (current * 100) / total;
}
for (int i = 0; i < 3; ++i) {
const int digit = percentage % 10;
percentage /= 10;
video_draw_number(0x430 + (2 - i) * 16 / 8, digit);
if (percentage == 0) {
break;
}
}
video_draw_format_string(0x410, "LEVEL COMPLETED %3d", percentage);
video_draw_character_spr(0x436, 0x1A);
}

Expand Down Expand Up @@ -3996,7 +3983,7 @@ static void level_pause() {
video_transition_close();
video_clear();
level_draw_panel();
video_draw_centred_string("PAUSED", 1);
video_draw_string_centred("PAUSED", 1);
g_sys.update_screen(g_res.vga, 1);
const int diff = (g_vars.timestamp + (1000 / 30)) - g_sys.get_timestamp();
while (g_sys.paused) {
Expand Down
37 changes: 23 additions & 14 deletions p2/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "resource.h"
#include "sys.h"
#include "util.h"
#include <stdarg.h>

#define MAX_SPRITES 480
#define MAX_SPRITESHEET_W 2048
Expand Down Expand Up @@ -85,7 +86,7 @@ void video_draw_panel_number(int offset, int num) {
}

void video_draw_number(int offset, int num) {
const uint8_t *fnt = g_res.allfonts + 0x1C70;
const uint8_t *fnt = g_res.allfonts + DIGITS_OFFSET;
const int y = (offset * 8) / ORIG_W;
const int x = (offset * 8) % ORIG_W;
decode_planar(fnt + num * NUMBER_W * NUMBER_H / 2, g_res.vga + y * GAME_SCREEN_W + x, GAME_SCREEN_W, NUMBER_W, NUMBER_H, 0);
Expand All @@ -97,20 +98,8 @@ void video_draw_character_spr(int offset, uint8_t chr) {
video_draw_sprite(CHARACTER_OFFSET + chr, x, y, 0, false);
}

void video_draw_string2(int offset, const char *s) {
while (*s) {
const uint8_t chr = *s++;
if (chr != ' ') {
video_draw_character_spr(offset, chr - 0x41);
}
offset += 2;
}
}

void video_draw_centred_string(const char *s, bool clip) {
void video_draw_string_clipped(const char *s, int x, int y, bool clip) {
const uint8_t l = strlen(s);
int x = (TILEMAP_SCREEN_W - STRING_SPR_W * l) / 2;
const int y = (TILEMAP_SCREEN_H - STRING_SPR_H) / 2;
const uint8_t uppercase_offset = 65;
const uint8_t lowercase_offset = 32;
const uint8_t number_offset = 6;
Expand All @@ -129,6 +118,26 @@ void video_draw_centred_string(const char *s, bool clip) {
}
}

void video_draw_format_string(int offset, const char *format, ...) {
char *s;
va_list args;
va_start(args, format);
vasprintf(&s, format, args);
va_end(args);
const int y = (offset * 8) / ORIG_W;
const int x = (offset * 8) % ORIG_W;
video_draw_string_clipped(s, x, y, 0);
free(s);
}


void video_draw_string_centred(const char *s, bool clip) {
const uint8_t l = strlen(s);
int x = (TILEMAP_SCREEN_W - STRING_SPR_W * l) / 2;
const int y = (TILEMAP_SCREEN_H - STRING_SPR_H) / 2;
video_draw_string_clipped(s, x, y, clip);
}

void video_resize() {
if (g_sys.resize) {
free(g_res.vga);
Expand Down

0 comments on commit f88cb7e

Please sign in to comment.