Reformat + Basic animation system
General fixes
This commit is contained in:
@@ -11,20 +11,18 @@
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
WorldLevel::WorldLevel(Camera* camera, Rectf viewport):
|
||||
Level(camera),
|
||||
m_gridManager(WorldGridManager()),
|
||||
m_player(Player { Point2f { 0, 100 } }),
|
||||
m_mousePos { 0, 0 },
|
||||
m_viewport(viewport)
|
||||
{
|
||||
WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
m_gridManager(WorldGridManager()),
|
||||
m_player(Player { Point2f { 0, 100 }, TextureManager::GetInstance() }),
|
||||
m_mousePos { 0, 0 },
|
||||
m_viewport(viewport) {
|
||||
// The grid is 34 x 50 big, the top center is 0,0 in world coords
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
int actualX = x - WORLD_WIDTH / 2;
|
||||
Point2f pos = Point2f{ float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT};
|
||||
auto pos = Point2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
|
||||
GroundTileType* type = Tiles::AIR;
|
||||
switch(utils::randRange(0,2)) {
|
||||
switch (utils::randRange(0, 2)) {
|
||||
case 0:
|
||||
type = Tiles::DIRT;
|
||||
break;
|
||||
@@ -38,8 +36,7 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport):
|
||||
std::cout << "??" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
m_gridManager.SetTileAtIndex(x,y, new WorldTile{ pos, type, TextureManager::GetInstance() });
|
||||
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance() });
|
||||
}
|
||||
}
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
@@ -48,27 +45,27 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport):
|
||||
}
|
||||
WorldLevel::~WorldLevel() {
|
||||
//delete m_pTextTexture;
|
||||
|
||||
|
||||
}
|
||||
void WorldLevel::Update(float elapsedSec) {
|
||||
int mouseX, mouseY;
|
||||
SDL_GetMouseState(&mouseX, &mouseY);
|
||||
m_mousePos = Point2f{ float(mouseX), float(mouseY) };
|
||||
m_mousePos = Point2f { float(mouseX), float(mouseY) };
|
||||
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
|
||||
//m_player.Update(elapsedSec, *this);
|
||||
|
||||
|
||||
WorldTile* selectedTile{ nullptr };
|
||||
|
||||
WorldTile* selectedTile { nullptr };
|
||||
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
if(m_gridManager.GetTileAtIndex(x,y)->GetCollisionRect().Contains(m_mousePos)) {
|
||||
selectedTile = m_gridManager.GetTileAtIndex(x,y);
|
||||
if (m_gridManager.GetTileAtIndex(x, y)->GetCollisionRect().Contains(m_mousePos)) {
|
||||
selectedTile = m_gridManager.GetTileAtIndex(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(selectedTile != nullptr) {
|
||||
if(utils::isMouseDown(SDL_BUTTON_LEFT)) {
|
||||
if (selectedTile != nullptr) {
|
||||
if (utils::isMouseDown(SDL_BUTTON_LEFT)) {
|
||||
selectedTile->SetTileType(Tiles::AIR);
|
||||
}
|
||||
}
|
||||
@@ -76,7 +73,7 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
m_player.Update(elapsedSec, *this);
|
||||
|
||||
WorldTile* t = m_gridManager.GetTileAtWorldPos(m_mousePos);
|
||||
if(t != nullptr) {
|
||||
if (t != nullptr) {
|
||||
t->SetTileType(Tiles::AIR);
|
||||
}
|
||||
|
||||
@@ -100,15 +97,15 @@ void WorldLevel::Draw() const {
|
||||
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
m_gridManager.GetTileAtIndex(x,y)->Draw();
|
||||
m_gridManager.GetTileAtIndex(x, y)->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
//loop over worldtiles
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
if(*m_gridManager.GetTileAtIndex(x,y)->GetTileType() != Tiles::AIR) {
|
||||
Collision::CollisionRect rect = m_gridManager.GetTileAtIndex(x,y)->GetCollisionRect().getCollisionRect();
|
||||
if (*m_gridManager.GetTileAtIndex(x, y)->GetTileType() != Tiles::AIR) {
|
||||
Collision::CollisionRect rect = m_gridManager.GetTileAtIndex(x, y)->GetCollisionRect().getCollisionRect();
|
||||
utils::SetColor(Colors::GREEN);
|
||||
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);
|
||||
}
|
||||
@@ -134,16 +131,17 @@ void WorldLevel::ProcessImGui() {
|
||||
if (ImGui::MenuItem("Camera Info")) {
|
||||
m_ShowCameraWindow = !m_ShowCameraWindow;
|
||||
}
|
||||
if(ImGui::MenuItem("Player Info")) {
|
||||
if (ImGui::MenuItem("Player Info")) {
|
||||
m_ShowPlayerInfo = !m_ShowPlayerInfo;
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if(ImGui::BeginMenu(std::to_string(utils::isKeyPressed(SDL_SCANCODE_S)).c_str())){}
|
||||
if (ImGui::BeginMenu(std::to_string(utils::isKeyPressed(SDL_SCANCODE_S)).c_str())) {
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
if(m_ShowTextureManagerWindow) {
|
||||
if (m_ShowTextureManagerWindow) {
|
||||
ImGui::Begin("Texture Manager", &m_ShowTextureManagerWindow, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("Texture loading Count:");
|
||||
ImGui::SameLine();
|
||||
@@ -151,17 +149,17 @@ void WorldLevel::ProcessImGui() {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if(m_ShowCameraWindow) {
|
||||
if (m_ShowCameraWindow) {
|
||||
ImGui::Begin("Camera", &m_ShowCameraWindow, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("Camera Position: (%f, %f)", m_pCamera->GetPosition().x, m_pCamera->GetPosition().y);
|
||||
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});
|
||||
if (ImGui::Button("Reset Camera")) {
|
||||
m_pCamera->SetPosition(Point2f { -m_viewport.width / 2, -m_viewport.height / 2 });
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if(m_ShowPlayerInfo) {
|
||||
if (m_ShowPlayerInfo) {
|
||||
ImGui::Begin("Player Info", &m_ShowPlayerInfo, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("Player Position: (%f, %f)", m_player.GetPosition().x, m_player.GetPosition().y);
|
||||
ImGui::Text("Player Velocity: (%f, %f)", m_player.GetVelocity().x, m_player.GetVelocity().y);
|
||||
|
||||
Reference in New Issue
Block a user