mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2026-02-04 08:09:19 +01:00
Remove Point2f, replace with Vector2f
This commit is contained in:
@@ -19,11 +19,11 @@ void Animation::Update(float elapsedSec) {
|
||||
}
|
||||
}
|
||||
}
|
||||
void Animation::Draw(const Point2f& pos) const {
|
||||
void Animation::Draw(const Vector2f& pos) const {
|
||||
Draw(pos, Rectf{ pos.x, pos.y, m_SrcRect.width, m_SrcRect.height });
|
||||
}
|
||||
|
||||
void Animation::Draw(const Point2f& pos, const Rectf& dst) const {
|
||||
void Animation::Draw(const Vector2f& pos, const Rectf& dst) const {
|
||||
Rectf src = m_SrcRect;
|
||||
src.left += m_CurrentFrame * src.width;
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ public:
|
||||
~Animation();
|
||||
|
||||
void Update(float elapsedSec);
|
||||
void Draw(const Point2f& pos) const;
|
||||
void Draw(const Point2f& pos, const Rectf& dst) const;
|
||||
void Draw(const Vector2f& pos) const;
|
||||
void Draw(const Vector2f& pos, const Rectf& dst) const;
|
||||
|
||||
void SetPlaying(bool isPlaying) {
|
||||
m_isPlaying = isPlaying;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
Camera::Camera() : m_Position { 0, 0 }, m_Scale { 1.0f } {
|
||||
}
|
||||
|
||||
Camera::Camera(const Point2f& position, float scale) : m_Position { position }, m_Scale { scale } {
|
||||
Camera::Camera(const Vector2f& position, float scale) : m_Position { position }, m_Scale { scale } {
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,14 @@ void Camera::EndRendering() const {
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
Point2f Camera::TransformMouse(const Point2f& mousePos) const {
|
||||
Point2f worldPos = mousePos;
|
||||
Vector2f Camera::TransformMouse(const Vector2f& mousePos) const {
|
||||
Vector2f worldPos = mousePos;
|
||||
worldPos.x = ( worldPos.x + m_Position.x ) / m_Scale;
|
||||
worldPos.y = Viewport.height - worldPos.y + m_Position.y / m_Scale;
|
||||
return worldPos;
|
||||
}
|
||||
Point2f Camera::TransformWorld(const Point2f& worldPos) const {
|
||||
Point2f screenPos = worldPos;
|
||||
Vector2f Camera::TransformWorld(const Vector2f& worldPos) const {
|
||||
Vector2f screenPos = worldPos;
|
||||
screenPos.x = screenPos.x * m_Scale - m_Position.x;
|
||||
screenPos.y = Viewport.height - screenPos.y * m_Scale - m_Position.y;
|
||||
return screenPos;
|
||||
|
||||
@@ -6,20 +6,20 @@ class Camera
|
||||
{
|
||||
public:
|
||||
Camera();
|
||||
Camera(const Point2f& position, float scale = 1);
|
||||
Camera(const Vector2f& position, float scale = 1);
|
||||
~Camera() = default;
|
||||
|
||||
Camera(const Camera& other) = default;
|
||||
Camera& operator=(const Camera& other) = default;
|
||||
|
||||
void SetPosition(const Point2f& position) {
|
||||
void SetPosition(const Vector2f& position) {
|
||||
m_Position = position;
|
||||
}
|
||||
void SetScale(const float scale) {
|
||||
m_Scale = scale;
|
||||
}
|
||||
|
||||
const Point2f& GetPosition() const {
|
||||
const Vector2f& GetPosition() const {
|
||||
return m_Position;
|
||||
}
|
||||
float GetScale() const {
|
||||
@@ -33,13 +33,13 @@ public:
|
||||
m_FollowingPlayer = player;
|
||||
}
|
||||
|
||||
Point2f TransformMouse(const Point2f& mousePos) const;
|
||||
Point2f TransformWorld(const Point2f& worldPos) const;
|
||||
Vector2f TransformMouse(const Vector2f& mousePos) const;
|
||||
Vector2f TransformWorld(const Vector2f& worldPos) const;
|
||||
Rectf Viewport = Rectf { 0, 0, 846.f, 500.f };
|
||||
//TODO: Remove this and make it some static
|
||||
|
||||
private:
|
||||
Point2f m_Position;
|
||||
Vector2f m_Position;
|
||||
float m_Scale;
|
||||
Player* m_FollowingPlayer { nullptr };
|
||||
//TODO: Ask if the rule applies to the fact that the player is not managed by the camera
|
||||
|
||||
@@ -22,7 +22,7 @@ Game::~Game() {
|
||||
}
|
||||
|
||||
void Game::Initialize() {
|
||||
m_Camera.SetPosition(Point2f { -GetViewPort().width / 2, -GetViewPort().height / 2 });
|
||||
m_Camera.SetPosition(Vector2f { -GetViewPort().width / 2, -GetViewPort().height / 2 });
|
||||
}
|
||||
|
||||
void Game::Cleanup() {
|
||||
@@ -32,8 +32,8 @@ void Game::Update(float elapsedSec) {
|
||||
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
if (m_IsRightMouseDown) {
|
||||
const Point2f newCameraPos = Point2f { m_MousePos.x + m_MouseOffset.x, m_MousePos.y + m_MouseOffset.y };
|
||||
m_Camera.SetPosition(Point2f { -newCameraPos.x, -newCameraPos.y });
|
||||
const Vector2f newCameraPos = Vector2f { m_MousePos.x + m_MouseOffset.x, m_MousePos.y + m_MouseOffset.y };
|
||||
m_Camera.SetPosition(Vector2f { -newCameraPos.x, -newCameraPos.y });
|
||||
}
|
||||
else {
|
||||
m_MouseOffset = m_Camera.GetPosition();
|
||||
@@ -56,15 +56,15 @@ void Game::ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
|
||||
}
|
||||
|
||||
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
|
||||
m_MousePos = Point2f { float(e.x), float(e.y) };
|
||||
m_pCurrentLevel->MouseMove(Point2f { float(e.x), float(e.y) });
|
||||
m_MousePos = Vector2f { float(e.x), float(e.y) };
|
||||
m_pCurrentLevel->MouseMove(Vector2f { float(e.x), float(e.y) });
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
|
||||
m_IsRightMouseDown = e.button == SDL_BUTTON_RIGHT;
|
||||
m_MouseOffset = Point2f { -m_Camera.GetPosition().x - m_MousePos.x, -m_Camera.GetPosition().y - m_MousePos.y };
|
||||
m_MouseOffset = Vector2f { -m_Camera.GetPosition().x - m_MousePos.x, -m_Camera.GetPosition().y - m_MousePos.y };
|
||||
}
|
||||
|
||||
void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
|
||||
|
||||
@@ -42,8 +42,8 @@ private:
|
||||
|
||||
Level* m_pCurrentLevel;
|
||||
|
||||
Point2f m_MousePos {};
|
||||
Point2f m_MouseOffset {};
|
||||
Vector2f m_MousePos {};
|
||||
Vector2f m_MouseOffset {};
|
||||
bool m_IsRightMouseDown {};
|
||||
|
||||
};
|
||||
|
||||
@@ -18,8 +18,8 @@ WorldGridManager::~WorldGridManager() {
|
||||
}
|
||||
surroundingTiles WorldGridManager::GetSurroundingTiles(const WorldTile* world_tile) {
|
||||
surroundingTiles tiles;
|
||||
Point2f pos = world_tile->GetPosition();
|
||||
Point2f gridCoords = this->GetIndexFromPosition(pos);
|
||||
Vector2f pos = world_tile->GetPosition();
|
||||
Vector2f gridCoords = this->GetIndexFromPosition(pos);
|
||||
int x = gridCoords.x;
|
||||
//TODO: Stupid fix, fix this
|
||||
int y = gridCoords.y - 1;
|
||||
@@ -38,10 +38,10 @@ surroundingTiles WorldGridManager::GetSurroundingTiles(const WorldTile* world_ti
|
||||
return tiles;
|
||||
|
||||
}
|
||||
Point2f WorldGridManager::GetIndexFromPosition(Point2f position) {
|
||||
Vector2f WorldGridManager::GetIndexFromPosition(Vector2f position) {
|
||||
int x = int(position.x / TILE_WIDTH + WORLD_WIDTH / 2);
|
||||
int y = int(-position.y / TILE_HEIGHT);
|
||||
return Point2f{ float(x), float(y) };
|
||||
return Vector2f{ float(x), float(y) };
|
||||
}
|
||||
WorldTile * WorldGridManager::GetTileAtIndex(const int x, const int y) const {
|
||||
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
||||
@@ -50,7 +50,7 @@ WorldTile * WorldGridManager::GetTileAtIndex(const int x, const int y) const {
|
||||
}
|
||||
return m_worldTiles[x][y];
|
||||
}
|
||||
WorldTile * WorldGridManager::GetTileAtWorldPos(const Point2f& pos) const {
|
||||
WorldTile * WorldGridManager::GetTileAtWorldPos(const Vector2f& pos) const {
|
||||
int x = int(pos.x / TILE_WIDTH + WORLD_WIDTH / 2);
|
||||
int y = int(-pos.y / TILE_HEIGHT);
|
||||
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
||||
|
||||
@@ -48,12 +48,12 @@ public:
|
||||
WorldGridManager();
|
||||
~WorldGridManager();
|
||||
surroundingTiles GetSurroundingTiles(const WorldTile* world_tile);
|
||||
Point2f GetIndexFromPosition(Point2f position);
|
||||
Vector2f GetIndexFromPosition(Vector2f position);
|
||||
|
||||
WorldGridManager(const WorldGridManager& other) = default;
|
||||
|
||||
WorldTile * GetTileAtIndex(const int x, const int y) const;
|
||||
WorldTile * GetTileAtWorldPos(const Point2f& pos) const;
|
||||
WorldTile * GetTileAtWorldPos(const Vector2f& pos) const;
|
||||
|
||||
void SetTileAtIndex(const int x, const int y, WorldTile* tile);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "WorldGridManager.h"
|
||||
|
||||
|
||||
WorldTile::WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager) : m_Position { position }, m_GroundTileType { groundTileType }, m_pGridManager { pGridManager } {
|
||||
WorldTile::WorldTile(const Vector2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager) : m_Position { position }, m_GroundTileType { groundTileType }, m_pGridManager { pGridManager } {
|
||||
// const std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png";
|
||||
// m_pTexture = new Texture(dirtPath);
|
||||
m_pTexture = pTextureManager->GetTexture(groundTileType->getPath());
|
||||
@@ -140,12 +140,12 @@ void WorldTile::Draw() {
|
||||
// GroundTileTypes type = tile->GetTileType()->getType();
|
||||
// if(type == Tiles::AIR->getType()) {
|
||||
// utils::SetColor(Colors::BLACK);
|
||||
// utils::FillRect(Rectf{tile->GetPosition(), Point2f{50,50}});
|
||||
// utils::FillRect(Rectf{tile->GetPosition(), Vector2f{50,50}});
|
||||
// continue;
|
||||
// }
|
||||
// if(type != Tiles::AIR->getType()) {
|
||||
// utils::SetColor(Colors::YELLOW);
|
||||
// utils::FillRect(Rectf{tile->GetPosition(), Point2f{50,50}});
|
||||
// utils::FillRect(Rectf{tile->GetPosition(), Vector2f{50,50}});
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -176,7 +176,7 @@ void WorldTile::Draw() {
|
||||
// if(topLeftType != Tiles::AIR) {
|
||||
// m_pTopLeftTexture->Draw(m_Position);
|
||||
// utils::SetColor(Colors::YELLOW);
|
||||
// utils::FillRect(Rectf{topLeft->GetPosition(), Point2f{50,50}});
|
||||
// utils::FillRect(Rectf{topLeft->GetPosition(), Vector2f{50,50}});
|
||||
// }
|
||||
//
|
||||
// WorldTile* topRight = m_SurroundingTiles.GetTile(TileDirection::TopRight);
|
||||
@@ -187,9 +187,9 @@ void WorldTile::Draw() {
|
||||
//
|
||||
}
|
||||
void WorldTile::Update(Camera* camera) {
|
||||
Point2f CurrentIndex = m_pGridManager->GetIndexFromPosition(m_Position);
|
||||
Vector2f CurrentIndex = m_pGridManager->GetIndexFromPosition(m_Position);
|
||||
m_SurroundingTiles = m_pGridManager->GetSurroundingTiles(this);
|
||||
Point2f mousePos = camera->TransformMouse(Point2f{utils::GetMousePos().x, 500 - utils::GetMousePos().y});
|
||||
Vector2f mousePos = camera->TransformMouse(Vector2f{utils::GetMousePos().x, 500 - utils::GetMousePos().y});
|
||||
m_Hightlight = utils::IsPointInRect(mousePos, Rectf{GetCollisionRect().pos, GetCollisionRect().size});
|
||||
if(CurrentIndex.x == 1 && CurrentIndex.y == 1) {
|
||||
// std::cout << "Hey" << std::endl;
|
||||
|
||||
@@ -95,21 +95,21 @@ class WorldTile
|
||||
{
|
||||
public:
|
||||
WorldTile() = default;
|
||||
WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager);
|
||||
WorldTile(const Vector2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager);
|
||||
~WorldTile();
|
||||
|
||||
void Draw();
|
||||
void Update(Camera* camera); //TODO: no use
|
||||
|
||||
Point2f GetPosition() const {
|
||||
Vector2f GetPosition() const {
|
||||
return m_Position;
|
||||
}
|
||||
void SetPosition(const Point2f& position) {
|
||||
void SetPosition(const Vector2f& position) {
|
||||
m_Position = position;
|
||||
}
|
||||
|
||||
Point2f GetSize() const {
|
||||
return Point2f { 50, 50 };
|
||||
Vector2f GetSize() const {
|
||||
return Vector2f { 50, 50 };
|
||||
}
|
||||
|
||||
GroundTileType * GetTileType() const {
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
bool m_Hightlight { false };
|
||||
|
||||
private:
|
||||
Point2f m_Position;
|
||||
Vector2f m_Position;
|
||||
GroundTileType* m_GroundTileType;
|
||||
|
||||
Texture* m_pTexture;
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
|
||||
#include "colors.h"
|
||||
#include "utils.h"
|
||||
Button::Button(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||
Button::Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||
m_Texture = manager->GetTexture(filePath);
|
||||
if(size.x == 0 && size.y == 0) {
|
||||
m_Size = Point2f{float(m_Texture->GetWidth()), float(m_Texture->GetHeight())};
|
||||
m_Size = Vector2f{float(m_Texture->GetWidth()), float(m_Texture->GetHeight())};
|
||||
}
|
||||
std::cout << "Button created" << '\n';
|
||||
}
|
||||
@@ -23,7 +23,7 @@ void Button::Draw() const {
|
||||
}
|
||||
}
|
||||
void Button::Update(float elapsedSec) {
|
||||
Point2f mousePos = utils::GetMousePos();
|
||||
Vector2f mousePos = utils::GetMousePos();
|
||||
Rectf buttonRect = Rectf(m_Position, m_Size);
|
||||
|
||||
this->m_IsHovered = utils::IsPointInRect(mousePos, buttonRect);
|
||||
|
||||
@@ -9,7 +9,7 @@ class Button
|
||||
{
|
||||
public:
|
||||
Button() = default;
|
||||
Button(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager);
|
||||
Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
~Button();
|
||||
void Draw() const;
|
||||
void Update(float elapsedSec);
|
||||
@@ -20,8 +20,8 @@ public:
|
||||
|
||||
private:
|
||||
Texture* m_Texture{ nullptr };
|
||||
Point2f m_Position;
|
||||
Point2f m_Size;
|
||||
Vector2f m_Position;
|
||||
Vector2f m_Size;
|
||||
|
||||
bool m_IsHovered{ false };
|
||||
bool m_IsPressed{ false };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "Screen.h"
|
||||
|
||||
Screen::Screen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||
Screen::Screen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||
m_Background = manager->GetTexture(filePath);
|
||||
}
|
||||
Screen::~Screen() {
|
||||
|
||||
@@ -10,7 +10,7 @@ class Screen
|
||||
{
|
||||
public:
|
||||
Screen() = default;
|
||||
Screen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager);
|
||||
Screen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
|
||||
virtual ~Screen();
|
||||
|
||||
@@ -19,8 +19,8 @@ public:
|
||||
virtual void Update(float elapsedSecs);
|
||||
virtual void Draw() const;
|
||||
private:
|
||||
Point2f m_Position;
|
||||
Point2f m_Size;
|
||||
Vector2f m_Position;
|
||||
Vector2f m_Size;
|
||||
|
||||
Texture* m_Background{ nullptr };
|
||||
|
||||
|
||||
@@ -3,40 +3,40 @@
|
||||
|
||||
#include "ScreenManager.h"
|
||||
#include "utils.h"
|
||||
FuelScreen::FuelScreen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager): Screen(filePath, pos, size, manager)
|
||||
FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): Screen(filePath, pos, size, manager)
|
||||
{
|
||||
Point2f fuelScreenSize = Point2f { 492, 396 };
|
||||
Point2f fuelScreenCenter = Point2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
|
||||
const Vector2f fuelScreenSize = Vector2f { 492, 396 };
|
||||
// Vector2f fuelScreenCenter = Vector2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
|
||||
const Vector2f ScreenCenter = Vector2f { utils::GetViewport().x / 2, utils::GetViewport().y / 2 };
|
||||
|
||||
Point2f closeButtonOffset = Point2f { 460, 396 - 14 };
|
||||
Point2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
|
||||
const Vector2f fuelScreenCenter = ScreenCenter - fuelScreenSize / 2;
|
||||
|
||||
|
||||
const Vector2f closeButtonOffset = Vector2f { 460, 396 - 14 };
|
||||
Vector2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
|
||||
closeButtonPos.y -= 18;
|
||||
Button* closeFuelButton = new Button { "gui/close.png", closeButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
|
||||
Button* closeFuelButton = new Button { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
closeFuelButton->SetOnClick([this]() { ScreenManager::GetInstance()->CloseScreen(); });
|
||||
this->AddButton(closeFuelButton);
|
||||
|
||||
Point2f oneDollarButtonPos = Point2f { 451, 287 };
|
||||
oneDollarButtonPos += fuelScreenCenter;
|
||||
Button* fiveDollarButton = new Button { "gui/fuel/5dollars.png", oneDollarButtonPos , Point2f{0,0}, TextureManager::GetInstance() };
|
||||
const Vector2f oneDollarButtonPos = Vector2f { 451, 287 };
|
||||
Button* fiveDollarButton = new Button { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(fiveDollarButton);
|
||||
|
||||
Point2f tenDollarButtonPos = oneDollarButtonPos + Point2f { 113, -1 };
|
||||
tenDollarButtonPos += fuelScreenCenter;
|
||||
Button* tenDollarButton = new Button { "gui/fuel/10dollars.png", tenDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
|
||||
const Vector2f tenDollarButtonPos = oneDollarButtonPos + Vector2f { 113, -1 };
|
||||
Button* tenDollarButton = new Button { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(tenDollarButton);
|
||||
|
||||
Point2f twentyFiveDollarButtonPos = oneDollarButtonPos + Point2f { 0, -89 };
|
||||
twentyFiveDollarButtonPos += fuelScreenCenter;
|
||||
Button* twentyFiveDollarButton = new Button { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
|
||||
const Vector2f twentyFiveDollarButtonPos = oneDollarButtonPos + Vector2f { 0, -89 };
|
||||
Button* twentyFiveDollarButton = new Button { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(twentyFiveDollarButton);
|
||||
|
||||
Point2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Point2f { 114, 0 };
|
||||
Button* fiftyDollarButton = new Button { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
|
||||
const Vector2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Vector2f { 114, 0 };
|
||||
Button* fiftyDollarButton = new Button { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(fiftyDollarButton);
|
||||
|
||||
Point2f fillTankButtonPos = Point2f { 450, 108 };
|
||||
fillTankButtonPos += fuelScreenCenter;
|
||||
Button* fillTankButton = new Button { "gui/fuel/fillTank.png", fillTankButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
|
||||
const Vector2f fillTankButtonPos = Vector2f { 450, 108 };
|
||||
Button* fillTankButton = new Button { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(fillTankButton);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ class FuelScreen : public Screen
|
||||
{
|
||||
public:
|
||||
|
||||
FuelScreen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager);
|
||||
FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSecs) override;
|
||||
|
||||
@@ -34,12 +34,12 @@ void ScreenManager::CloseScreen() {
|
||||
|
||||
}
|
||||
void ScreenManager::InitializeScreens() {
|
||||
Point2f fuelScreenSize = Point2f { 492, 396 };
|
||||
Point2f fuelScreenCenter = Point2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
|
||||
Fuel = new FuelScreen { "gui/fuel/background.png", fuelScreenCenter, Point2f { 0, 0 }, TextureManager::GetInstance() };
|
||||
Vector2f fuelScreenSize = Vector2f { 492, 396 };
|
||||
Vector2f fuelScreenCenter = Vector2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
|
||||
Fuel = new FuelScreen { "gui/fuel/background.png", fuelScreenCenter, Vector2f { 0, 0 }, TextureManager::GetInstance() };
|
||||
|
||||
Point2f sellScreenSize = Point2f { 533, 398 };
|
||||
Point2f sellScreenCenter = Point2f { utils::GetViewport().x / 2 - sellScreenSize.x / 2, utils::GetViewport().y / 2 - sellScreenSize.y / 2 };
|
||||
Vector2f sellScreenSize = Vector2f { 533, 398 };
|
||||
Vector2f sellScreenCenter = Vector2f { utils::GetViewport().x / 2 - sellScreenSize.x / 2, utils::GetViewport().y / 2 - sellScreenSize.y / 2 };
|
||||
SellScreen = new Screen { "gui/sell/background.png", sellScreenCenter, sellScreenSize, TextureManager::GetInstance() };
|
||||
|
||||
//m_Button = Button { "gui/close.png", closeButtonPos, closeButtonSize, TextureManager::GetInstance() };
|
||||
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
|
||||
virtual void Update(float elapsedSec) = 0;
|
||||
virtual void Draw() const = 0;
|
||||
virtual void MouseMove(const Point2f& mousePos) = 0;
|
||||
virtual void MouseMove(const Vector2f& mousePos) = 0;
|
||||
virtual void ProcessImGui() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -16,12 +16,12 @@ MainMenuLevel::~MainMenuLevel() {
|
||||
void MainMenuLevel::Update(float elapsedSec) {
|
||||
}
|
||||
void MainMenuLevel::Draw() const {
|
||||
m_TextMotherload->Draw(Point2f(200, 100));
|
||||
m_TextNewGame->Draw(Point2f(200, 200));
|
||||
m_TextExit->Draw(Point2f(200, 300));
|
||||
m_TextMotherload->Draw(Vector2f(200, 100));
|
||||
m_TextNewGame->Draw(Vector2f(200, 200));
|
||||
m_TextExit->Draw(Vector2f(200, 300));
|
||||
|
||||
}
|
||||
void MainMenuLevel::MouseMove(const Point2f& mousePos) {
|
||||
void MainMenuLevel::MouseMove(const Vector2f& mousePos) {
|
||||
}
|
||||
void MainMenuLevel::ProcessImGui() {
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
|
||||
void Update(float elapsedSec) override;
|
||||
void Draw() const override;
|
||||
void MouseMove(const Point2f& mousePos) override;
|
||||
void MouseMove(const Vector2f& mousePos) override;
|
||||
void ProcessImGui() override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
class GroundTileType;
|
||||
WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
m_gridManager(WorldGridManager()),
|
||||
m_player(Player { Point2f { 0, 100 }, TextureManager::GetInstance() }),
|
||||
m_player(Player { Vector2f { 0, 100 }, TextureManager::GetInstance() }),
|
||||
m_mousePos { 0, 0 },
|
||||
m_viewport(viewport),
|
||||
m_screenManager(ScreenManager::GetInstance()) {
|
||||
@@ -24,7 +24,7 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
const int actualX = x - WORLD_WIDTH / 2;
|
||||
Point2f pos = Point2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
|
||||
Vector2f pos = Vector2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
|
||||
GroundTileType* type = Tiles::AIR;
|
||||
switch (utils::randRange(0, 2)) {
|
||||
case 0:
|
||||
@@ -54,7 +54,7 @@ WorldLevel::~WorldLevel() {
|
||||
void WorldLevel::Update(float elapsedSec) {
|
||||
int mouseX, mouseY;
|
||||
SDL_GetMouseState(&mouseX, &mouseY);
|
||||
m_mousePos = Point2f { float(mouseX), float(mouseY) };
|
||||
m_mousePos = Vector2f { float(mouseX), float(mouseY) };
|
||||
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
|
||||
|
||||
|
||||
@@ -101,12 +101,12 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
screen->Update(elapsedSec);
|
||||
}
|
||||
|
||||
//Point2f playerPos = m_player.GetPosition();
|
||||
//Point2f newCameraPos = playerPos;
|
||||
//Vector2f playerPos = m_player.GetPosition();
|
||||
//Vector2f newCameraPos = playerPos;
|
||||
//m_pCamera->SetPosition(newCameraPos);
|
||||
|
||||
//place the player in the center of the camera
|
||||
//m_pCamera->SetPosition(Point2f{playerPos.x - m_viewport.width / 2, playerPos.y - m_viewport.height / 2});
|
||||
//m_pCamera->SetPosition(Vector2f{playerPos.x - m_viewport.width / 2, playerPos.y - m_viewport.height / 2});
|
||||
|
||||
}
|
||||
void WorldLevel::Draw() const {
|
||||
@@ -141,7 +141,7 @@ void WorldLevel::Draw() const {
|
||||
screen->Draw();
|
||||
}
|
||||
}
|
||||
void WorldLevel::MouseMove(const Point2f& mousePos) {
|
||||
void WorldLevel::MouseMove(const Vector2f& mousePos) {
|
||||
m_mousePos = mousePos;
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ void WorldLevel::ProcessImGui() {
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
const Point2f screenPos = utils::GetMousePos();
|
||||
const Vector2f screenPos = utils::GetMousePos();
|
||||
const std::string mousePos = "Mouse Pos: (" + std::to_string(screenPos.x) + ", " + std::to_string(screenPos.y) + ")";
|
||||
if(ImGui::BeginMenu(mousePos.c_str())) {
|
||||
|
||||
@@ -198,7 +198,7 @@ void WorldLevel::ProcessImGui() {
|
||||
ImGui::Text("Camera Position: (%f, %f)", m_pCamera->GetPosition().x, m_pCamera->GetPosition().y);
|
||||
ImGui::Text("Is Right Mouse Down: %s", utils::isMouseDown(0) ? "true" : "false");
|
||||
if (ImGui::Button("Reset Camera")) {
|
||||
m_pCamera->SetPosition(Point2f { -m_viewport.width / 2, -m_viewport.height / 2 });
|
||||
m_pCamera->SetPosition(Vector2f { -m_viewport.width / 2, -m_viewport.height / 2 });
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
void Update(float elapsedSec) override;
|
||||
void Draw() const override;
|
||||
|
||||
void MouseMove(const Point2f& mousePos) override;
|
||||
void MouseMove(const Vector2f& mousePos) override;
|
||||
void ProcessImGui() override;
|
||||
|
||||
WorldGridManager& GetGridManager() {
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
private:
|
||||
WorldGridManager m_gridManager {};
|
||||
Player m_player;
|
||||
Point2f m_mousePos {};
|
||||
Vector2f m_mousePos {};
|
||||
|
||||
Rectf m_viewport;
|
||||
|
||||
@@ -38,6 +38,8 @@ private:
|
||||
|
||||
WorldTile* m_pSelectedTile { nullptr };
|
||||
|
||||
float testLerp{ 0.0f };
|
||||
|
||||
// ImGui Vars
|
||||
bool m_ShowTextureManagerWindow { false };
|
||||
bool m_ShowCameraWindow { false };
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "Animations/Animation.h"
|
||||
#include "GridSystem/WorldTile.h"
|
||||
|
||||
Player::Player(const Point2f& Position, TextureManager* manager) : m_Position(Position), m_Size(Point2f { 40, 40 }), m_Vel(Point2f { 0, 0 }), m_Acc(Point2f { 0, 0 }) {
|
||||
Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(Position), m_Size(Vector2f { 40, 40 }), m_Vel(Vector2f { 0, 0 }), m_Acc(Vector2f { 0, 0 }) {
|
||||
m_ContactMap[Collision::CollisionDirection::Top] = nullptr;
|
||||
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
|
||||
m_ContactMap[Collision::CollisionDirection::Left] = nullptr;
|
||||
@@ -30,12 +30,12 @@ void Player::Draw() const {
|
||||
utils::SetColor(Colors::PINK);
|
||||
utils::DrawRect(Rectf { m_Position.x, m_Position.y, m_Size.x, m_Size.y });
|
||||
}
|
||||
Point2f center = m_Position + m_Size / 2;
|
||||
Vector2f center = m_Position + m_Size / 2;
|
||||
|
||||
const int frameWidth = 70; //TODO: fix this
|
||||
int halfFrameWidth = frameWidth / 2;
|
||||
|
||||
Point2f drawPos = Point2f { center.x - halfFrameWidth, center.y - halfFrameWidth + 9 };
|
||||
Vector2f drawPos = Vector2f { center.x - halfFrameWidth, center.y - halfFrameWidth + 9 };
|
||||
|
||||
m_walkAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y, frameWidth, frameWidth });
|
||||
}
|
||||
@@ -72,7 +72,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
|
||||
//check for keys
|
||||
if(m_State != PlayerState::Digging) {
|
||||
m_Vel = Point2f { 0, -100 };
|
||||
m_Vel = Vector2f { 0, -100 };
|
||||
if (utils::isKeyDown(SDL_SCANCODE_W)) {
|
||||
m_Vel.y = 100;
|
||||
m_Grounded = false;
|
||||
@@ -83,14 +83,11 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
if (m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr) {
|
||||
//Do the digging
|
||||
m_State = PlayerState::Digging;
|
||||
m_DigProgress = 0;
|
||||
m_DigTile = m_ContactMap[Collision::CollisionDirection::Bottom];
|
||||
//Set the digging location in the center of the destination tile;
|
||||
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Bottom];
|
||||
m_DigDestination = tile->GetPosition() + tile->GetSize() / 2;
|
||||
m_ContactMap[Collision::CollisionDirection::Bottom]->SetTileType(Tiles::AIR);
|
||||
//center of tile
|
||||
Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
|
||||
m_Position = Point2f { tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5 };
|
||||
|
||||
const WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Bottom];
|
||||
m_DigDestination = tile->GetPosition() + Vector2f{0, 0};
|
||||
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -108,8 +105,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
m_ContactMap[Collision::CollisionDirection::Right]->SetTileType(Tiles::AIR);
|
||||
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Right];
|
||||
//center of tile
|
||||
const Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
|
||||
m_Position = Point2f { tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5 };
|
||||
const Vector2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
|
||||
m_Position = Vector2f { tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5 };
|
||||
|
||||
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
|
||||
m_DidJustDigRight = true;
|
||||
@@ -133,7 +130,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
|
||||
|
||||
float t = 0, min_t = INFINITY;
|
||||
Point2f intersectionPoint, normal;
|
||||
Vector2f intersectionPoint, normal;
|
||||
|
||||
std::vector<std::pair<int, float>> contactTimes {};
|
||||
|
||||
@@ -161,8 +158,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
int y = contact_time.first / WORLD_WIDTH;
|
||||
WorldTile* world_tile = gridManager.GetTileAtIndex(x, y);
|
||||
|
||||
const Point2f WorldTilePos = world_tile->GetCollisionRect().getCollisionRect().pos;
|
||||
const Point2f WorldTileSize = world_tile->GetCollisionRect().getCollisionRect().size;
|
||||
const Vector2f WorldTilePos = world_tile->GetCollisionRect().getCollisionRect().pos;
|
||||
const Vector2f WorldTileSize = world_tile->GetCollisionRect().getCollisionRect().size;
|
||||
|
||||
if (WorldTilePos.y + WorldTileSize.y > m_Position.y) {
|
||||
if (WorldTilePos.x + WorldTileSize.x > m_Position.x) {
|
||||
@@ -211,8 +208,25 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
case PlayerState::Walking:
|
||||
m_walkAnimation->SetPlaying(true);
|
||||
break;
|
||||
case PlayerState::Digging:
|
||||
case PlayerState::Digging: {
|
||||
m_walkAnimation->SetPlaying(false);
|
||||
//Diganimation
|
||||
m_DigProgress += elapsedTime;
|
||||
//lerp to the destination
|
||||
float progress = utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 1.0f);
|
||||
std::cout << progress << '\n';
|
||||
m_Position = utils::lerp(m_Position, m_DigDestination, progress);
|
||||
if (progress >= 0.5f && !m_HasDeletedTile) {
|
||||
m_DigTile->SetTileType(Tiles::AIR);
|
||||
m_DigTile = nullptr;
|
||||
m_HasDeletedTile = true;
|
||||
}
|
||||
if (progress >= 1.0f) {
|
||||
m_State = PlayerState::Idle;
|
||||
m_HasDeletedTile = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
@@ -30,22 +30,22 @@ enum class DigDirection
|
||||
class Player
|
||||
{
|
||||
public:
|
||||
Player(const Point2f& Position, TextureManager* pTextureManager);
|
||||
Player(const Vector2f& Position, TextureManager* pTextureManager);
|
||||
Collision::CollisionRect GetCollisionRect() const;
|
||||
void Update(float elapsedTime, WorldLevel& level);
|
||||
void Draw() const;
|
||||
|
||||
void SetPosition(Point2f pos) {
|
||||
void SetPosition(Vector2f pos) {
|
||||
m_Position = pos;
|
||||
}
|
||||
Point2f GetPosition() const {
|
||||
Vector2f GetPosition() const {
|
||||
return m_Position;
|
||||
}
|
||||
|
||||
void SetVelocity(Point2f vel) {
|
||||
void SetVelocity(Vector2f vel) {
|
||||
m_Vel = vel;
|
||||
}
|
||||
Point2f GetVelocity() const {
|
||||
Vector2f GetVelocity() const {
|
||||
return m_Vel;
|
||||
}
|
||||
|
||||
@@ -59,17 +59,22 @@ public:
|
||||
void ProcessImGui();
|
||||
|
||||
private:
|
||||
Point2f m_Position;
|
||||
Point2f m_Size;
|
||||
Vector2f m_Position;
|
||||
Vector2f m_Size;
|
||||
|
||||
Point2f m_Vel;
|
||||
Vector2f m_Vel;
|
||||
|
||||
std::map<Collision::CollisionDirection, WorldTile *> m_ContactMap;
|
||||
|
||||
Point2f m_Acc;
|
||||
Point2f m_Gravity { 0, -9.81f };
|
||||
Vector2f m_Acc;
|
||||
Vector2f m_Gravity { 0, -9.81f };
|
||||
|
||||
Point2f m_DigDestination{};
|
||||
Vector2f m_DigDestination{};
|
||||
float m_DigProgress{};
|
||||
bool m_HasDeletedTile{ false };
|
||||
WorldTile* m_DigTile{ nullptr };
|
||||
|
||||
const float m_DigTime{ 1.0f };
|
||||
|
||||
bool m_Grounded { false };
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
void StartHeapControl();
|
||||
void DumpMemoryLeaks();
|
||||
|
||||
Point2f Viewport { 900.f, 500.f };
|
||||
Vector2f Viewport { 900.f, 500.f };
|
||||
|
||||
int SDL_main(int argv, char** args) {
|
||||
srand(static_cast<unsigned int>(time(nullptr)));
|
||||
|
||||
Reference in New Issue
Block a user