From 3037b9305b10b58e01055c21bbce223d7b2c673f Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 3 Apr 2024 14:33:30 -0400 Subject: Added player position tracking --- src/tracker_panel.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/tracker_panel.cpp') diff --git a/src/tracker_panel.cpp b/src/tracker_panel.cpp index daaeff7..5f9f8ea 100644 --- a/src/tracker_panel.cpp +++ b/src/tracker_panel.cpp @@ -10,6 +10,7 @@ constexpr int AREA_ACTUAL_SIZE = 64; constexpr int AREA_BORDER_SIZE = 5; constexpr int AREA_EFFECTIVE_SIZE = AREA_ACTUAL_SIZE + AREA_BORDER_SIZE * 2; +constexpr int PLAYER_SIZE = 96; TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) { map_image_ = wxImage(GetAbsolutePath("assets/lingo_map.png").c_str(), @@ -18,6 +19,12 @@ TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) { return; } + player_image_ = + wxImage(GetAbsolutePath("assets/player.png").c_str(), wxBITMAP_TYPE_PNG); + if (!player_image_.IsOk()) { + return; + } + for (const MapArea &map_area : GD_GetMapAreas()) { AreaIndicator area; area.area_id = map_area.id; @@ -50,6 +57,20 @@ void TrackerPanel::OnPaint(wxPaintEvent &event) { wxPaintDC dc(this); dc.DrawBitmap(rendered_, 0, 0); + if (AP_GetPlayerPosition().has_value()) { + // 1588, 1194 + // 14x14 -> 154x154 + double intended_x = + 1588.0 + (std::get<0>(*AP_GetPlayerPosition()) * (154.0 / 14.0)); + double intended_y = + 1194.0 + (std::get<1>(*AP_GetPlayerPosition()) * (154.0 / 14.0)); + + int real_x = offset_x_ + scale_x_ * intended_x - scaled_player_.GetWidth() / 2; + int real_y = offset_y_ + scale_y_ * intended_y - scaled_player_.GetHeight() / 2; + + dc.DrawBitmap(scaled_player_, real_x, real_y); + } + event.Skip(); } @@ -91,6 +112,17 @@ void TrackerPanel::Redraw() { map_image_.Scale(final_width, final_height, wxIMAGE_QUALITY_NORMAL) .Size(panel_size, {final_x, final_y}, 0, 0, 0)); + offset_x_ = final_x; + offset_y_ = final_y; + scale_x_ = static_cast(final_width) / image_size.GetWidth(); + scale_y_ = static_cast(final_height) / image_size.GetHeight(); + + int player_width = PLAYER_SIZE * scale_x_; + int player_height = PLAYER_SIZE * scale_y_; + scaled_player_ = + wxBitmap(player_image_.Scale(player_width > 0 ? player_width : 1, + player_height > 0 ? player_height : 1)); + wxMemoryDC dc; dc.SelectObject(rendered_); -- cgit 1.4.1