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

@@ -2,14 +2,48 @@
#include "Building.h"
#include <iostream>
Building::Building(const std::string& filePath, const Vector2f& position, TextureManager* pTextureManager): m_Position(position) {
#include <utility>
#include "colors.h"
#include "utils.h"
Building::Building(const std::string& filePath, const Vector2f& position, const Rectf& boundingBox, TextureManager* pTextureManager): m_Position(position),
m_BoundingBox(boundingBox) {
m_Texture = pTextureManager->GetTexture(filePath);
m_Size = Vector2f(m_Texture->GetWidth(), m_Texture->GetHeight());
std::cout << "i like kids" << std::endl;
}
Building::~Building() = default;
void Building::Draw() const {
m_Texture->Draw(m_Position);
utils::SetColor(Colors::GREEN);
Rectf temp = m_BoundingBox;
temp.left += m_Position.x;
temp.bottom += m_Position.y;
utils::DrawRect(temp);
}
void Building::Update(float dt) {
void Building::Update(float dt, const Rectf& objectBoundingBox) {
if (IsObjectInHitbox(objectBoundingBox)) {
if (!m_IsPlayerInHitbox) { //TODO: what
m_IsPlayerInHitbox = true;
if (m_OnEnterHitbox != nullptr) {
m_OnEnterHitbox();
}
else {
std::cout << "No function set for onEnterHitbox" << std::endl;
}
}
}
else {
m_IsPlayerInHitbox = false;
}
}
void Building::SetOnEnterHitbox(std::function<void()> onEnterHitbox) {
m_OnEnterHitbox = std::move(onEnterHitbox);
}
bool Building::IsObjectInHitbox(const Rectf& objectBoundingBox) const {
Rectf temp = m_BoundingBox;
temp.left += m_Position.x;
temp.bottom += m_Position.y;
return utils::IsRectInRect(objectBoundingBox, temp);
}

View File

@@ -1,26 +1,34 @@
#pragma once
#include <functional>
#include "Texture.h"
#include "TextureManager.h"
class Building
{
public:
Building(const std::string& filePath, const Vector2f& position, TextureManager* pTextureManager);
Building(const Building& other) = default;
Building(Building&& other) = default;
Building& operator=(const Building& other) = default;
Building& operator=(Building&& other) = default;
Building(const std::string& filePath, const Vector2f& position, const Rectf& boundingBox, TextureManager* pTextureManager);
// Building(const Building& other) = default;
// Building(Building&& other) = default;
// Building& operator=(const Building& other) = default;
// Building& operator=(Building&& other) = default;
~Building();
void Draw() const;
void Update(float dt);
void Update(float dt, const Rectf& objectBoundingBox);
void SetOnEnterHitbox(std::function<void(void)> onEnterHitbox);
private:
bool IsObjectInHitbox(const Rectf& objectBoundingBox) const;
Texture* m_Texture;
Vector2f m_Position;
Vector2f m_Size;
Rectf m_boundingBox;
Rectf m_BoundingBox;
std::function<void(void)> m_OnEnterHitbox;
bool m_IsPlayerInHitbox{ false };
bool m_DidPlayerEnterHitbox{ false };
};

View File

@@ -8,6 +8,7 @@
#include "Collision.h"
#include "colors.h"
#include "GameManager.h"
#include "../../GridSystem/GroundTileTypeManager.h"
#include "utils.h"
#include "GridSystem/WorldTile.h"
@@ -35,44 +36,56 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
m_GridManager.GetTileAtIndex(x, 0)->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
m_GridManager.GetTileAtIndex(x, 1)->SetTileType(GroundTileTypeManager::GetInstance()->GRASS);
}
m_Buildings.emplace_back(Building { "buildings/fuelStation.png", Vector2f { -700, -52 }, TextureManager::GetInstance() });
Building* fuelBuilding = new Building { "buildings/fuelStation.png", Vector2f { -700, -52 }, Rectf{0 ,0, 50, 50}, TextureManager::GetInstance() };
fuelBuilding->SetOnEnterHitbox([]() {
ScreenManager::GetInstance()->OpenScreen(ScreenManager::m_FuelScreen);
});
m_Buildings.push_back(fuelBuilding);
m_GridManager.GetTileAtWorldPos(Vector2f { -750, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f { -700, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f { -700, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f { -650, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f { -600, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_Buildings.emplace_back(Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, TextureManager::GetInstance() });
m_Buildings.emplace_back(new Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, Rectf{0 ,0, 100, 100}, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {-400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {-350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-150, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_Buildings.emplace_back(Building { "buildings/junkStation.png", Vector2f { 250, -52 }, TextureManager::GetInstance() });
m_Buildings.emplace_back(new Building { "buildings/junkStation.png", Vector2f { 250, -52 }, Rectf{0 ,0, 100, 100}, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {450, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_Buildings.emplace_back(Building { "buildings/repairStation.png", Vector2f { 700, -52 }, TextureManager::GetInstance() });
m_Buildings.emplace_back(new Building { "buildings/repairStation.png", Vector2f { 700, -52 }, Rectf{0 ,0, 100, 100}, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {650, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {700, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {750, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {800, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
// Texture* test = new Texture("gui/main/fuel_guage.png");
m_topCover = TextureManager::GetInstance()->GetTexture("topBackground.png");
m_MainScreen = new MainScreen(TextureManager::GetInstance());
GameManager::GetInstance().SetMainScreen(m_MainScreen);
m_Sun = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.5f, TextureManager::GetInstance()->GetTexture("sun.png"));
m_Moon = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.5f, TextureManager::GetInstance()->GetTexture("moon.png"), M_PI);
GameManager::GetInstance().SetFuel(100);
GameManager::GetInstance().SetHullIntegrity(100);
}
WorldLevel::~WorldLevel() {
delete m_MainScreen;
delete m_Sun;
delete m_Moon;
}
void WorldLevel::Update(float elapsedSec) {
m_Fps = 1 / elapsedSec;
@@ -102,8 +115,9 @@ void WorldLevel::Update(float elapsedSec) {
}
}
for (Building building : m_Buildings) {
building.Update(elapsedSec);
for (Building* building : m_Buildings) {
building->Update(elapsedSec, m_Player.GetCollisionRect().getRectf());
// building.IsPlayerInHitbox(Rectf{m_Player.GetCollisionRect().pos, m_Player.GetCollisionRect().size});
}
@@ -112,8 +126,9 @@ void WorldLevel::Update(float elapsedSec) {
m_pSelectedTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
}
}
m_Player.Update(elapsedSec, *this);
if(!m_ScreenManager->IsScreenOpen()) {
m_Player.Update(elapsedSec, *this);
}
//Move the camera when the player gets to the edge
if(m_FollowPlayer) {
@@ -139,8 +154,14 @@ void WorldLevel::Update(float elapsedSec) {
screen->Update(elapsedSec);
}
m_MainScreen->Update(elapsedSec);
GameManager::GetInstance().Update(elapsedSec);
m_MainScreen->SetDepth(std::to_string((int)-m_Player.GetPosition().y - 50) + " ft.");
m_MainScreen->SetScore("Score: " + std::to_string(GameManager::GetInstance().GetScore()));
// m_MainScreen->SetFuelMeterValue(GameManager::GetInstance().GetFuel());
// m_MainScreen->SetHullMeterValue(GameManager::GetInstance().GetHullIntegrity());
m_MainScreen->Update(elapsedSec);
//Vector2f playerPos = m_player.GetPosition();
//Vector2f newCameraPos = playerPos;
@@ -152,6 +173,10 @@ void WorldLevel::Update(float elapsedSec) {
void WorldLevel::Draw() const {
m_pCamera->BeginRendering();
m_Sun->Draw();
m_Moon->Draw();
// m_topCover->Draw(Vector2f{-850,-70} );
m_topCover->Draw(Rectf{-850, -70, 850, -70 + 32}, Rectf{0, 0, WORLD_WIDTH * 50, 32});
@@ -175,8 +200,8 @@ void WorldLevel::Draw() const {
m_pSelectedTile->Draw();
}
for(Building building : m_Buildings) {
building.Draw();
for(Building* building : m_Buildings) {
building->Draw();
}
m_Player.Draw();
@@ -184,9 +209,6 @@ void WorldLevel::Draw() const {
utils::SetColor(Colors::GREEN);
utils::DrawArrow(Vector2f{0, 0}, m_MousePos);
m_Sun->Draw();
m_Moon->Draw();
m_pCamera->EndRendering();
utils::FillRect(utils::GetMousePos(), 10, 10);
@@ -209,7 +231,7 @@ void WorldLevel::ProcessImGui() {
ImGui::Begin("Selected Tile");
std::string tileType = "None";
if (m_pSelectedTile != nullptr) {
switch (m_pSelectedTile->GetTileType()->getType()) {
switch (m_pSelectedTile->GetTileType()->GetType()) {
case GroundTileTypes::Air:
tileType = "Air";
break;
@@ -243,6 +265,9 @@ void WorldLevel::ProcessImGui() {
if (ImGui::MenuItem("Player Info")) {
m_ShowPlayerInfo = !m_ShowPlayerInfo;
}
if(ImGui::MenuItem("Game Manager Info")) {
m_ShowGameManagerInfo = !m_ShowGameManagerInfo;
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Screens")) {
@@ -302,6 +327,26 @@ void WorldLevel::ProcessImGui() {
ImGui::End();
m_Player.ProcessImGui();
}
if(m_ShowGameManagerInfo) {
ImGui::Begin("Game Manager", &m_ShowGameManagerInfo, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("Fuel: %f", GameManager::GetInstance().GetFuel());
ImGui::Text("Hull Integrity: %d", GameManager::GetInstance().GetHullIntegrity());
ImGui::Text("Score: %d", GameManager::GetInstance().GetScore());
ImGui::Text("Money: %d", GameManager::GetInstance().GetMoney());
ImGui::Separator();
if(ImGui::Button("Add 1$")) {
GameManager::GetInstance().IncreaseMoney(1);
}
if(ImGui::Button("Add 10$")) {
GameManager::GetInstance().IncreaseMoney(10);
}
ImGui::SameLine();
if(ImGui::Button("Add 100$")) {
GameManager::GetInstance().IncreaseMoney(100);
}
ImGui::End();
}
}
WorldGridManager& WorldLevel::GetGridManager() {
return m_GridManager;

View File

@@ -7,6 +7,7 @@
#include "Gui/Screens/ScreenManager.h"
#include "Camera.h"
#include "OrbitingObject.h"
#include "SoundEffect.h"
#include "Text.h"
#include "Gui/GuiMeter.h"
#include "Gui/Screens/MainScreen.h"
@@ -45,7 +46,7 @@ private:
WorldTile* m_pSelectedTile { nullptr };
std::vector<Building> m_Buildings{};
std::vector<Building*> m_Buildings{};
MainScreen* m_MainScreen{};
@@ -55,10 +56,12 @@ private:
Texture* m_topCover{ nullptr };
// ImGui Vars
bool m_ShowTextureManagerWindow { false };
bool m_ShowCameraWindow { false };
bool m_ShowPlayerInfo { true };
bool m_ShowGameManagerInfo{ true };
bool m_FollowPlayer { true };
};