diff --git a/src/Core/Game.cpp b/src/Core/Game.cpp index 5e08773..0ebbd0b 100644 --- a/src/Core/Game.cpp +++ b/src/Core/Game.cpp @@ -1,16 +1,26 @@ #include "Game.hpp" #include "Entity/Player.hpp" +#include "SDL3/SDL_render.h" +#include Game::Game() { SDL_Init(SDL_INIT_VIDEO); - this->window = SDL_CreateWindow("Wave Rush", 640, 320, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL); + this->window = SDL_CreateWindow("Wave Rush", 640, 360, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL); this->renderer = SDL_CreateRenderer(this->window, nullptr); + + this->textures[TEXTURE_PLAYER] = IMG_LoadTexture(this->renderer, "assets/textures/test.png"); + this->player = new Player({ 0, 0 }); } Game::~Game() { delete this->player; + + for (auto texture : this->textures) { + SDL_DestroyTexture(texture.second); + } + SDL_DestroyRenderer(this->renderer); SDL_DestroyWindow(this->window); SDL_Quit(); diff --git a/src/Core/Game.hpp b/src/Core/Game.hpp index 8a01ba3..483220e 100644 --- a/src/Core/Game.hpp +++ b/src/Core/Game.hpp @@ -6,14 +6,19 @@ struct Player; +enum TextureKey { + TEXTURE_PLAYER, +}; + struct Game { SDL_Window* window = nullptr; SDL_Renderer* renderer = nullptr; bool isRunning = true; - std::unordered_map isKeyDown = {}; u64 lastTime = 0; u64 currentTime = 0; f64 deltaTime = 0; + std::unordered_map isKeyDown = {}; + std::unordered_map textures = {}; Player* player = nullptr; Game(); diff --git a/src/Entity/Player.cpp b/src/Entity/Player.cpp index 2a7bed2..def577d 100644 --- a/src/Entity/Player.cpp +++ b/src/Entity/Player.cpp @@ -2,8 +2,6 @@ #include "Core/Game.hpp" #include "Core/Types.hpp" -#include "glm/fwd.hpp" -#include Player::Player(glm::vec2 startingPosition) { this->position = startingPosition; @@ -16,8 +14,6 @@ void Player::update(Game* game) { f32 distance = 1000; f32 time = game->deltaTime; - std::cout << time << std::endl; - if (game->isKeyDown[SDLK_UP]) { direction.y -= 1; } @@ -42,5 +38,5 @@ void Player::update(Game* game) { void Player::render(Game* game) { SDL_FRect rect = { this->position.x, this->position.y, this->size.x, this->size.y }; SDL_SetRenderDrawColor(game->renderer, 255, 255, 255, 255); - SDL_RenderFillRect(game->renderer, &rect); + SDL_RenderTexture(game->renderer, game->textures[TEXTURE_PLAYER], nullptr, &rect); } \ No newline at end of file