From 041a565ae18a4673bc3be482774c0e6899a35d26 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Sat, 10 Jun 2023 18:51:23 +0200 Subject: [PATCH] Player size now correlated to world size --- assets/ring.png | Bin 0 -> 2498 bytes src/config.h | 6 ++++-- src/game/physics/map_simulation.cpp | 2 +- src/game/player/player.cpp | 18 +++++++++++++++--- src/game/player/player.hpp | 9 +++++++-- src/texture_config.h | 8 +++++--- 6 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 assets/ring.png diff --git a/assets/ring.png b/assets/ring.png new file mode 100644 index 0000000000000000000000000000000000000000..65b3c2f80f7623db38ef6d64b66adf92def473fd GIT binary patch literal 2498 zcmV;z2|f0SP)EX>4Tx04R}tkv&MmKpe$iTeVWE4t5Z6h)_FO5EXIMDionYs1;guFuC+YXws0R zxHt-~1qVMCs}3&Cx;nTDg5U>;tBaGOilA>^e5@H zmKHq%`nG|K>y{?(0hc?#z>_W+k|PCZ`U?f%{fxdT2lU?pp;foH<~~jzfDCn&x&aOj zfmo5U*F4_c-QL^3XPW)}0B!4XrI-gVF#rGn24YJ`L;(K){{a7>y{D4^000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2j>O~4kI_CX>@2HM@dakSAh-}000M>NklDX5u|kV0(KB9+)PjXa%+J=3v?HOg&)_L}o)ceN+$$L`+u zJEL(X6Ir@_Z{K_0)kR-uQ7QOKfpR>CNF@VyN5O9j{#J0I;2#AyQwX3G{Hx$nKevl3}w#jHkesCc?TW zAyhUduMl94yZsutr~!TgoHPY`hWED#?CM9A5RWt|qEdw{FyO!O1pOm$xD3D>5aIyX z^CZKUP>7HP0=`Y^OL@Npx}kvXNrn#a&|wonSVI;t@E5?JKo2;~#u6V>w^9;eA9$iw zAy^_TUG6QXa5oAD3XT-~pm$X4*Se{%s-a>?T4qGTv20v-JpQ9}lDT4pGt-Ibs z4L&D90*l|5lK-~NyMBrqymeT@D0c9BZI}E8me7lm1Qzg1zdsO&z1Q);kqbt#f&X6o ze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_4Jy>0lo(bJ}G#kU_(v}o$I%z*XWI<)e9GVPZInr$Hq?Z_w*XY3BCsj%Fhm- zNiLZ1`)8K3{kXvQI47v)f>v8XMe<#KU&MZq#S}|ur5aRry-V_oR4%q~NZYZ3?-e|5 z0}(XvkM%VlJJzL0?ZRETAbDHxl>2!7eokso+QRcxh)@Ck`4qWd$*#{)528@!{7F@QU$g_^$6?{xb7_;E0U?RW+FM9tOaPCPNpv1g^3`2U}~! zdH_6Re4F+G<9qd8z|a2%&R7W0fCyBGaI94!2r|?_-vORhfG1SogCc;ZE!fC#23#?= zh=miP0{FWAxzzylmCAk41gH_A$wbrACQfRE81i)x_OK~2Dq~j4;TdZ+z;`|5z4j|9 zLIFNl0?c3yHbRs`um{{8i0zt=UY(Ru4$auC{J9C>K}mg-1h|7LOe2VGI{LgOr3AU# zqb0xs$uQ@)76<526Cf}$LCreateBody(&bodyDef); b2CircleShape shape; - shape.m_radius = MAPSIM_PLAYER_RADIUS; + shape.m_radius = player->getWorldRadius(); shape.m_p.Set(0, 0); b2FixtureDef fixtureDef; diff --git a/src/game/player/player.cpp b/src/game/player/player.cpp index ab7684e..a3f1991 100644 --- a/src/game/player/player.cpp +++ b/src/game/player/player.cpp @@ -12,8 +12,9 @@ Player::Player(std::shared_ptr assignedInput, const std::string & input = std::move(assignedInput); - auto sprite = std::make_shared(skinRessourceName, sf::Vector2f{width, width}); - addChildScreenOffset(sprite, {-width / 2.f, -width / 2.f}); + auto radiusInIso = getIsoRadius(); + auto sprite = std::make_shared(skinRessourceName, sf::Vector2f{radiusInIso * 2.f, radiusInIso * 2.f}); + addChildScreenOffset(sprite, {-radiusInIso, -radiusInIso}); } sf::Vector2f Player::getTrackablePosition() const @@ -23,7 +24,8 @@ sf::Vector2f Player::getTrackablePosition() const sf::Vector2f Player::getTrackableSize() const { - return {width, width}; + auto isoRadius = getIsoRadius(); + return {isoRadius * 2.f, isoRadius * 2.f}; } void Player::update() @@ -61,3 +63,13 @@ int Player::getPlayerId() const { return playerId; } + +float Player::getIsoRadius() const +{ + return radiusInWorld * WORLD_TO_ISO_SCALE; +} + +float Player::getWorldRadius() const +{ + return radiusInWorld; +} diff --git a/src/game/player/player.hpp b/src/game/player/player.hpp index 1b11fa2..b08eea5 100644 --- a/src/game/player/player.hpp +++ b/src/game/player/player.hpp @@ -5,6 +5,7 @@ #include "../camera/ITrackable.h" #include "../../sprites/versatile_sprite.hpp" #include "../input/input_identity.h" +#include "../../config.h" class Player : public GameObject, public ITrackable { @@ -22,18 +23,22 @@ public: TrackableState getTrackableState() const override; - float speed = 30.0f; + float speed = DEFAULT_PLAYER_SPEED; int getPlayerId() const; + float getWorldRadius() const; + private: std::shared_ptr input; - float width = 50; + float radiusInWorld = DEFAULT_PLAYER_RADIUS; sf::Vector2f spawnPosition; int playerId; static inline int playerCreationCounter = 0; + + float getIsoRadius() const; }; diff --git a/src/texture_config.h b/src/texture_config.h index c16c821..872ba00 100644 --- a/src/texture_config.h +++ b/src/texture_config.h @@ -7,7 +7,7 @@ #include "sprites/configs/sheet_config.hpp" #include "sprites/configs/sprite_config.hpp" -#define PLAYER_SKIN "edge" +#define PLAYER_SKIN "ring" /** * All textures used in the game. @@ -16,7 +16,8 @@ std::map const all_textures = { {"numbers", "assets/numbers.png"}, {"64", "assets/64.png"}, - {"edge", "assets/edge.png"} + {"edge", "assets/edge.png"}, + {"ring", "assets/ring.png"} }; /** @@ -41,7 +42,8 @@ std::map const all_animations = { */ std::map const all_sprites = { {"64", SpriteConfig("64")}, - {"edge", SpriteConfig("edge")} + {"edge", SpriteConfig("edge")}, + {"ring", SpriteConfig("ring")} }; #endif //HOLESOME_TEXTURE_CONFIG_H