Add fly animations

This commit is contained in:
Bram Verhulst
2024-05-29 00:00:29 +02:00
parent 3c83e566dd
commit e1165fdcb4
31 changed files with 580 additions and 157 deletions

View File

@@ -18,7 +18,6 @@ void GuiMeter::Draw() const {
utils::DrawRect(Rectf { m_Position, m_DrawSize});
}
void GuiMeter::Update(float elapsedSec) {
m_Value += 1;
const int frame = static_cast<int>(utils::map(m_Value, 0.0f, m_MaxValue, 0, (float)m_Animation->GetFrameCount()));
m_Animation->SetFrame(frame);
}

View File

@@ -19,7 +19,6 @@ void GuiText::Update(float elapsedSec) {
void GuiText::ChangeText(const std::string& text) const {
m_Text->ChangeText(text);
}
GuiText::~GuiText() {
delete m_Text;

View File

@@ -1,6 +1,8 @@
#include "pch.h"
#include "FuelScreen.h"
#include "colors.h"
#include "GameManager.h"
#include "ScreenManager.h"
#include "utils.h"
FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): Screen(filePath, pos, size, manager)
@@ -38,14 +40,33 @@ FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size,
const Vector2f fillTankButtonPos = Vector2f { 450, 108 };
GuiButton* fillTankButton = new GuiButton { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddElement(fillTankButton);
Vector2f offset{ 50, 320};
m_MoneyText = new GuiText {fuelScreenCenter + offset, "$ 20", "fonts/Arial.ttf", 20, Colors::YELLOW };
}
FuelScreen::~FuelScreen() = default;
FuelScreen::~FuelScreen() {
delete m_MoneyText;
};
void FuelScreen::Draw() const {
int currentFuel = GameManager::GetInstance().GetFuel();
int maxFuel = GameManager::GetInstance().GetMaxFuel();
utils::SetColor(Colors::ORANGE);
Vector2f fuelBarPos = Vector2f { 275, 135 };
const int MAX_HEIGHT = 210;
Vector2f fuelBarSize = Vector2f { 40, utils::map(currentFuel, 0, maxFuel, 0, MAX_HEIGHT) };
utils::FillRect(Rectf{fuelBarPos, fuelBarSize});
Screen::Draw();
m_MoneyText->Draw();
}
void FuelScreen::Update(float elapsedSecs) {
Screen::Update(elapsedSecs);
m_MoneyText->ChangeText("$ " + std::to_string(GameManager::GetInstance().GetMoney()));
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include "../Screen.h"
#include "Gui/GuiText.h"
class FuelScreen : public Screen
{
@@ -10,5 +11,8 @@ public:
virtual void Draw() const override;
virtual void Update(float elapsedSecs) override;
private:
GuiText* m_MoneyText;
};

View File

@@ -2,6 +2,7 @@
#include "MainScreen.h"
#include "colors.h"
#include "GameManager.h"
#include "utils.h"
#include "Gui/GuiText.h"
MainScreen::MainScreen(TextureManager* manager) : Screen("", Vector2f{0, 0}, Vector2f{900.f, 500.f}, manager) {

View File

@@ -37,6 +37,9 @@ void ScreenManager::CloseScreen() {
}
}
bool ScreenManager::IsScreenOpen() {
return m_IsScreenOpen;
}
ScreenManager::~ScreenManager() {
delete m_FuelScreen;
delete m_SellScreen;

View File

@@ -12,8 +12,9 @@ public:
void OpenScreen(Screen* screen);
void CloseScreen();
Screen* GetCurrentScreen() const { return m_currentScreen; }
Screen* GetCurrentScreen() const { return m_currentScreen; }
bool IsScreenOpen();
static ScreenManager* m_pInstance;