mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-18 11:49:20 +01:00
Add sun / moon, started on score / GameManager
This commit is contained in:
14
Game/Levels/World/OrbitingObject.cpp
Normal file
14
Game/Levels/World/OrbitingObject.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "pch.h"
|
||||
#include "OrbitingObject.h"
|
||||
|
||||
#include <iostream>
|
||||
OrbitingObject::OrbitingObject(const Vector2f& orbit, float distance, float speed, Texture* texture, float offset): m_Texture(texture), m_Orbit(orbit), m_Speed(speed), m_Distance(distance), m_currentCycle(offset) {
|
||||
}
|
||||
void OrbitingObject::Update(float elapsedSecs) {
|
||||
m_Position = Vector2f(m_Orbit.x + cosf(m_currentCycle) * m_Distance, m_Orbit.y + sinf(m_currentCycle) * m_Distance);
|
||||
m_currentCycle += m_Speed * elapsedSecs;
|
||||
}
|
||||
void OrbitingObject::Draw() const {
|
||||
m_Texture->Draw(m_Position);
|
||||
|
||||
}
|
||||
21
Game/Levels/World/OrbitingObject.h
Normal file
21
Game/Levels/World/OrbitingObject.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "Texture.h"
|
||||
|
||||
class OrbitingObject {
|
||||
public:
|
||||
OrbitingObject(const Vector2f& orbit, float distance, float speed, Texture* texture, float offset = 0);
|
||||
|
||||
void Update(float elapsedSecs);
|
||||
void Draw() const;
|
||||
|
||||
|
||||
private:
|
||||
Texture* m_Texture;
|
||||
Vector2f m_Position;
|
||||
Vector2f m_Orbit;
|
||||
float m_Distance;
|
||||
float m_Speed;
|
||||
|
||||
float m_currentCycle{ 0 };
|
||||
|
||||
};
|
||||
@@ -67,6 +67,8 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
|
||||
m_MainScreen = new MainScreen(TextureManager::GetInstance());
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
WorldLevel::~WorldLevel() {
|
||||
@@ -86,6 +88,9 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
// m_gridManager.GetTileAtIndex(x, y)->m_Hightlight = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
m_Sun->Update(elapsedSec);
|
||||
m_Moon->Update(elapsedSec);
|
||||
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
@@ -179,6 +184,9 @@ 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);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "GridSystem/WorldGridManager.h"
|
||||
#include "Gui/Screens/ScreenManager.h"
|
||||
#include "Camera.h"
|
||||
#include "OrbitingObject.h"
|
||||
#include "Text.h"
|
||||
#include "Gui/GuiMeter.h"
|
||||
#include "Gui/Screens/MainScreen.h"
|
||||
@@ -49,6 +50,9 @@ private:
|
||||
|
||||
MainScreen* m_MainScreen{};
|
||||
|
||||
OrbitingObject* m_Sun{ nullptr };
|
||||
OrbitingObject* m_Moon{ nullptr };
|
||||
|
||||
Texture* m_topCover{ nullptr };
|
||||
|
||||
// ImGui Vars
|
||||
|
||||
Reference in New Issue
Block a user