mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 15:53:42 +00:00
Compare commits
No commits in common. "b497991975905acc2ada3f809e59e48b94cf25cb" and "a8052b4bbbbaa72b5832bdd4e689bdeb14c41edf" have entirely different histories.
b497991975
...
a8052b4bbb
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -1,15 +1,19 @@
|
||||
[submodule "SDL"]
|
||||
path = extern/SDL
|
||||
url = https://github.com/libsdl-org/SDL.git
|
||||
branch = release-2.28.x
|
||||
[submodule "SDL_image"]
|
||||
path = extern/SDL_image
|
||||
url = https://github.com/libsdl-org/SDL_image.git
|
||||
branch = release-2.8.x
|
||||
[submodule "extern/SDL_mixer"]
|
||||
path = extern/SDL_mixer
|
||||
url = https://github.com/libsdl-org/SDL_mixer.git
|
||||
branch = release-2.8.x
|
||||
[submodule "extern/SDL_ttf"]
|
||||
path = extern/SDL_ttf
|
||||
url = https://github.com/libsdl-org/SDL_ttf.git
|
||||
branch = release-2.22.x
|
||||
[submodule "extern/tmxlite"]
|
||||
path = extern/tmxlite
|
||||
url = https://github.com/fallahn/tmxlite.git
|
||||
|
||||
@ -31,10 +31,11 @@ add_library(${PROJECT_NAME} ${SOURCES})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${ENGINE_INCLUDE_DIR})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC # should be private when all SDL functionality has a wrapper
|
||||
SDL3::SDL3-static
|
||||
SDL3_image::SDL3_image-static
|
||||
SDL3_mixer::SDL3_mixer-static
|
||||
SDL3_ttf::SDL3_ttf-static
|
||||
SDL2::SDL2main
|
||||
SDL2::SDL2-static
|
||||
SDL2_image::SDL2_image-static
|
||||
SDL2_mixer::SDL2_mixer-static
|
||||
SDL2_ttf::SDL2_ttf-static
|
||||
tmxlite
|
||||
)
|
||||
|
||||
|
||||
@ -2,12 +2,12 @@
|
||||
"folders":
|
||||
[
|
||||
{
|
||||
"path": ".",
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
],
|
||||
"settings":
|
||||
{
|
||||
"tab_size": 4,
|
||||
"tab_size": 4
|
||||
},
|
||||
"build_systems": [
|
||||
{
|
||||
@ -23,7 +23,7 @@
|
||||
"name": "Release",
|
||||
"shell_cmd": "cmake -DCMAKE_BUILD_TYPE=Release build && cmake --build build",
|
||||
},
|
||||
],
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Generate CMake",
|
||||
@ -43,10 +43,7 @@
|
||||
"name": "Generate documentation",
|
||||
"shell_cmd": "docker run --rm -v \"$project_path:/source\" -v \"$project_path/docs:/output\" -v \"$project_path/docs/Doxyfile:/Doxyfile\" vego_engine-docker",
|
||||
},
|
||||
],
|
||||
]
|
||||
}
|
||||
],
|
||||
"debugger_configurations":
|
||||
[
|
||||
],
|
||||
]
|
||||
}
|
||||
|
||||
2
extern/SDL
vendored
2
extern/SDL
vendored
@ -1 +1 @@
|
||||
Subproject commit e027b85cc457556071cbb2f3f1bcf8803c1bc001
|
||||
Subproject commit 05eb08053d48fea9052ad02b3d619244aeb868d3
|
||||
2
extern/SDL_image
vendored
2
extern/SDL_image
vendored
@ -1 +1 @@
|
||||
Subproject commit b1c8ec7d75e3d8398940c9e04a8b82886ae6163d
|
||||
Subproject commit abcf63aa71b4e3ac32120fa9870a6500ddcdcc89
|
||||
2
extern/SDL_mixer
vendored
2
extern/SDL_mixer
vendored
@ -1 +1 @@
|
||||
Subproject commit 5e2a70519294bc6ec44f1870b019ecd4760fde7d
|
||||
Subproject commit 5bcd40ad962dc72a3c051084ce128d78f7656566
|
||||
2
extern/SDL_ttf
vendored
2
extern/SDL_ttf
vendored
@ -1 +1 @@
|
||||
Subproject commit 4a8bda9197cc4d6fafd188bc9df6c7e8749a43a2
|
||||
Subproject commit 4a318f8dfaa1bb6f10e0c5e54052e25d3c7f3440
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <SDL3/SDL_render.h>
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
#include <SDL_render.h>
|
||||
#include <SDL_mixer.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
@ -24,7 +24,7 @@ public:
|
||||
AssetManager(Manager* manager);
|
||||
~AssetManager();
|
||||
|
||||
void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, float speed, const char* texturePath, Entity* owner);
|
||||
void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity* owner);
|
||||
void createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, std::string texturePath);
|
||||
|
||||
Vector2D calculateSpawnPosition();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL.h>
|
||||
|
||||
#include "Component.h"
|
||||
#include "Vector2D.h"
|
||||
@ -22,7 +22,7 @@ public:
|
||||
ColliderComponent(const char* tag, float hitboxScale);
|
||||
|
||||
void init() override;
|
||||
void update(uint_fast16_t diffTime) override;
|
||||
void update() override;
|
||||
void removeCollision();
|
||||
|
||||
void handleCollision(Vector2D& characterPos, SDL_Rect& characterCollider, SDL_Rect& componentCollider);
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
#include "ColliderComponent.h"
|
||||
#include "Constants.h"
|
||||
#include "Entity.h"
|
||||
#include <SDL3/SDL_rect.h>
|
||||
#include "SDL_rect.h"
|
||||
#include "SpriteComponent.h"
|
||||
#include "Vector2D.h"
|
||||
#include "Manager.h"
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
class Entity;
|
||||
|
||||
class Component
|
||||
@ -9,7 +8,7 @@ public:
|
||||
Entity* entity;
|
||||
|
||||
virtual void init() {}
|
||||
virtual void update(uint_fast16_t diffTime) {}
|
||||
virtual void update() {}
|
||||
|
||||
virtual ~Component() = default;
|
||||
};
|
||||
@ -59,7 +59,7 @@ public:
|
||||
explicit Entity(Manager& mManager) :
|
||||
manager(mManager) { };
|
||||
|
||||
void update(uint_fast16_t diffTime) const; //!< Call each frame to update all components
|
||||
void update() const; //!< Call each frame to update all components
|
||||
|
||||
bool isActive() const { return this->active; } //!< \sa destroy()
|
||||
//! Mark for destruction for Manager::refresh() and disables collision
|
||||
|
||||
@ -8,7 +8,7 @@ public:
|
||||
virtual ~Game() {}
|
||||
|
||||
virtual void init() = 0;
|
||||
virtual void update(uint_fast16_t diffTime) = 0;
|
||||
virtual void update() = 0;
|
||||
|
||||
GameInternal* gameInternal; //!< \deprecated
|
||||
};
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
#include <cstdint>
|
||||
#include <SDL.h>
|
||||
#include <SDL_image.h>
|
||||
#include <SDL_mixer.h>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
@ -27,10 +26,10 @@ public:
|
||||
GameInternal();
|
||||
~GameInternal();
|
||||
|
||||
SDL_AppResult init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
|
||||
void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
|
||||
|
||||
void handleEvents();
|
||||
void update(Uint64 frameTime);
|
||||
void update();
|
||||
void render();
|
||||
void clean();
|
||||
bool isRunning() const;
|
||||
@ -64,6 +63,4 @@ private:
|
||||
int counter = 0;
|
||||
bool running = true;
|
||||
SDL_Window* window;
|
||||
|
||||
Uint64 lastFrameTime = 0;
|
||||
};
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL.h>
|
||||
#include <map>
|
||||
|
||||
#include "Component.h"
|
||||
@ -94,12 +94,12 @@ public:
|
||||
~InputComponent();
|
||||
|
||||
void init() override;
|
||||
void update(uint_fast16_t diffTime) override;
|
||||
void update() override;
|
||||
|
||||
bool isKeyDown(Key key);
|
||||
|
||||
private:
|
||||
const bool* m_keyStates;
|
||||
const Uint8* m_keyStates;
|
||||
SDL_Scancode mapKeyToSDL(Key key);
|
||||
std::map<Key, SDL_Scancode> m_keyMappings;
|
||||
void InitKeyMappings();
|
||||
|
||||
@ -24,7 +24,7 @@ class Manager
|
||||
public:
|
||||
Manager(GameInternal* game) : game(game) {};
|
||||
|
||||
void update(uint_fast16_t diffTime); //!< \sa Entity::update()
|
||||
void update(); //!< \sa Entity::update()
|
||||
//! Disables all functionality of entities marked for destruction
|
||||
//! \sa Entity::destroy()
|
||||
void refresh();
|
||||
|
||||
@ -34,7 +34,7 @@ private:
|
||||
|
||||
struct TileSetData {
|
||||
std::string texturePath{};
|
||||
tmx::Vector2f textureSize;
|
||||
tmx::Vector2i textureSize;
|
||||
uint32_t tileCount{};
|
||||
tmx::Vector2u tileCount2D;
|
||||
uint32_t firstGID{};
|
||||
|
||||
@ -9,7 +9,7 @@ public:
|
||||
PowerupComponent(std::function<void (Entity*)> func);
|
||||
~PowerupComponent() {};
|
||||
|
||||
void update(uint_fast16_t diffTime) override;
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
std::function<void (Entity*)> pickupFunc;
|
||||
|
||||
@ -16,14 +16,14 @@ public:
|
||||
~ProjectileComponent() {}
|
||||
|
||||
void init() override;
|
||||
void update(uint_fast16_t diffTime) override;
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
TransformComponent* transformComponent;
|
||||
|
||||
int range = 0;
|
||||
float speed = 0;
|
||||
float distance = 0;
|
||||
int speed = 0;
|
||||
int distance = 0;
|
||||
|
||||
Entity* owner = nullptr;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
#include <SDL_mixer.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <SDL3/SDL_render.h>
|
||||
#include <SDL_render.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@ -22,7 +22,7 @@ public:
|
||||
private:
|
||||
TransformComponent* transform;
|
||||
SDL_Texture* texture;
|
||||
SDL_FRect srcRect, destRect;
|
||||
SDL_Rect srcRect, destRect;
|
||||
|
||||
const char* texturePath;
|
||||
|
||||
@ -48,7 +48,7 @@ public:
|
||||
void setTexture(const char* path);
|
||||
|
||||
void init() override;
|
||||
void update(uint_fast16_t diffTime) override;
|
||||
void update() override;
|
||||
void draw() override;
|
||||
void playAnimation(std::string type);
|
||||
void setDirection(Direction direction);
|
||||
|
||||
@ -16,7 +16,7 @@ public:
|
||||
~StatEffectsComponent() {};
|
||||
|
||||
void init() override;
|
||||
void update(uint_fast16_t diffTime) override;
|
||||
void update() override;
|
||||
|
||||
void modifyStatDur(Stats stat, int duration, int value);
|
||||
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "ECS.h"
|
||||
#include "SDL3/SDL_surface.h"
|
||||
#include <SDL3/SDL_render.h>
|
||||
#include <SDL_render.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -22,10 +21,7 @@ class TextureManager
|
||||
|
||||
SDL_Texture* loadTexture(const char* fileName);
|
||||
static std::vector<SDL_Rect> splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet);
|
||||
static void draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_FRect src, SDL_FRect dest, bool flipped = false);
|
||||
|
||||
void setScaleMode(SDL_ScaleMode scaleMode) { this->scaleMode = scaleMode; }
|
||||
static void draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect src, SDL_Rect dest, bool flipped = false);
|
||||
private:
|
||||
SDL_ScaleMode scaleMode = SDL_SCALEMODE_NEAREST;
|
||||
Manager* manager;
|
||||
};
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
@ -25,11 +25,11 @@ public:
|
||||
|
||||
void init() override;
|
||||
/*! TODO: document usage of collision handler */
|
||||
void update(uint_fast16_t diffTime) override;
|
||||
void update() override;
|
||||
void setPositionAfterCollision(Vector2D& positionChange);
|
||||
void modifySpeed(int8_t modifier);
|
||||
|
||||
private:
|
||||
int speed = 180;
|
||||
int speed = 3;
|
||||
int speedMod = 0;
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_rect.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_rect.h>
|
||||
|
||||
class Vector2D
|
||||
{
|
||||
|
||||
@ -46,7 +46,7 @@ Mix_Music* AssetManager::getMusic(std::string id)
|
||||
return music.at(id);
|
||||
}
|
||||
|
||||
void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, float speed, const char* texturePath, Entity* owner) {
|
||||
void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity* owner) {
|
||||
|
||||
auto& projectile(man->addEntity());
|
||||
projectile.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, scale); //32x32 is standard size for objects
|
||||
@ -86,7 +86,7 @@ Vector2D AssetManager::calculateSpawnPosition()
|
||||
conflict = false;
|
||||
for (auto cc : this->man->getGame()->collisionHandler->getColliders({ Entity::GroupLabel::MAPTILES }))
|
||||
{
|
||||
if (SDL_HasRectIntersection(&spawnRect, &cc->collider) && strcmp(cc->tag, "projectile"))
|
||||
if (SDL_HasIntersection(&spawnRect, &cc->collider) && strcmp(cc->tag, "projectile"))
|
||||
{
|
||||
conflict = true;
|
||||
break;
|
||||
|
||||
@ -31,10 +31,10 @@ void ColliderComponent::init()
|
||||
}
|
||||
|
||||
transform = &entity->getComponent<TransformComponent>();
|
||||
this->update(0);
|
||||
this->update();
|
||||
}
|
||||
|
||||
void ColliderComponent::update(uint_fast16_t diffTime)
|
||||
void ColliderComponent::update()
|
||||
{
|
||||
collider.x = transform->position.x - (transform->width - transform->width * transform->scale * this->hitboxScale) / 2;
|
||||
collider.y = transform->position.y - (transform->width - transform->width * transform->scale * this->hitboxScale) / 2;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
#include "Manager.h"
|
||||
#include "Vector2D.h"
|
||||
|
||||
#include <SDL3/SDL_rect.h>
|
||||
#include <SDL_rect.h>
|
||||
#include <bitset>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
@ -26,7 +26,7 @@ IntersectionBitSet CollisionHandler::getIntersection(Entity* entityA, Entity* en
|
||||
colliderB.x += posModB.x;
|
||||
colliderB.y += posModB.y;
|
||||
|
||||
if (!SDL_HasRectIntersection(
|
||||
if (!SDL_HasIntersection(
|
||||
&colliderA,
|
||||
&colliderB))
|
||||
return std::bitset<DIRECTION_C>();
|
||||
@ -152,7 +152,7 @@ Entity* CollisionHandler::getAnyIntersection<Entity*>(
|
||||
if (!entity->hasComponent<ColliderComponent>()) return nullptr;
|
||||
for (auto& collider : getColliders(groupLabels, excludedEntities)) {
|
||||
SDL_Rect rect = entity->getComponent<ColliderComponent>().collider + posMod;
|
||||
if (SDL_HasRectIntersection(&rect, &collider->collider)) {
|
||||
if (SDL_HasIntersection(&rect, &collider->collider)) {
|
||||
return collider->entity;
|
||||
}
|
||||
}
|
||||
@ -175,7 +175,7 @@ bool CollisionHandler::getAnyIntersection<bool>(
|
||||
if (!entity->hasComponent<ColliderComponent>()) return false;
|
||||
for (auto& collider : getColliders(groupLabels, excludedEntities)) {
|
||||
SDL_Rect rect = entity->getComponent<ColliderComponent>().collider + posMod;
|
||||
if (SDL_HasRectIntersection(&rect, &collider->collider)) {
|
||||
if (SDL_HasIntersection(&rect, &collider->collider)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,9 +4,9 @@
|
||||
#include "Component.h"
|
||||
#include <cstddef>
|
||||
|
||||
void Entity::update(uint_fast16_t diffTime) const
|
||||
void Entity::update() const
|
||||
{
|
||||
for (auto const& c : components) c->update(diffTime);
|
||||
for (auto const& c : components) c->update();
|
||||
}
|
||||
|
||||
bool Entity::hasGroup(Group mGroup)
|
||||
|
||||
@ -1,20 +1,23 @@
|
||||
#include "GameInternal.h"
|
||||
|
||||
#include <SDL_error.h>
|
||||
|
||||
#include "CollisionHandler.h"
|
||||
#include "AssetManager.h"
|
||||
#include "RenderManager.h"
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
#include "SDL3/SDL_init.h"
|
||||
#include "SDL_mixer.h"
|
||||
#include "SoundManager.h"
|
||||
#include "TileComponent.h"
|
||||
#include "Direction.h"
|
||||
#include "Entity.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "Map.h"
|
||||
#include "TextureManager.h"
|
||||
#include "StatEffectsComponent.h"
|
||||
#include "Constants.h"
|
||||
#include "Game.h"
|
||||
#include "GameFactory.h"
|
||||
|
||||
#include <VEGO.h>
|
||||
|
||||
GameInternal::GameInternal() :
|
||||
manager(this),
|
||||
renderManager(),
|
||||
@ -27,7 +30,7 @@ GameInternal::GameInternal() :
|
||||
|
||||
GameInternal::~GameInternal() = default;
|
||||
|
||||
SDL_AppResult GameInternal::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
|
||||
void GameInternal::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
|
||||
{
|
||||
GameInternal::assets = new AssetManager(&manager);
|
||||
GameInternal::textureManager = new TextureManager(&manager);
|
||||
@ -40,24 +43,24 @@ SDL_AppResult GameInternal::init(const char* title, int xpos, int ypos, int widt
|
||||
flags = SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
|
||||
if (!SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO))
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
||||
{
|
||||
std::cout << "ERROR. Subsystem couldnt be initialized! " << SDL_GetError() << std::endl;
|
||||
SDL_ClearError();
|
||||
return SDL_APP_FAILURE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Mix_Init(MIX_INIT_MP3) != MIX_INIT_MP3) {
|
||||
std::cout << "ERROR. Subsystem couldnt be initialized!" << std::endl;
|
||||
return SDL_APP_FAILURE;
|
||||
return;
|
||||
}
|
||||
|
||||
window = SDL_CreateWindow(title, width, height, flags);
|
||||
window = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
|
||||
if (!window)
|
||||
{
|
||||
std::cout << "ERROR: Window couldnt be created! " << SDL_GetError() << std::endl;
|
||||
SDL_ClearError();
|
||||
return SDL_APP_FAILURE;
|
||||
return;
|
||||
}
|
||||
|
||||
// bad
|
||||
@ -69,20 +72,20 @@ SDL_AppResult GameInternal::init(const char* title, int xpos, int ypos, int widt
|
||||
|
||||
SDL_SetWindowIcon(window, icon);
|
||||
|
||||
renderer = SDL_CreateRenderer(window, NULL);
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer)
|
||||
{
|
||||
std::cout << "ERROR: Renderer couldnt be created! " << SDL_GetError() << std::endl;
|
||||
SDL_ClearError();
|
||||
return SDL_APP_FAILURE;
|
||||
return;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
|
||||
if (!Mix_OpenAudio(0, NULL))
|
||||
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
|
||||
{
|
||||
std::cout << "ERROR: Mixer couldnt be initialized! " << SDL_GetError() << std::endl;
|
||||
SDL_ClearError();
|
||||
return SDL_APP_FAILURE;
|
||||
return;
|
||||
}
|
||||
|
||||
Mix_Volume(-1, MIX_MAX_VOLUME);
|
||||
@ -97,8 +100,6 @@ SDL_AppResult GameInternal::init(const char* title, int xpos, int ypos, int widt
|
||||
|
||||
this->gameInstance = GameFactory::instance().create(this);
|
||||
this->gameInstance->init();
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
void GameInternal::handleEvents()
|
||||
@ -107,7 +108,7 @@ void GameInternal::handleEvents()
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_EVENT_QUIT: this->setRunning(false);
|
||||
case SDL_QUIT: this->setRunning(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -115,16 +116,12 @@ void GameInternal::handleEvents()
|
||||
}
|
||||
}
|
||||
|
||||
void GameInternal::update(Uint64 frameTime)
|
||||
void GameInternal::update()
|
||||
{
|
||||
manager.refresh();
|
||||
manager.update();
|
||||
|
||||
uint_fast16_t diffTime = frameTime - this->lastFrameTime;
|
||||
manager.update(diffTime);
|
||||
|
||||
this->gameInstance->update(diffTime); // TODO: this might have to be split up into two update functions, before and after manager...
|
||||
|
||||
this->lastFrameTime = frameTime;
|
||||
this->gameInstance->update(); // TODO: this might have to be split up into two update functions, before and after manager...
|
||||
}
|
||||
|
||||
void GameInternal::render()
|
||||
|
||||
@ -10,7 +10,7 @@ InputComponent::~InputComponent() = default;
|
||||
|
||||
void InputComponent::init(){}
|
||||
|
||||
void InputComponent::update(uint_fast16_t diffTime)
|
||||
void InputComponent::update()
|
||||
{
|
||||
SDL_PumpEvents();
|
||||
}
|
||||
|
||||
@ -27,9 +27,9 @@ void Manager::refresh()
|
||||
std::end(entities));
|
||||
}
|
||||
|
||||
void Manager::update(uint_fast16_t diffTime)
|
||||
void Manager::update()
|
||||
{
|
||||
for (auto& e : entities) e->update(diffTime);
|
||||
for (auto& e : entities) e->update();
|
||||
}
|
||||
|
||||
void Manager::addToGroup(Entity* mEntity, Group mGroup)
|
||||
|
||||
12
src/Map.cpp
12
src/Map.cpp
@ -9,8 +9,8 @@
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
#include <SDL3/SDL_error.h>
|
||||
#include <SDL3/SDL_render.h>
|
||||
#include <SDL_error.h>
|
||||
#include <SDL_render.h>
|
||||
|
||||
#include <tmxlite/Layer.hpp>
|
||||
#include <tmxlite/Map.hpp>
|
||||
@ -102,14 +102,16 @@ void Map::loadTileLayer(const tmx::TileLayer& layer)
|
||||
| std::views::transform([&](uint16_t i) {
|
||||
const char* texturePath = this->mapData.texturePaths->at(i).c_str();
|
||||
|
||||
tmx::Vector2f textureSize;
|
||||
SDL_GetTextureSize(
|
||||
tmx::Vector2i textureSize;
|
||||
SDL_QueryTexture(
|
||||
VEGO_Game().textureManager->loadTexture(texturePath),
|
||||
nullptr,
|
||||
nullptr,
|
||||
&(textureSize.x),
|
||||
&(textureSize.y)
|
||||
);
|
||||
|
||||
tmx::Vector2u tileCount2D = { static_cast<unsigned int>(textureSize.x / this->mapData.mapTileSize->x), static_cast<unsigned int>(textureSize.y / this->mapData.mapTileSize->y) };
|
||||
tmx::Vector2u tileCount2D = { textureSize.x / this->mapData.mapTileSize->x, textureSize.y / this->mapData.mapTileSize->y };
|
||||
|
||||
uint32_t tileCount = this->mapData.tileSets->at(i).getTileCount();
|
||||
uint32_t firstGID = this->mapData.tileSets->at(i).getFirstGID();
|
||||
|
||||
@ -12,7 +12,7 @@ PowerupComponent::PowerupComponent(std::function<void (Entity*)> func)
|
||||
this->pickupFunc = func;
|
||||
}
|
||||
|
||||
void PowerupComponent::update(uint_fast16_t diffTime)
|
||||
void PowerupComponent::update()
|
||||
{
|
||||
Entity* player;
|
||||
if ((player = this->entity->getManager().getGame()->collisionHandler->getAnyIntersection<Entity*>(
|
||||
|
||||
@ -17,9 +17,9 @@ void ProjectileComponent::init()
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "throw_egg", true, PLAY_ONCE, MAX_VOLUME, -1);
|
||||
}
|
||||
|
||||
void ProjectileComponent::update(uint_fast16_t diffTime)
|
||||
void ProjectileComponent::update()
|
||||
{
|
||||
distance += speed * diffTime * (1.f/1000);
|
||||
distance += speed;
|
||||
|
||||
IntersectionBitSet boundsIntersection = this->entity->getManager().getGame()->collisionHandler->getIntersectionWithBounds(entity);
|
||||
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
#include "SoundManager.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
|
||||
#include "GameInternal.h"
|
||||
#include "AssetManager.h"
|
||||
|
||||
@ -66,12 +65,12 @@ void SoundManager::playSound(GameInternal* game, std::string sound, bool canOver
|
||||
|
||||
if(Mix_VolumeChunk(game->assets->getSound(sound), volume) == -1)
|
||||
{
|
||||
std::cerr << "Error adjusting volume: " /*<< Mix_GetError()*/ << std::endl;
|
||||
std::cerr << "Error adjusting volume: " << Mix_GetError() << std::endl;
|
||||
}
|
||||
|
||||
if (Mix_PlayChannel(channel, game->assets->getSound(sound), loops) == -1)
|
||||
{
|
||||
std::cerr << "Error playing sound '" << sound << "': " /*<< Mix_GetError()*/ << std::endl;
|
||||
std::cerr << "Error playing sound '" << sound << "': " << Mix_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,12 +87,12 @@ void SoundManager::playMusic(GameInternal* game, std::string music, int loops, i
|
||||
|
||||
if(Mix_VolumeMusic(volume) == -1)
|
||||
{
|
||||
std::cerr << "Error adjusting volume: " /*<< Mix_GetError()*/ << std::endl;
|
||||
std::cerr << "Error adjusting volume: " << Mix_GetError() << std::endl;
|
||||
}
|
||||
|
||||
if (Mix_PlayMusic(game->assets->getMusic(music), loops) == -1)
|
||||
{
|
||||
std::cerr << "Error playing music '" << music << "': " /*<< Mix_GetError()*/ << std::endl;
|
||||
std::cerr << "Error playing music '" << music << "': " << Mix_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "SpriteComponent.h"
|
||||
|
||||
#include <SDL3/SDL_timer.h>
|
||||
#include <SDL_timer.h>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
@ -59,14 +59,14 @@ void SpriteComponent::init()
|
||||
this->srcRect.x = this->textureXOffset * this->srcRect.w;
|
||||
this->srcRect.y = this->textureYOffset * this->srcRect.h;;
|
||||
|
||||
this->update(0);
|
||||
this->update();
|
||||
}
|
||||
|
||||
void SpriteComponent::update(uint_fast16_t diffTime)
|
||||
void SpriteComponent::update()
|
||||
{
|
||||
// This code is not compatible for animated tiles
|
||||
if (animated) {
|
||||
srcRect.x = srcRect.w * static_cast<int>((SDL_GetTicks() / speed) % frames); // TODO: should not call SDL_GetTicks() but use diffTime
|
||||
srcRect.x = srcRect.w * static_cast<int>((SDL_GetTicks() / speed) % frames);
|
||||
|
||||
srcRect.y = animationIndex * transform->height;
|
||||
}
|
||||
|
||||
@ -8,16 +8,16 @@
|
||||
void StatEffectsComponent::init()
|
||||
{}
|
||||
|
||||
void StatEffectsComponent::update(uint_fast16_t diffTime)
|
||||
void StatEffectsComponent::update()
|
||||
{
|
||||
for (int i = 0; i < MAX_STATS; i++)
|
||||
{
|
||||
if (this->buffs.at(i) <= 0) continue;
|
||||
if (this->buffs.at(i) - diffTime <= 0)
|
||||
if (this->buffs.at(i) == 0) continue;
|
||||
if (this->buffs.at(i) - 1 == 0)
|
||||
{
|
||||
this->resetStatValue((Stats)i);
|
||||
}
|
||||
this->buffs.at(i) -= diffTime;
|
||||
this->buffs.at(i) -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ void StatEffectsComponent::modifyStatValue(Stats stat, int modifier) //modifier
|
||||
switch (stat)
|
||||
{
|
||||
case Stats::MOVEMENT_SPEED:
|
||||
this->entity->getComponent<TransformComponent>().modifySpeed(modifier * 60);
|
||||
this->entity->getComponent<TransformComponent>().modifySpeed(modifier);
|
||||
break;
|
||||
case Stats::ATTACK_SPEED:
|
||||
// this->entity->getComponent<KeyboardController>().modifyAtkSpeed(modifier);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "TextureManager.h"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
@ -13,14 +14,13 @@ SDL_Texture* TextureManager::loadTexture(const char* fileName)
|
||||
}
|
||||
auto texture = IMG_LoadTexture(this->manager->getGame()->renderer, fileName);
|
||||
if (texture == NULL) throw std::runtime_error(std::string("Couldn't load texture '") + fileName + "'");
|
||||
SDL_SetTextureScaleMode(texture, this->scaleMode); // linear scaling results in blurry images
|
||||
this->texture_cache.emplace(std::string(fileName), texture);
|
||||
printf("Loaded texture at '%s'\n", fileName);
|
||||
return texture;
|
||||
}
|
||||
|
||||
void TextureManager::draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_FRect src, SDL_FRect dest, bool flipped)
|
||||
void TextureManager::draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect src, SDL_Rect dest, bool flipped)
|
||||
{
|
||||
SDL_FlipMode flip = flipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
SDL_RenderTextureRotated(renderer, texture, &src, &dest, 0, NULL, flip);
|
||||
SDL_RendererFlip flip = flipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
SDL_RenderCopyEx(renderer, texture, &src, &dest, 0, NULL, flip);
|
||||
}
|
||||
@ -50,12 +50,12 @@ void TransformComponent::init()
|
||||
direction.zero();
|
||||
}
|
||||
|
||||
void TransformComponent::update(uint_fast16_t diffTime)
|
||||
void TransformComponent::update()
|
||||
{
|
||||
float multiplier = direction.x != 0 && direction.y != 0 ? 0.707 : 1; // normalizes vector; only works if directions are in increments of 45°
|
||||
Vector2D positionChange(
|
||||
direction.x * this->getSpeed() * multiplier * diffTime * (1.f/1000),
|
||||
direction.y * this->getSpeed() * multiplier * diffTime * (1.f/1000)
|
||||
direction.x * this->getSpeed() * multiplier,
|
||||
direction.y * this->getSpeed() * multiplier
|
||||
);
|
||||
|
||||
if (this->entity->hasGroup((size_t)Entity::GroupLabel::PLAYERS)){
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#include "Vector2D.h"
|
||||
#include <SDL3/SDL_rect.h>
|
||||
#include "SDL_rect.h"
|
||||
|
||||
Vector2D::Vector2D()
|
||||
{
|
||||
|
||||
@ -1,48 +0,0 @@
|
||||
#include "SDL3/SDL_init.h"
|
||||
#include <cstdint>
|
||||
#define SDL_MAIN_USE_CALLBACKS
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
|
||||
#include "VEGO.h"
|
||||
#include "Entity.h"
|
||||
#include "GameInternal.h"
|
||||
#include "Constants.h"
|
||||
|
||||
GameInternal* vego::game = nullptr;
|
||||
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
|
||||
srand(time(NULL));
|
||||
bool playing = true;
|
||||
|
||||
*appstate = vego::game = new GameInternal();
|
||||
|
||||
return vego::game->init("No_Name_Chicken_Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_SIZE_WIDTH, SCREEN_SIZE_HEIGHT, false);
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppIterate(void *appstate) {
|
||||
if (!vego::game->isRunning()) {
|
||||
return SDL_APP_SUCCESS;
|
||||
}
|
||||
|
||||
vego::game->handleEvents(); // bad
|
||||
|
||||
Uint64 frameStart = SDL_GetTicks();
|
||||
|
||||
vego::game->update(frameStart);
|
||||
vego::game->render();
|
||||
|
||||
int frameTime = SDL_GetTicks() - frameStart;
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
void SDL_AppQuit(void *appstate, SDL_AppResult result) {
|
||||
vego::game->clean();
|
||||
}
|
||||
41
src/main.cpp
Normal file
41
src/main.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
|
||||
#include "VEGO.h"
|
||||
#include "Entity.h"
|
||||
#include "GameInternal.h"
|
||||
#include "Constants.h"
|
||||
|
||||
GameInternal* vego::game = nullptr;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
srand(time(NULL));
|
||||
bool playing = true;
|
||||
|
||||
const int frameDelay = 1000 / FPS;
|
||||
|
||||
Uint32 frameStart;
|
||||
int frameTime;
|
||||
|
||||
vego::game = new GameInternal();
|
||||
|
||||
vego::game->init("No_Name_Chicken_Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_SIZE_WIDTH, SCREEN_SIZE_HEIGHT, false);
|
||||
while (vego::game->isRunning()) {
|
||||
frameStart = SDL_GetTicks();
|
||||
|
||||
vego::game->handleEvents();
|
||||
vego::game->update();
|
||||
vego::game->render();
|
||||
|
||||
frameTime = SDL_GetTicks() - frameStart;
|
||||
|
||||
if (frameDelay > frameTime) {
|
||||
SDL_Delay(frameDelay - frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
vego::game->clean();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user