Add display names for powerups.

sigonasr2 3 months ago
parent 051d2f32b0
commit e37456f757
  1. BIN
      assets/border.png
  2. BIN
      assets/border.xcf
  3. 12
      src/HamsterGame.cpp
  4. 14
      src/Powerup.cpp
  5. 2
      src/Powerup.h

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

@ -194,13 +194,25 @@ void HamsterGame::DrawGame(){
const float drawY{y*32.f+12.f+96.f}; const float drawY{y*32.f+12.f+96.f};
const Powerup::PowerupType powerupType{Powerup::PowerupType(powerupInd)}; const Powerup::PowerupType powerupType{Powerup::PowerupType(powerupInd)};
const geom2d::rect<float>powerupSubimageRect{Powerup::GetPowerupSubimageRect(powerupType)}; const geom2d::rect<float>powerupSubimageRect{Powerup::GetPowerupSubimageRect(powerupType)};
const Powerup tempPowerup{{},powerupType};
const std::string powerupName{tempPowerup.GetName()};
const vf2d powerupTextSize{GetTextSize(powerupName)};
if(Hamster::GetPlayer().HasPowerup(powerupType)){ if(Hamster::GetPlayer().HasPowerup(powerupType)){
SetDecalMode(DecalMode::ADDITIVE); SetDecalMode(DecalMode::ADDITIVE);
DrawPartialRotatedDecal(vf2d{drawX,drawY}+16,GetGFX("gametiles.png").Decal(),0.f,{16.f,16.f},powerupSubimageRect.pos,powerupSubimageRect.size,{1.1f,1.1f}); DrawPartialRotatedDecal(vf2d{drawX,drawY}+16,GetGFX("gametiles.png").Decal(),0.f,{16.f,16.f},powerupSubimageRect.pos,powerupSubimageRect.size,{1.1f,1.1f});
SetDecalMode(DecalMode::NORMAL); SetDecalMode(DecalMode::NORMAL);
DrawPartialDecal({drawX,drawY},GetGFX("gametiles.png").Decal(),powerupSubimageRect.pos,powerupSubimageRect.size); DrawPartialDecal({drawX,drawY},GetGFX("gametiles.png").Decal(),powerupSubimageRect.pos,powerupSubimageRect.size);
SetDecalMode(DecalMode::ADDITIVE);
for(int y:std::ranges::iota_view(-1,2)){
for(int x:std::ranges::iota_view(-1,2)){
DrawRotatedStringDecal(vf2d{drawX+16.f,drawY+32.f}+vi2d{x,y},powerupName,0.f,powerupTextSize/2,CYAN,{0.5f,1.f});
}
}
SetDecalMode(DecalMode::NORMAL);
DrawRotatedStringDecal({drawX+16.f,drawY+32.f},powerupName,0.f,powerupTextSize/2,VERY_DARK_BLUE,{0.5f,1.f});
}else{ }else{
DrawPartialDecal({drawX,drawY},GetGFX("gametiles.png").Decal(),powerupSubimageRect.pos,powerupSubimageRect.size,{1.f,1.f},VERY_DARK_GREY); DrawPartialDecal({drawX,drawY},GetGFX("gametiles.png").Decal(),powerupSubimageRect.pos,powerupSubimageRect.size,{1.f,1.f},VERY_DARK_GREY);
DrawRotatedStringDecal({drawX+16.f,drawY+32.f},powerupName,0.f,powerupTextSize/2,DARK_GREY,{0.5f,1.f});
} }
} }
} }

@ -43,6 +43,16 @@ All rights reserved.
std::vector<Powerup>Powerup::powerupList; std::vector<Powerup>Powerup::powerupList;
std::unordered_map<int,std::pair<Powerup::PowerupType,Powerup::TileType>>Powerup::powerupIds; std::unordered_map<int,std::pair<Powerup::PowerupType,Powerup::TileType>>Powerup::powerupIds;
const vf2d Powerup::POWERUP_TILESET_STARTING_POS{144.f,816.f}; const vf2d Powerup::POWERUP_TILESET_STARTING_POS{144.f,816.f};
std::unordered_map<Powerup::PowerupType,std::string>Powerup::powerupNames{
{WHEEL,"WHEEL"},
{GRASS,"GRASS"},
{SAND,"SAND"},
{SWAMP,"SWAMP"},
{LAVA,"LAVA"},
{FOREST,"FOREST"},
{ICE,"ICE"},
{JET,"JET"},
};
Powerup::Powerup(const vf2d pos,const PowerupType type) Powerup::Powerup(const vf2d pos,const PowerupType type)
:pos(pos),type(type){} :pos(pos),type(type){}
@ -116,4 +126,8 @@ const geom2d::rect<float>Powerup::GetPowerupSubimageRect(const PowerupType power
void Powerup::OnPowerupObtain(Hamster&pickupHamster){ void Powerup::OnPowerupObtain(Hamster&pickupHamster){
spinSpd=0.3f; spinSpd=0.3f;
if(type==JET)pickupHamster.SetJetFuel(1.f); if(type==JET)pickupHamster.SetJetFuel(1.f);
}
const std::string&Powerup::GetName()const{
return powerupNames.at(type);
} }

@ -63,6 +63,7 @@ private:
static std::vector<Powerup>powerupList; static std::vector<Powerup>powerupList;
static std::unordered_map<int,std::pair<PowerupType,TileType>>powerupIds; static std::unordered_map<int,std::pair<PowerupType,TileType>>powerupIds;
static const vf2d POWERUP_TILESET_STARTING_POS; static const vf2d POWERUP_TILESET_STARTING_POS;
static std::unordered_map<PowerupType,std::string>powerupNames;
vf2d pos; vf2d pos;
float z{5.f}; float z{5.f};
float spinSpd{}; float spinSpd{};
@ -72,6 +73,7 @@ public:
static void Initialize(const std::vector<Powerup>&powerupList); static void Initialize(const std::vector<Powerup>&powerupList);
const vf2d&GetPos()const; const vf2d&GetPos()const;
const PowerupType&GetType()const; const PowerupType&GetType()const;
const std::string&GetName()const;
static std::vector<Powerup>&GetPowerups(); static std::vector<Powerup>&GetPowerups();
static void AddOrUpdatePowerupIdList(const int powerupId,const PowerupType powerupType); static void AddOrUpdatePowerupIdList(const int powerupId,const PowerupType powerupType);
static void AddOrUpdatePowerupIdList(const int powerupId,const TileType powerupTileType); static void AddOrUpdatePowerupIdList(const int powerupId,const TileType powerupTileType);

Loading…
Cancel
Save