26 lines
922 B
C++
26 lines
922 B
C++
// src/render/player_positioning.cpp
|
|
#include "player_positioning.h"
|
|
#include <cstdio>
|
|
|
|
// Convert a pivot coordinate (bottom-left) to the top-left draw position
|
|
PlayerPosition get_aligned_frame_position(PlayerPosition base, int frame_index) {
|
|
if (frame_index < 0 || frame_index >= PLAYER_FRAME_COUNT)
|
|
frame_index = 0;
|
|
|
|
int sprite_height = 0;
|
|
if (frame_index == 0)
|
|
sprite_height = PLAYER_MASK_LINES_FRAME_1;
|
|
else if (frame_index == 1)
|
|
sprite_height = PLAYER_MASK_LINES_FRAME_2;
|
|
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
|
|
return draw_pos;
|
|
}
|