Compare commits

...

3 Commits

4 changed files with 35 additions and 1 deletions

6
.gitignore vendored
View File

@ -14,4 +14,8 @@ cmake-build-debug/
# Tooling files # Tooling files
output.txt output.txt
buildall.bat buildall.bat
typer.py typer.py
# Sandbox Assets
assets/
art/

View File

@ -1,8 +1,18 @@
#include "sprite_component.h" #include "sprite_component.h"
#include <raylib.h> #include <raylib.h>
#include "Logger.h"
#include "transform_component.h"
void SpriteComponent::Render(float x, float y) const { void SpriteComponent::Render(float x, float y) const {
if (texture) { if (texture) {
DrawTexture(*reinterpret_cast<Texture2D*>(texture), x, y, WHITE); DrawTexture(*reinterpret_cast<Texture2D*>(texture), x, y, WHITE);
} }
} }
void SpriteComponent::Render(TransformComponent transform) const {
if (texture) {
DrawTexture(*reinterpret_cast<Texture2D*>(texture), transform.x, transform.y, WHITE);
}
}

View File

@ -1,9 +1,13 @@
#pragma once #pragma once
#include "transform_component.h"
struct SpriteComponent { struct SpriteComponent {
public: public:
void* texture; // void* to abstract Texture2D void* texture; // void* to abstract Texture2D
void Render(float x, float y) const; void Render(float x, float y) const;
void Render(TransformComponent transform) const;
}; };
// Usage: // Usage:

View File

@ -26,14 +26,30 @@ public:
void UpdateActiveScene() { void UpdateActiveScene() {
if (activeScene != entt::null) { if (activeScene != entt::null) {
// Iterate over entities in the active scene that have an InputComponent
auto view = registry.view<InputComponent>();
for (auto entity : view) {
auto& inputComponent = view.get<InputComponent>(entity);
inputComponent.Update(); // This will call the input logic
}
} }
} }
void RenderActiveScene() { void RenderActiveScene() {
if (activeScene != entt::null) { if (activeScene != entt::null) {
// Iterate over entities in the active scene that have both SpriteComponent and TransformComponent
auto view = registry.view<SpriteComponent, TransformComponent>();
for (auto entity : view) {
auto& sprite = view.get<SpriteComponent>(entity);
auto& transform = view.get<TransformComponent>(entity);
// Render the sprite at the position defined by the TransformComponent
sprite.Render(transform);
}
} }
} }
private: private:
entt::registry& registry; entt::registry& registry;
entt::entity activeScene; entt::entity activeScene;