Skip to content

Commit

Permalink
add texture loading + rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
OhhhZenix committed Feb 9, 2025
1 parent 52d7eab commit 5dfc572
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/Core/Game.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
#include "Game.hpp"

#include "Entity/Player.hpp"
#include "SDL3/SDL_render.h"
#include <SDL3_image/SDL_image.h>

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();
Expand Down
7 changes: 6 additions & 1 deletion src/Core/Game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32, bool> isKeyDown = {};
u64 lastTime = 0;
u64 currentTime = 0;
f64 deltaTime = 0;
std::unordered_map<u32, bool> isKeyDown = {};
std::unordered_map<TextureKey, SDL_Texture*> textures = {};
Player* player = nullptr;

Game();
Expand Down
6 changes: 1 addition & 5 deletions src/Entity/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "Core/Game.hpp"
#include "Core/Types.hpp"
#include "glm/fwd.hpp"
#include <iostream>

Player::Player(glm::vec2 startingPosition) {
this->position = startingPosition;
Expand All @@ -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;
}
Expand All @@ -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);
}

0 comments on commit 5dfc572

Please sign in to comment.