multiple frames now added and working
This commit is contained in:
@@ -1,25 +1,30 @@
|
||||
// src/render/player_positioning.cpp
|
||||
#include "player_positioning.h"
|
||||
#include "../assets/background_frame.h"
|
||||
#include "../assets/character_walk_frames.h"
|
||||
#include "../assets/character_run_frames.h"
|
||||
#include "../assets/character_crawl_frames.h"
|
||||
#include <cstdio>
|
||||
|
||||
// Convert a pivot coordinate (bottom-left) to the top-left draw position
|
||||
CharacterPosition get_aligned_frame_position(CharacterPosition base, CharacterFrame frame) {
|
||||
int frame_index = static_cast<int>(frame);
|
||||
if (frame_index < 0 || frame_index >= CHARACTER_FRAME_COUNT)
|
||||
frame_index = 0;
|
||||
|
||||
CharacterPosition get_aligned_frame_position(CharacterPosition base,
|
||||
MovementType movement,
|
||||
int /*frame_index*/) {
|
||||
int character_height = 0;
|
||||
if (frame_index == 0)
|
||||
character_height = CHARACTER_HEIGHT_1;
|
||||
else if (frame_index == 1)
|
||||
character_height = CHARACTER_HEIGHT_2;
|
||||
else
|
||||
character_height = CHARACTER_HEIGHT_3;
|
||||
|
||||
CharacterPosition draw_pos;
|
||||
switch (movement) {
|
||||
case MovementType::Walk:
|
||||
character_height = CHARACTER_WALK_FRAME_HEIGHT;
|
||||
break;
|
||||
case MovementType::Run:
|
||||
character_height = CHARACTER_RUN_FRAME_HEIGHT;
|
||||
break;
|
||||
case MovementType::Crawl:
|
||||
character_height = CHARACTER_CRAWL_FRAME_HEIGHT;
|
||||
break;
|
||||
}
|
||||
|
||||
CharacterPosition draw_pos{};
|
||||
draw_pos.x = base.x;
|
||||
draw_pos.y = (VIEW_HEIGHT - base.y) - character_height;
|
||||
|
||||
return draw_pos;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user