proper positioning works now

This commit is contained in:
Priec
2025-11-14 18:50:57 +01:00
parent cda395d6b9
commit 9170524d33
4 changed files with 10 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
// background_dark_inverted.h
#pragma once
static const char *BACKGROUND_DARK_INVERTED[] = {
static const char *BACKGROUND_MASK[] = {
"~`````````````````````````````````````````````````````````````````````````````````````\"````````````````````````````````~```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````+````````````````````~````````````````````````````````~```````````````````````````````````````````````````````",
"...................................................................,.......................:..........................................'.........`..:.....................................................................................................+...................................:...........:..,................................................",
"...........................\"............................................._................................+...........................................................................................................,..............................................`..............................................................!........................",
@@ -19,5 +19,4 @@ static const char *BACKGROUND_DARK_INVERTED[] = {
"...,,,,,,,,4@@@$g@....,7^=sa@@$a@@@@@@@@@@@@@@@@@@~``.`,,,,,,,,:::`,g@R@BZa$TTTTF5PM@@@@^:`'`~T5#@@y_`,u@~$@$@@g_,F,,,,`@@@@'':^na$g@@@=_:@@.`,.4__,,,,,,,,,g@@K:,,,,,,g@@@@w....,,,,,,,,,$@@$g@F...,,^=#aa@$gg@@@@@@@@@@@@@@@@@F``.`,,,,,,,,,::`,:@@P@R5$T~TTFFPP5@@@$:'``~~7P@@y_``,$E4@W@$@y,4::,,`3@@@[`:,raagg@@Fk`@@L.,.`g_,,,,,,,,,,g@@~:,,,,,,g@@@$..",
"..,:''``a$gg@$@@ZF...:,,,,,,:`~T@@@@@@@@@@@@@A@@^``...:,,,,,`,,::,.,@@@@@@@@,`.`````@@@[',,,,,,,,,,`TR@@@@@@@$@@@`'''':,A@MP.,,,,,\"~TT@,`3@@*g'.`4@':,,,,,,:EDT,,,,,,,_@@@@@$....:':':H$$g@$@@$@....,,,,,`:`~7R@@@@@@@@@@@@AR@@```..,',,,'``,,::,,d@0@@@@@y`.`````g@@@`',,,,,,,,,:79@$@@@@@@@@@'\"``':,!$FP~:,,,,,~~7@y.~A@mg@'.\"@F::,,,,,,4ER~,,,,,,,g@@@@@..",
};
static const int BACKGROUND_DARK_INVERTED_LINES =
sizeof(BACKGROUND_DARK_INVERTED) / sizeof(BACKGROUND_DARK_INVERTED[0]);
static const int VIEW_HEIGHT = sizeof(BACKGROUND_MASK) / sizeof(BACKGROUND_MASK[0]);

View File

@@ -11,8 +11,8 @@ void draw_mask(const char *unused_filename, int shift, const char *text) {
// Terminal clear + home
printf("\033[2J\033[H");
for (int i = 0; i < view_height && i < BACKGROUND_DARK_INVERTED_LINES; i++) {
const char *row = BACKGROUND_DARK_INVERTED[i];
for (int i = 0; i < view_height && i < VIEW_HEIGHT; i++) {
const char *row = BACKGROUND_MASK[i];
int width = strlen(row);
if (width == 0) {
printf("\r\n");

View File

@@ -16,8 +16,8 @@ constexpr size_t BUFFER_SIZE = 64;
constexpr auto CRAWL_DURATION = 300ms;
constexpr auto ANIMATION_TICK = 170ms;
constexpr auto MESSAGE_DISPLAY_DURATION = 1s;
constexpr int PLAYER_X = 18;
constexpr int PLAYER_Y = 13;
constexpr int PLAYER_X = 9;
constexpr int PLAYER_Y = 6;
enum class PlayerState { Walk1, Walk2, Crawl1 };
@@ -129,7 +129,7 @@ void render_loop(int speed) {
anim_timer.start();
int shift = 0;
PlayerPosition pos = {9, 9};
PlayerPosition pos = {PLAYER_X, PLAYER_Y};
const char *bg_file = "background_dark_inverted.txt";
bool need_redraw = false;

View File

@@ -1,5 +1,6 @@
// src/render/player_positioning.cpp
#include "player_positioning.h"
#include "../background_dark_inverted.h"
#include <cstdio>
// Convert a pivot coordinate (bottom-left) to the top-left draw position
@@ -15,11 +16,9 @@ PlayerPosition get_aligned_frame_position(PlayerPosition base, int frame_index)
else
sprite_height = PLAYER_MASK_LINES_FRAME_3;
// The X coordinate stays the same (left edge aligned)
// The Y coordinate moves upward by the sprite height,
// because the pivot is bottom-left, but rendering starts from top-left
PlayerPosition draw_pos;
draw_pos.x = base.x;
draw_pos.y = base.y - sprite_height + 1; // align to feet baseline
draw_pos.y = (VIEW_HEIGHT - base.y) - sprite_height;
return draw_pos;
}