Added the Grid, Camera, Level system

Basic player
Started (Barely) on the TextureManager
And other fixes
This commit is contained in:
Bram Verhulst
2024-03-11 03:29:44 +01:00
parent f7c2262e10
commit d6bb3add26
35 changed files with 991 additions and 62 deletions

View File

@@ -1,25 +1,72 @@
#include "pch.h"
#include "WorldLevel.h"
#include <iostream>
#include <ostream>
#include "colors.h"
#include "utils.h"
WorldLevel::WorldLevel() {
for (int i{ 0 }; i < 10; ++i) {
for (int j{ 0 }; j < 10; ++j) {
m_WorldTiles[i][j] = WorldTile{ Point2f{ (float)i * 50, (float)j * 50 }, GroundTileTypes::Dirt };
}
}
}
WorldLevel::~WorldLevel() {
}
void WorldLevel::Update(float elapsedSec) {
}
void WorldLevel::Draw() const {
for (int i{ 0 }; i < 10; ++i) {
for (int j{ 0 }; j < 10; ++j) {
utils::SetColor(Color4f{ 0.5f, 0.5f, 0.5f, 1.0f });
utils::FillRect(m_WorldTiles[i][j].GetPosition().x, m_WorldTiles[i][j].GetPosition().y, 50, 50);
WorldLevel::WorldLevel(Camera* camera) : Level(camera), m_mousePos{ 0, 0 }, m_player(Player{ Point2f{ 0, 100 } }) {
// 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;
m_worldTiles[x][y] = new WorldTile{ Point2f{ float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT}, GroundTileTypes::Dirt};
}
}
// std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png";
// m_pTextTexture = new Texture(dirtPath);
}
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_player.Update(elapsedSec, *this);
}
void WorldLevel::Draw() const {
m_pCamera->BeginRendering();
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
m_worldTiles[x][y]->Draw();
}
}
utils::SetColor(Colors::WHITE);
for (int x { -100 }; x < 100; ++x) {
for (int y { -100 }; y < 100; ++y) {
utils::DrawLine(x * 50, -5000, x * 50, 50000);
utils::DrawLine(-5000, y * 50, 50000, y * 50);
}
}
utils::SetColor(Colors::MAGENTA);
utils::FillEllipse(0, 0, 10, 10);
m_player.Draw();
m_pCamera->EndRendering();
//utils::SetColor(Colors::WHITE);
//m_pTextTexture->Draw(Point2f{ 0, 0 });
}
void WorldLevel::MouseMove(const Point2f& mousePos) {
m_mousePos = mousePos;
}
WorldTile* WorldLevel::GetTileAt(const Point2f& pos) const {
return nullptr;
}
void WorldLevel::SetTileAt(const Point2f& pos, WorldTile* tile) {
}
std::array<std::array<WorldTile*, WorldLevel::WORLD_WIDTH>, WorldLevel::WORLD_HEIGHT> WorldLevel::GetAllTiles() const {
return m_worldTiles;
}