some renames, nothing much

This commit is contained in:
Priec
2025-11-14 19:39:19 +01:00
parent b9ca8df59b
commit 4ed4452fae
6 changed files with 39 additions and 38 deletions

View File

@@ -19,6 +19,7 @@ constexpr auto MESSAGE_DISPLAY_DURATION = 1s;
constexpr int PLAYER_X = 9;
constexpr int PLAYER_Y = 6;
// PlayerState is what user pressed. We are mapping CharacterState to it
enum class PlayerState { Walk1, Walk2, Crawl1 };
struct WalkingState {
@@ -86,16 +87,16 @@ static bool update_animation(Timer &anim_timer, int &shift, int speed) {
return false;
}
static PlayerFrame get_player_frame(PlayerState state) {
static CharacterFrame get_character_frame(PlayerState state) {
switch (state) {
case PlayerState::Walk1:
return PlayerFrame::Walk1;
return CharacterFrame::Walk1;
case PlayerState::Walk2:
return PlayerFrame::Walk2;
return CharacterFrame::Walk2;
case PlayerState::Crawl1:
return PlayerFrame::Crawl1;
return CharacterFrame::Crawl1;
default:
return PlayerFrame::Walk1;
return CharacterFrame::Walk1;
}
}
@@ -129,7 +130,7 @@ void render_loop(int speed) {
anim_timer.start();
int shift = 0;
PlayerPosition pos = {PLAYER_X, PLAYER_Y};
CharacterPosition pos = {PLAYER_X, PLAYER_Y};
const char *bg_file = "background_dark_inverted.txt";
bool need_redraw = false;
@@ -157,9 +158,9 @@ void render_loop(int speed) {
if (need_redraw) {
draw_mask(bg_file, shift, message_active ? message : nullptr);
PlayerFrame player_frame = get_player_frame(player_state.current_state);
PlayerPosition draw_pos = get_aligned_frame_position(pos, player_frame);
draw_player(draw_pos.x, draw_pos.y, player_frame);
CharacterFrame player_frame = get_character_frame(player_state.current_state);
CharacterPosition draw_pos = get_aligned_frame_position(pos, player_frame);
draw_character(draw_pos.x, draw_pos.y, player_frame);
// alternate between frame 0 and 1 when not crawling
if (player_state.current_state != PlayerState::Crawl1) {

View File

@@ -3,26 +3,26 @@
#include "player_mask.h"
#include <cstdio>
void draw_player(int x, int y, PlayerFrame frame) {
void draw_character(int x, int y, CharacterFrame frame) {
int frame_index = static_cast<int>(frame);
if (frame_index < 0 || frame_index >= PLAYER_FRAME_COUNT)
if (frame_index < 0 || frame_index >= CHARACTER_FRAME_COUNT)
frame_index = 0; // fallback safety
const char **character = PLAYER_FRAMES[frame_index];
int character_height = 0;
switch (frame) {
case PlayerFrame::Walk1:
character_height = PLAYER_MASK_LINES_FRAME_1;
case CharacterFrame::Walk1:
character_height = CHARACTER_HEIGHT_1;
break;
case PlayerFrame::Walk2:
character_height = PLAYER_MASK_LINES_FRAME_2;
case CharacterFrame::Walk2:
character_height = CHARACTER_HEIGHT_2;
break;
case PlayerFrame::Crawl1:
character_height = PLAYER_MASK_LINES_FRAME_3;
case CharacterFrame::Crawl1:
character_height = CHARACTER_HEIGHT_3;
break;
default:
character_height = PLAYER_MASK_LINES_FRAME_1;
character_height = CHARACTER_HEIGHT_1;
break;
}

View File

@@ -3,4 +3,4 @@
#include "player_mask.h"
// Draw the player object starting at given (x, y)
void draw_player(int x, int y, PlayerFrame frame);
void draw_character(int x, int y, CharacterFrame frame);

View File

@@ -3,7 +3,7 @@
#pragma once
// Player frame 1
static const char *PLAYER_MASK_FRAME_1[] = {
static const char *CHARACTER_MASK_FRAME_1[] = {
".....a@$..",
".....7PF..",
"..yaM@@__y",
@@ -14,7 +14,7 @@ static const char *PLAYER_MASK_FRAME_1[] = {
};
// Player frame 2
static const char *PLAYER_MASK_FRAME_2[] = {
static const char *CHARACTER_MASK_FRAME_2[] = {
".g@$",
".7PF",
"y@$.",
@@ -25,14 +25,14 @@ static const char *PLAYER_MASK_FRAME_2[] = {
};
// Player frame 3 (triggered)
static const char *PLAYER_MASK_FRAME_3[] = {
static const char *CHARACTER_MASK_FRAME_3[] = {
".._$@.",
".$By`.",
"4@$@@a",
"aa@W@."
};
enum class PlayerFrame {
enum class CharacterFrame {
Walk1 = 0,
Walk2,
Crawl1,
@@ -41,14 +41,14 @@ enum class PlayerFrame {
// Combine frames for easy access
static const char **PLAYER_FRAMES[] = {
PLAYER_MASK_FRAME_1, // Walk1
PLAYER_MASK_FRAME_2, // Walk1
PLAYER_MASK_FRAME_3 // Crawl1
CHARACTER_MASK_FRAME_1, // Walk1
CHARACTER_MASK_FRAME_2, // Walk1
CHARACTER_MASK_FRAME_3 // Crawl1
};
static const int PLAYER_FRAME_COUNT = static_cast<int>(PlayerFrame::COUNT);
static const int CHARACTER_FRAME_COUNT = static_cast<int>(CharacterFrame::COUNT);
// Height per frame
static const int PLAYER_MASK_LINES_FRAME_1 = sizeof(PLAYER_MASK_FRAME_1) / sizeof(PLAYER_MASK_FRAME_1[0]);
static const int PLAYER_MASK_LINES_FRAME_2 = sizeof(PLAYER_MASK_FRAME_2) / sizeof(PLAYER_MASK_FRAME_2[0]);
static const int PLAYER_MASK_LINES_FRAME_3 = sizeof(PLAYER_MASK_FRAME_3) / sizeof(PLAYER_MASK_FRAME_3[0]);
static const int CHARACTER_HEIGHT_1 = sizeof(CHARACTER_MASK_FRAME_1) / sizeof(CHARACTER_MASK_FRAME_1[0]);
static const int CHARACTER_HEIGHT_2 = sizeof(CHARACTER_MASK_FRAME_2) / sizeof(CHARACTER_MASK_FRAME_2[0]);
static const int CHARACTER_HEIGHT_3 = sizeof(CHARACTER_MASK_FRAME_3) / sizeof(CHARACTER_MASK_FRAME_3[0]);

View File

@@ -4,20 +4,20 @@
#include <cstdio>
// Convert a pivot coordinate (bottom-left) to the top-left draw position
PlayerPosition get_aligned_frame_position(PlayerPosition base, PlayerFrame frame) {
CharacterPosition get_aligned_frame_position(CharacterPosition base, CharacterFrame frame) {
int frame_index = static_cast<int>(frame);
if (frame_index < 0 || frame_index >= PLAYER_FRAME_COUNT)
if (frame_index < 0 || frame_index >= CHARACTER_FRAME_COUNT)
frame_index = 0;
int character_height = 0;
if (frame_index == 0)
character_height = PLAYER_MASK_LINES_FRAME_1;
character_height = CHARACTER_HEIGHT_1;
else if (frame_index == 1)
character_height = PLAYER_MASK_LINES_FRAME_2;
character_height = CHARACTER_HEIGHT_2;
else
character_height = PLAYER_MASK_LINES_FRAME_3;
character_height = CHARACTER_HEIGHT_3;
PlayerPosition draw_pos;
CharacterPosition draw_pos;
draw_pos.x = base.x;
draw_pos.y = (VIEW_HEIGHT - base.y) - character_height;

View File

@@ -3,10 +3,10 @@
#include "../background_dark_inverted.h"
#include "player_mask.h"
struct PlayerPosition {
struct CharacterPosition {
int x;
int y;
};
// Calculates drawing position relative to bottom-left pivot
PlayerPosition get_aligned_frame_position(PlayerPosition base, PlayerFrame frame);
CharacterPosition get_aligned_frame_position(CharacterPosition base, CharacterFrame frame);