mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 22:23:43 +00:00
Compare commits
No commits in common. "247d6cc173536c8d27c0bd75f3a72ce83e22133f" and "b321051ac5f8892379dcb228aa80d3e8a871f67d" have entirely different histories.
247d6cc173
...
b321051ac5
@ -16,5 +16,11 @@ struct Animation
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum AnimationType //TODO enum class
|
||||||
|
{
|
||||||
|
IDLE = 0,
|
||||||
|
WALK = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
include/Components.h
Normal file
13
include/Components.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ECS.h"
|
||||||
|
#include "Component.h"
|
||||||
|
#include "Manager.h"
|
||||||
|
#include "Entity.h"
|
||||||
|
#include "TransformComponent.h"
|
||||||
|
#include "SpriteComponent.h"
|
||||||
|
#include "KeyboardController.h"
|
||||||
|
#include "ColliderComponent.h"
|
||||||
|
#include "TileComponent.h"
|
||||||
|
#include "ProjectileComponent.h"
|
||||||
|
#include "HealthComponent.h"
|
||||||
@ -24,6 +24,10 @@ constexpr int MAP_SIZE_Y = 20;
|
|||||||
|
|
||||||
constexpr int SPAWN_ATTEMPTS = 20;
|
constexpr int SPAWN_ATTEMPTS = 20;
|
||||||
|
|
||||||
|
constexpr int BUFF_DURATION = 240;
|
||||||
|
|
||||||
|
constexpr int BUFF_VALUE = 1;
|
||||||
|
|
||||||
constexpr int PLAY_LOOPED = -1;
|
constexpr int PLAY_LOOPED = -1;
|
||||||
constexpr int PLAY_ONCE = 0;
|
constexpr int PLAY_ONCE = 0;
|
||||||
|
|
||||||
|
|||||||
@ -9,13 +9,6 @@
|
|||||||
#include "ECS.h"
|
#include "ECS.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
|
|
||||||
// TODO: remove here if possible
|
|
||||||
// temporary fix: addComponent function template doesnt know TransformComponent -> error undefined type
|
|
||||||
// #include "KeyboardController.h"
|
|
||||||
#include "InputComponent.h"
|
|
||||||
#include "TransformComponent.h"
|
|
||||||
#include "SpriteComponent.h"
|
|
||||||
|
|
||||||
class Manager;
|
class Manager;
|
||||||
class Component;
|
class Component;
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,76 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class GameInternal;
|
#include <SDL.h>
|
||||||
|
#include <SDL_image.h>
|
||||||
|
#include <SDL_mixer.h>
|
||||||
|
#include <functional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
// TODO: add managers here
|
#include "Manager.h"
|
||||||
class Game {
|
#include "Vector2D.h"
|
||||||
|
#include "Entity.h"
|
||||||
|
|
||||||
|
typedef std::function<void()> gamefunction;
|
||||||
|
|
||||||
|
class AssetManager;
|
||||||
|
class CollisionHandler;
|
||||||
|
class TextureManager;
|
||||||
|
class SoundManager;
|
||||||
|
class Map;
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
extern gamefunction init;
|
||||||
|
extern gamefunction update;
|
||||||
|
|
||||||
|
extern Game* game; // this is a temporary fix to remove artifacts of chicken_game from the engine while the API is not yet finalized
|
||||||
|
}
|
||||||
|
|
||||||
|
class Game
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Game() {}
|
Game();
|
||||||
|
~Game();
|
||||||
|
|
||||||
virtual void init() = 0;
|
void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
|
||||||
virtual void update() = 0;
|
void selectCharacters(const char* &playerSprite, const char* &enemySprite);
|
||||||
|
|
||||||
GameInternal* gameInternal; //!< \deprecated
|
void handleEvents();
|
||||||
|
void update();
|
||||||
|
void render();
|
||||||
|
void clean();
|
||||||
|
bool running() const;
|
||||||
|
|
||||||
|
/* static */ SDL_Renderer* renderer = nullptr;
|
||||||
|
/* static */ SDL_Event event;
|
||||||
|
/* static */ CollisionHandler* collisionHandler;
|
||||||
|
/* static */ AssetManager* assets;
|
||||||
|
/* static */ TextureManager* textureManager;
|
||||||
|
/* static */ SoundManager* soundManager;
|
||||||
|
|
||||||
|
// moved globals
|
||||||
|
Manager manager;
|
||||||
|
Map* map; // game specific, might not be needed for all types of games
|
||||||
|
|
||||||
|
Entity& player1;
|
||||||
|
Entity& player2;
|
||||||
|
|
||||||
|
Entity& wall;
|
||||||
|
|
||||||
|
std::vector<Entity*>& tiles;
|
||||||
|
std::vector<Entity*>& players;
|
||||||
|
std::vector<Entity*>& projectiles;
|
||||||
|
std::vector<Entity*>& hearts;
|
||||||
|
std::vector<Entity*>& powerups;
|
||||||
|
// end moved globals
|
||||||
|
|
||||||
|
void refreshPlayers();
|
||||||
|
Entity::TeamLabel getWinner() const;
|
||||||
|
void setWinner(Entity::TeamLabel winningTeam);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
bool isRunning = false;
|
||||||
|
SDL_Window* window;
|
||||||
|
Entity::TeamLabel winner;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// game factory include to simplify imports in implementation
|
|
||||||
#include "GameFactory.h"
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <iostream>
|
|
||||||
#include <map>
|
|
||||||
#include <functional>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "Game.h"
|
|
||||||
|
|
||||||
class GameInternal;
|
|
||||||
|
|
||||||
class GameFactory {
|
|
||||||
public:
|
|
||||||
using CreateFunc = std::function<Game*()>;
|
|
||||||
|
|
||||||
static GameFactory& instance() {
|
|
||||||
static GameFactory factory;
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*Game* get() {
|
|
||||||
assert(this->gameInstance != nullptr);
|
|
||||||
return this->gameInstance;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*Game* create(GameInternal* gameInternal) {
|
|
||||||
Game* game = this->gameInstance == nullptr ? this->creator() : this->gameInstance; // TODO: error handling
|
|
||||||
game->gameInternal = gameInternal;
|
|
||||||
this->gameInstance = game;
|
|
||||||
return game;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void registerClass(const std::string& className, CreateFunc createFunc) {
|
|
||||||
this->creators[className] = createFunc;
|
|
||||||
}
|
|
||||||
|
|
||||||
Game* create(const std::string& className, GameInternal* gameInternal) {
|
|
||||||
auto it = this->creators.find(className);
|
|
||||||
if (it != creators.end()) {
|
|
||||||
Game* game = it->second();
|
|
||||||
game->gameInternal = gameInternal;
|
|
||||||
return game;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
CreateFunc creator;
|
|
||||||
std::map<std::string, CreateFunc> creators;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
#define REGISTER_GAME(className) \
|
|
||||||
static bool registered_##className = []() { \
|
|
||||||
GameFactory::instance().registerClass(#className, []() -> Game* { return new className; }); \
|
|
||||||
return true; \
|
|
||||||
}();
|
|
||||||
*/
|
|
||||||
@ -1,68 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL.h>
|
|
||||||
#include <SDL_image.h>
|
|
||||||
#include <SDL_mixer.h>
|
|
||||||
#include <functional>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "Manager.h"
|
|
||||||
#include "Vector2D.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
|
|
||||||
typedef std::function<void()> gamefunction;
|
|
||||||
|
|
||||||
class AssetManager;
|
|
||||||
class CollisionHandler;
|
|
||||||
class TextureManager;
|
|
||||||
class SoundManager;
|
|
||||||
class Map;
|
|
||||||
class Game;
|
|
||||||
|
|
||||||
class GameInternal
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GameInternal();
|
|
||||||
~GameInternal();
|
|
||||||
|
|
||||||
void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
|
|
||||||
void selectCharacters(const char* &playerSprite, const char* &enemySprite);
|
|
||||||
|
|
||||||
void handleEvents();
|
|
||||||
void update();
|
|
||||||
void render();
|
|
||||||
void clean();
|
|
||||||
bool isRunning() const;
|
|
||||||
void setRunning(bool running);
|
|
||||||
|
|
||||||
/* static */ SDL_Renderer* renderer = nullptr;
|
|
||||||
/* static */ SDL_Event event;
|
|
||||||
/* static */ CollisionHandler* collisionHandler;
|
|
||||||
/* static */ AssetManager* assets;
|
|
||||||
/* static */ TextureManager* textureManager;
|
|
||||||
/* static */ SoundManager* soundManager;
|
|
||||||
|
|
||||||
// moved globals
|
|
||||||
Manager manager;
|
|
||||||
Map* map; // game specific, might not be needed for all types of games
|
|
||||||
|
|
||||||
std::vector<Entity*>& tiles;
|
|
||||||
std::vector<Entity*>& players;
|
|
||||||
std::vector<Entity*>& projectiles;
|
|
||||||
std::vector<Entity*>& hearts;
|
|
||||||
std::vector<Entity*>& powerups;
|
|
||||||
// end moved globals
|
|
||||||
|
|
||||||
void refreshPlayers();
|
|
||||||
Entity::TeamLabel getWinner() const;
|
|
||||||
void setWinner(Entity::TeamLabel winningTeam);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Game* gameInstance;
|
|
||||||
|
|
||||||
int counter = 0;
|
|
||||||
bool running = false;
|
|
||||||
SDL_Window* window;
|
|
||||||
Entity::TeamLabel winner;
|
|
||||||
};
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "GameFactory.h"
|
|
||||||
|
|
||||||
namespace vego {
|
|
||||||
template<typename T>
|
|
||||||
class GameRegistryHelper {
|
|
||||||
public:
|
|
||||||
GameRegistryHelper(const std::string& className) {
|
|
||||||
static_assert(std::is_base_of<Game, T>::value, "Your class must inherit from Game");
|
|
||||||
GameFactory::instance().registerClass(
|
|
||||||
className,
|
|
||||||
[]() -> Game* { return new T; }
|
|
||||||
);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "Direction.h"
|
#include "Direction.h"
|
||||||
#include "Component.h"
|
#include "Component.h"
|
||||||
|
|
||||||
@ -10,7 +9,7 @@ class HealthComponent : public Component
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
HealthComponent(int health, Direction side, std::string healthTexture) : health(health), side(side), healthTexture(healthTexture) {}
|
HealthComponent(int health, Direction side) : health(health), side(side) {}
|
||||||
~HealthComponent() {}
|
~HealthComponent() {}
|
||||||
|
|
||||||
void modifyHealth(int health = -1);
|
void modifyHealth(int health = -1);
|
||||||
@ -27,5 +26,4 @@ private:
|
|||||||
|
|
||||||
int health;
|
int health;
|
||||||
Direction side;
|
Direction side;
|
||||||
std::string healthTexture;
|
|
||||||
};
|
};
|
||||||
@ -1,107 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <SDL.h>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include "Component.h"
|
|
||||||
|
|
||||||
enum class Key
|
|
||||||
{
|
|
||||||
UP,
|
|
||||||
DOWN,
|
|
||||||
LEFT,
|
|
||||||
RIGHT,
|
|
||||||
SPACE,
|
|
||||||
ENTER,
|
|
||||||
ESCAPE,
|
|
||||||
TAB,
|
|
||||||
BACKSPACE,
|
|
||||||
DELETE,
|
|
||||||
HOME,
|
|
||||||
END,
|
|
||||||
PAGE_UP,
|
|
||||||
PAGE_DOWN,
|
|
||||||
INSERT,
|
|
||||||
CAPS_LOCK,
|
|
||||||
LEFT_SHIFT,
|
|
||||||
RIGHT_SHIFT,
|
|
||||||
LEFT_CTRL,
|
|
||||||
RIGHT_CTRL,
|
|
||||||
LEFT_ALT,
|
|
||||||
RIGHT_ALT,
|
|
||||||
F1,
|
|
||||||
F2,
|
|
||||||
F3,
|
|
||||||
F4,
|
|
||||||
F5,
|
|
||||||
F6,
|
|
||||||
F7,
|
|
||||||
F8,
|
|
||||||
F9,
|
|
||||||
F10,
|
|
||||||
F11,
|
|
||||||
F12,
|
|
||||||
A,
|
|
||||||
B,
|
|
||||||
C,
|
|
||||||
D,
|
|
||||||
E,
|
|
||||||
F,
|
|
||||||
G,
|
|
||||||
H,
|
|
||||||
I,
|
|
||||||
J,
|
|
||||||
K,
|
|
||||||
L,
|
|
||||||
M,
|
|
||||||
N,
|
|
||||||
O,
|
|
||||||
P,
|
|
||||||
Q,
|
|
||||||
R,
|
|
||||||
S,
|
|
||||||
T,
|
|
||||||
U,
|
|
||||||
V,
|
|
||||||
W,
|
|
||||||
X,
|
|
||||||
Y,
|
|
||||||
Z,
|
|
||||||
NUM_0,
|
|
||||||
NUM_1,
|
|
||||||
NUM_2,
|
|
||||||
NUM_3,
|
|
||||||
NUM_4,
|
|
||||||
NUM_5,
|
|
||||||
NUM_6,
|
|
||||||
NUM_7,
|
|
||||||
NUM_8,
|
|
||||||
NUM_9,
|
|
||||||
LEFT_BRACKET,
|
|
||||||
RIGHT_BRACKET,
|
|
||||||
SEMICOLON,
|
|
||||||
APOSTROPHE,
|
|
||||||
COMMA,
|
|
||||||
PERIOD,
|
|
||||||
SLASH,
|
|
||||||
BACKSLASH,
|
|
||||||
GRAVE
|
|
||||||
};
|
|
||||||
|
|
||||||
class InputComponent : public Component
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
InputComponent();
|
|
||||||
~InputComponent();
|
|
||||||
|
|
||||||
void init() override;
|
|
||||||
void update() override;
|
|
||||||
|
|
||||||
// void pollEvents();
|
|
||||||
bool isKeyDown(Key key);
|
|
||||||
|
|
||||||
private:
|
|
||||||
const Uint8* m_keyStates;
|
|
||||||
SDL_Scancode mapKeyToSDL(Key key);
|
|
||||||
std::map<Key, SDL_Scancode> m_keyMappings;
|
|
||||||
void InitKeyMappings();
|
|
||||||
};
|
|
||||||
44
include/KeyboardController.h
Normal file
44
include/KeyboardController.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
#include "Vector2D.h"
|
||||||
|
#include "Constants.h"
|
||||||
|
#include "SoundManager.h"
|
||||||
|
|
||||||
|
class TransformComponent;
|
||||||
|
class SpriteComponent;
|
||||||
|
|
||||||
|
class KeyboardController : public Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TransformComponent* transform;
|
||||||
|
const uint8_t* keystates = SDL_GetKeyboardState(NULL);
|
||||||
|
SDL_Scancode up;
|
||||||
|
SDL_Scancode down;
|
||||||
|
SDL_Scancode left;
|
||||||
|
SDL_Scancode right;
|
||||||
|
SDL_Scancode fire;
|
||||||
|
|
||||||
|
SpriteComponent* sprite;
|
||||||
|
|
||||||
|
//for attack cooldown in between shots
|
||||||
|
uint32_t lastFireTime = 0;
|
||||||
|
uint32_t fireCooldown = 1000; //in ms can be adjusted to change possible attack-speed
|
||||||
|
|
||||||
|
KeyboardController() = default;
|
||||||
|
KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity);
|
||||||
|
~KeyboardController() = default;
|
||||||
|
|
||||||
|
void init() override;
|
||||||
|
void update() override;
|
||||||
|
|
||||||
|
void modifyAtkSpeed(int8_t modifier);
|
||||||
|
|
||||||
|
private:
|
||||||
|
//for creation of projectiles
|
||||||
|
TransformComponent* player; //for starting position of projectile
|
||||||
|
Vector2D fireVelocity; //decide source of projectile and flying direction
|
||||||
|
// SoundManager* soundEffect = Game::assets->getSound;
|
||||||
|
//SoundManager* soundEffect = new SoundManager();
|
||||||
|
};
|
||||||
@ -9,11 +9,11 @@
|
|||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
|
||||||
class GameInternal;
|
class Game;
|
||||||
class Manager
|
class Manager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Manager(GameInternal* game) : game(game) {};
|
Manager(Game* game) : game(game) {};
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
void draw();
|
void draw();
|
||||||
@ -29,10 +29,10 @@ public:
|
|||||||
|
|
||||||
Entity& addEntity();
|
Entity& addEntity();
|
||||||
|
|
||||||
GameInternal* getGame() { return this->game; };
|
Game* getGame() { return this->game; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GameInternal* game;
|
Game* game;
|
||||||
std::vector<std::unique_ptr<Entity>> entities;
|
std::vector<std::unique_ptr<Entity>> entities;
|
||||||
std::array<std::vector<Entity*>, MAX_GROUPS> entitiesByGroup;
|
std::array<std::vector<Entity*>, MAX_GROUPS> entitiesByGroup;
|
||||||
std::array<std::vector<Entity*>, MAX_TEAMS> entitiesByTeam;
|
std::array<std::vector<Entity*>, MAX_TEAMS> entitiesByTeam;
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class GameInternal;
|
class Game;
|
||||||
class Map
|
class Map
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -21,6 +21,6 @@ public:
|
|||||||
* \return Boolean for success
|
* \return Boolean for success
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */);
|
static void loadMap(const char* path, int sizeX, int sizeY, Game* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */);
|
||||||
static void addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict);
|
static void addTile(unsigned long id, int x, int y, Game* game, const std::map<int, std::pair<std::string, bool>>* textureDict);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
|
||||||
class GameInternal;
|
class Game;
|
||||||
|
|
||||||
class PopupWindow {
|
class PopupWindow {
|
||||||
|
|
||||||
|
|||||||
@ -13,9 +13,7 @@
|
|||||||
// THROW_EGG,
|
// THROW_EGG,
|
||||||
// };
|
// };
|
||||||
|
|
||||||
// class Game;
|
class Game;
|
||||||
|
|
||||||
class GameInternal;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
*
|
*
|
||||||
@ -50,9 +48,9 @@ class SoundManager
|
|||||||
//! \returns a pointer to Mix_Chunk, which is added to a map in the AssetManager
|
//! \returns a pointer to Mix_Chunk, which is added to a map in the AssetManager
|
||||||
//! \sa AssetManager::AddSound(std::string id, const char* path)
|
//! \sa AssetManager::AddSound(std::string id, const char* path)
|
||||||
|
|
||||||
static void playSound(GameInternal* game, std::string sound, bool canOverlap, int loops, int volume, int channel); //!< Plays sound effects
|
static void playSound(Game* game, std::string sound, bool canOverlap, int loops, int volume, int channel); //!< Plays sound effects
|
||||||
//! handles if sounds can overlap, how often they can loop, as well as the volume at which the specified sound effect should play
|
//! handles if sounds can overlap, how often they can loop, as well as the volume at which the specified sound effect should play
|
||||||
static void playMusic(GameInternal* game, std::string sound, int loops, int volume, int ms); //<! Plays music
|
static void playMusic(Game* game, std::string sound, int loops, int volume, int ms); //<! Plays music
|
||||||
//! handles how often the track should loop, as well as the volume at which the specified track should play
|
//! handles how often the track should loop, as well as the volume at which the specified track should play
|
||||||
|
|
||||||
static void setSoundVolume(int volume, int channel); //!< Volume handling for the entire program
|
static void setSoundVolume(int volume, int channel); //!< Volume handling for the entire program
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <SDL_render.h>
|
#include <SDL_render.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "AnimationHandler.h"
|
#include "AnimationHandler.h"
|
||||||
#include "Component.h"
|
#include "Component.h"
|
||||||
@ -16,7 +15,7 @@ class SpriteComponent : public Component
|
|||||||
public:
|
public:
|
||||||
int animationIndex = 0;
|
int animationIndex = 0;
|
||||||
|
|
||||||
std::map<std::string, std::unique_ptr<Animation>>* animations = nullptr;
|
std::map<AnimationType, std::unique_ptr<Animation>> animations;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TransformComponent* transform;
|
TransformComponent* transform;
|
||||||
@ -33,11 +32,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
SpriteComponent() = default;
|
SpriteComponent() = default;
|
||||||
SpriteComponent(const char* path);
|
SpriteComponent(const char* path);
|
||||||
SpriteComponent(
|
SpriteComponent(const char* path, bool isAnimated);
|
||||||
const char* path,
|
|
||||||
bool isAnimated,
|
|
||||||
std::map<std::string, std::unique_ptr<Animation>>* animationList,
|
|
||||||
std::string defaultAnimation);
|
|
||||||
~SpriteComponent();
|
~SpriteComponent();
|
||||||
|
|
||||||
void setTexture(const char* path);
|
void setTexture(const char* path);
|
||||||
@ -45,6 +40,6 @@ public:
|
|||||||
void init() override;
|
void init() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
void draw() override;
|
void draw() override;
|
||||||
void playAnimation(std::string type);
|
void playAnimation(AnimationType type);
|
||||||
void setDirection(Direction direction);
|
void setDirection(Direction direction);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -18,10 +18,9 @@ public:
|
|||||||
void init() override;
|
void init() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
void modifyStatDur(Stats stat, int duration, int value);
|
void modifyStatDur(Stats stat, int duration);
|
||||||
|
|
||||||
void modifyStatValue(Stats stat, int modifier);
|
void modifyStatValue(Stats stat, int modifier);
|
||||||
void resetStatValue(Stats stat);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<int, MAX_STATS> buffs = { 0 };
|
std::array<int, MAX_STATS> buffs = { 0 };
|
||||||
|
|||||||
@ -14,8 +14,7 @@ public:
|
|||||||
int width = 32;
|
int width = 32;
|
||||||
int scale = 1;
|
int scale = 1;
|
||||||
|
|
||||||
int getSpeed() { return speed + speedMod; };
|
int speed = 3;
|
||||||
void resetSpeedMod() { speedMod = 0; };
|
|
||||||
|
|
||||||
TransformComponent();
|
TransformComponent();
|
||||||
explicit TransformComponent(int scale);
|
explicit TransformComponent(int scale);
|
||||||
@ -27,8 +26,4 @@ public:
|
|||||||
void update() override;
|
void update() override;
|
||||||
void setPositionAfterCollision(Vector2D& positionChange);
|
void setPositionAfterCollision(Vector2D& positionChange);
|
||||||
void modifySpeed(int8_t modifier);
|
void modifySpeed(int8_t modifier);
|
||||||
|
|
||||||
private:
|
|
||||||
int speed = 3;
|
|
||||||
int speedMod = 0;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "SoundManager.h"
|
#include "SoundManager.h"
|
||||||
#include "ProjectileComponent.h"
|
#include "Components.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
|
|
||||||
#include "TransformComponent.h"
|
#include "TransformComponent.h"
|
||||||
|
|
||||||
@ -11,6 +11,7 @@
|
|||||||
#include "ColliderComponent.h"
|
#include "ColliderComponent.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
#include "Game.h"
|
||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
#include "PowerupComponent.h"
|
#include "PowerupComponent.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "CollisionHandler.h"
|
#include "CollisionHandler.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
#include "TransformComponent.h"
|
#include "TransformComponent.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ void Entity::delGroup(Group mGroup)
|
|||||||
groupBitSet[mGroup] = false;
|
groupBitSet[mGroup] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::bitset<MAX_GROUPS> Entity::getGroupBitSet()
|
std::bitset<MAX_GROUPS> Entity::getGroupBitSet()
|
||||||
{
|
{
|
||||||
return groupBitSet;
|
return groupBitSet;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
|
|
||||||
#include <SDL_error.h>
|
#include <SDL_error.h>
|
||||||
|
|
||||||
#include "CollisionHandler.h"
|
#include "CollisionHandler.h"
|
||||||
|
#include "Components.h"
|
||||||
#include "AssetManager.h"
|
#include "AssetManager.h"
|
||||||
#include "SoundManager.h"
|
|
||||||
// #include "KeyboardController.h"
|
|
||||||
#include "TileComponent.h"
|
|
||||||
#include "Direction.h"
|
#include "Direction.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
@ -14,28 +12,31 @@
|
|||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "StatEffectsComponent.h"
|
#include "StatEffectsComponent.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "Game.h"
|
|
||||||
#include "GameFactory.h"
|
|
||||||
|
|
||||||
GameInternal::GameInternal() :
|
Game* engine::game = nullptr; // will be initialized in constructor
|
||||||
|
|
||||||
|
Game::Game() :
|
||||||
manager(this),
|
manager(this),
|
||||||
tiles(manager.getGroup((size_t)Entity::GroupLabel::MAPTILES)),
|
tiles(manager.getGroup((size_t)Entity::GroupLabel::MAPTILES)),
|
||||||
players(manager.getGroup((size_t)Entity::GroupLabel::PLAYERS)),
|
players(manager.getGroup((size_t)Entity::GroupLabel::PLAYERS)),
|
||||||
projectiles(manager.getGroup((size_t)Entity::GroupLabel::PROJECTILE)),
|
projectiles(manager.getGroup((size_t)Entity::GroupLabel::PROJECTILE)),
|
||||||
hearts(manager.getGroup((size_t)Entity::GroupLabel::HEARTS)),
|
hearts(manager.getGroup((size_t)Entity::GroupLabel::HEARTS)),
|
||||||
powerups(manager.getGroup((size_t)Entity::GroupLabel::POWERUPS))
|
powerups(manager.getGroup((size_t)Entity::GroupLabel::POWERUPS)),
|
||||||
//player1(manager.addEntity()),
|
player1(manager.addEntity()),
|
||||||
//player2(manager.addEntity())
|
player2(manager.addEntity()),
|
||||||
{};
|
wall(manager.addEntity())
|
||||||
|
|
||||||
GameInternal::~GameInternal() = default;
|
|
||||||
|
|
||||||
void GameInternal::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
|
|
||||||
{
|
{
|
||||||
GameInternal::assets = new AssetManager(&manager);
|
engine::game = this;
|
||||||
GameInternal::textureManager = new TextureManager(&manager);
|
};
|
||||||
GameInternal::soundManager = new SoundManager();
|
|
||||||
GameInternal::collisionHandler = new CollisionHandler(manager); // why does this use a referrence, but AssetManager a pointer?
|
Game::~Game() = default;
|
||||||
|
|
||||||
|
void Game::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
|
||||||
|
{
|
||||||
|
Game::assets = new AssetManager(&manager);
|
||||||
|
Game::textureManager = new TextureManager(&manager);
|
||||||
|
Game::soundManager = new SoundManager();
|
||||||
|
Game::collisionHandler = new CollisionHandler(manager); // why does this use a referrence, but AssetManager a pointer?
|
||||||
|
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
@ -81,7 +82,7 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he
|
|||||||
}
|
}
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||||
|
|
||||||
SDL_Texture* backgroundTexture = GameInternal::textureManager->loadTexture("assets/startscreen.png");
|
SDL_Texture* backgroundTexture = Game::textureManager->loadTexture("assets/startscreen.png");
|
||||||
|
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
SDL_RenderCopy(renderer, backgroundTexture, NULL, NULL);
|
SDL_RenderCopy(renderer, backgroundTexture, NULL, NULL);
|
||||||
@ -103,7 +104,7 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he
|
|||||||
while (!hasQuit)
|
while (!hasQuit)
|
||||||
{
|
{
|
||||||
SDL_PollEvent(&event);
|
SDL_PollEvent(&event);
|
||||||
|
|
||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
hasQuit = true;
|
hasQuit = true;
|
||||||
@ -128,18 +129,18 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he
|
|||||||
|
|
||||||
if (hasQuit)
|
if (hasQuit)
|
||||||
{
|
{
|
||||||
this->setRunning(false);
|
this->isRunning = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// engine::init(); // temporarily moved down to access groups at engine init call
|
engine::init();
|
||||||
|
|
||||||
// character selection
|
// character selection
|
||||||
const char* player1Sprite;
|
const char* player1Sprite;
|
||||||
const char* player2Sprite;
|
const char* player2Sprite;
|
||||||
|
|
||||||
selectCharacters(player1Sprite, player2Sprite);
|
selectCharacters(player1Sprite, player2Sprite);
|
||||||
if (this->isRunning() == false) return;
|
if (this->isRunning == false) return;
|
||||||
|
|
||||||
map = new Map();
|
map = new Map();
|
||||||
|
|
||||||
@ -156,34 +157,31 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he
|
|||||||
assets->addSoundEffect("steps", "assets/sound/steps.wav");
|
assets->addSoundEffect("steps", "assets/sound/steps.wav");
|
||||||
|
|
||||||
// loading music
|
// loading music
|
||||||
// assets->addMusic("background_music", "assets/sound/background_music.mp3");
|
assets->addMusic("background_music", "assets/sound/background_music.mp3");
|
||||||
|
|
||||||
//ecs implementation
|
//ecs implementation
|
||||||
|
|
||||||
// player1.setTeam(Entity::TeamLabel::BLUE);
|
player1.setTeam(Entity::TeamLabel::BLUE);
|
||||||
// player1.addComponent<TransformComponent>(80,80,2); //posx, posy, scale
|
player1.addComponent<TransformComponent>(80,80,2); //posx, posy, scale
|
||||||
// player1.addComponent<SpriteComponent>(player1Sprite, true); //adds sprite (32x32px), path needed
|
player1.addComponent<SpriteComponent>(player1Sprite, true); //adds sprite (32x32px), path needed
|
||||||
// player1.addComponent<KeyboardController>(SDL_SCANCODE_W, SDL_SCANCODE_S, SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_SCANCODE_E, Vector2D(2, 0));//custom keycontrols can be added
|
player1.addComponent<KeyboardController>(SDL_SCANCODE_W, SDL_SCANCODE_S, SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_SCANCODE_E, Vector2D(2, 0));//custom keycontrols can be added
|
||||||
// player1.addComponent<ColliderComponent>("player", 0.8f); //adds tag (for further use, reference tag)
|
player1.addComponent<ColliderComponent>("player", 0.8f); //adds tag (for further use, reference tag)
|
||||||
// player1.addComponent<HealthComponent>(5, Direction::LEFT, "assets/heart.png");
|
player1.addComponent<HealthComponent>(5, Direction::LEFT);
|
||||||
// player1.addComponent<StatEffectsComponent>();
|
player1.addComponent<StatEffectsComponent>();
|
||||||
// player1.addGroup((size_t) Entity::GroupLabel::PLAYERS); //tell programm what group it belongs to for rendering order
|
player1.addGroup((size_t) Entity::GroupLabel::PLAYERS); //tell programm what group it belongs to for rendering order
|
||||||
|
|
||||||
|
|
||||||
// player2.setTeam(Entity::TeamLabel::RED);
|
player2.setTeam(Entity::TeamLabel::RED);
|
||||||
// player2.addComponent<TransformComponent>(600, 500, 2);
|
player2.addComponent<TransformComponent>(600, 500, 2);
|
||||||
// player2.addComponent<SpriteComponent>(player2Sprite, true);
|
player2.addComponent<SpriteComponent>(player2Sprite, true);
|
||||||
// player2.addComponent<KeyboardController>(SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_RCTRL, Vector2D(-2, 0));
|
player2.addComponent<KeyboardController>(SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_RCTRL, Vector2D(-2, 0));
|
||||||
// player2.addComponent<ColliderComponent>("enemy", 0.8f);
|
player2.addComponent<ColliderComponent>("enemy", 0.8f);
|
||||||
// player2.addComponent<HealthComponent>(5, Direction::RIGHT, "assets/heart.png");
|
player2.addComponent<HealthComponent>(5, Direction::RIGHT);
|
||||||
// player2.addComponent<StatEffectsComponent>();
|
player2.addComponent<StatEffectsComponent>();
|
||||||
// player2.addGroup((size_t) Entity::GroupLabel::PLAYERS);
|
player2.addGroup((size_t) Entity::GroupLabel::PLAYERS);
|
||||||
|
|
||||||
this->gameInstance = GameFactory::instance().create("Chickengame", this); //!< \todo Should be specified via a config file
|
|
||||||
this->gameInstance->init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameInternal::selectCharacters(const char* &playerSprite, const char* &enemySprite)
|
void Game::selectCharacters(const char* &playerSprite, const char* &enemySprite)
|
||||||
{
|
{
|
||||||
// TODO: move this whereever it makes sense (maybe game as a member)
|
// TODO: move this whereever it makes sense (maybe game as a member)
|
||||||
std::map<int, std::pair<const char*, const char*>> characterSprites;
|
std::map<int, std::pair<const char*, const char*>> characterSprites;
|
||||||
@ -251,7 +249,7 @@ void GameInternal::selectCharacters(const char* &playerSprite, const char* &enem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Texture* backgroundTexture = GameInternal::textureManager->loadTexture("assets/characterSelection.png");
|
SDL_Texture* backgroundTexture = Game::textureManager->loadTexture("assets/characterSelection.png");
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
SDL_RenderCopy(renderer, backgroundTexture, NULL, NULL);
|
SDL_RenderCopy(renderer, backgroundTexture, NULL, NULL);
|
||||||
|
|
||||||
@ -270,22 +268,22 @@ void GameInternal::selectCharacters(const char* &playerSprite, const char* &enem
|
|||||||
|
|
||||||
if (hasQuit)
|
if (hasQuit)
|
||||||
{
|
{
|
||||||
this->setRunning(false);
|
this->isRunning = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerSprite = characterSprites.find(playerSelection)->second.second;
|
playerSprite = characterSprites.find(playerSelection)->second.second;
|
||||||
enemySprite = characterSprites.find(enemySelection)->second.second;
|
enemySprite = characterSprites.find(enemySelection)->second.second;
|
||||||
this->setRunning(true);
|
this->isRunning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameInternal::handleEvents()
|
void Game::handleEvents()
|
||||||
{
|
{
|
||||||
SDL_PollEvent(&event);
|
SDL_PollEvent(&event);
|
||||||
|
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case SDL_QUIT: this->setRunning(false);
|
case SDL_QUIT: this->isRunning = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -293,15 +291,15 @@ void GameInternal::handleEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameInternal::update()
|
void Game::update()
|
||||||
{
|
{
|
||||||
manager.refresh();
|
manager.refresh();
|
||||||
manager.update();
|
manager.update();
|
||||||
|
|
||||||
this->gameInstance->update(); // TODO: this might have to be split up into two update functions, before and after manager...
|
engine::update(); // TODO: this might have to be split up into two update functions, before and after manager...
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameInternal::render()
|
void Game::render()
|
||||||
{
|
{
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
for (auto& t : tiles)
|
for (auto& t : tiles)
|
||||||
@ -312,7 +310,7 @@ void GameInternal::render()
|
|||||||
|
|
||||||
for (auto& p : players)
|
for (auto& p : players)
|
||||||
p->draw();
|
p->draw();
|
||||||
|
|
||||||
for (auto& p : projectiles)
|
for (auto& p : projectiles)
|
||||||
p->draw();
|
p->draw();
|
||||||
|
|
||||||
@ -322,7 +320,7 @@ void GameInternal::render()
|
|||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameInternal::clean()
|
void Game::clean()
|
||||||
{
|
{
|
||||||
delete(textureManager);
|
delete(textureManager);
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
@ -331,23 +329,18 @@ void GameInternal::clean()
|
|||||||
std::cout << "Game Cleaned!" << std::endl;
|
std::cout << "Game Cleaned!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameInternal::isRunning() const
|
bool Game::running() const
|
||||||
{
|
{
|
||||||
return running;
|
return isRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameInternal::setRunning(bool running)
|
void Game::setWinner(Entity::TeamLabel winningTeam)
|
||||||
{
|
|
||||||
this->running = running;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameInternal::setWinner(Entity::TeamLabel winningTeam)
|
|
||||||
{
|
{
|
||||||
this->winner = winningTeam;
|
this->winner = winningTeam;
|
||||||
this->setRunning(false);
|
this->isRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity::TeamLabel GameInternal::getWinner() const
|
Entity::TeamLabel Game::getWinner() const
|
||||||
{
|
{
|
||||||
return this->winner;
|
return this->winner;
|
||||||
}
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "SDL_error.h"
|
#include "SDL_error.h"
|
||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
|
|
||||||
GameObject::GameObject(const char* texturesheet, int x, int y)
|
GameObject::GameObject(const char* texturesheet, int x, int y)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
|
|
||||||
|
#include "Components.h"
|
||||||
#include "Direction.h"
|
#include "Direction.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
void HealthComponent::init()
|
void HealthComponent::init()
|
||||||
@ -57,7 +58,7 @@ void HealthComponent::createHeartComponents(int x)
|
|||||||
{
|
{
|
||||||
auto& heart(this->entity->getManager().addEntity());
|
auto& heart(this->entity->getManager().addEntity());
|
||||||
heart.addComponent<TransformComponent>(x,5,2);
|
heart.addComponent<TransformComponent>(x,5,2);
|
||||||
heart.addComponent<SpriteComponent>(this->healthTexture.data());
|
heart.addComponent<SpriteComponent>("assets/heart.png");
|
||||||
heart.addGroup((size_t)Entity::GroupLabel::HEARTS);
|
heart.addGroup((size_t)Entity::GroupLabel::HEARTS);
|
||||||
heart.setTeam(this->entity->getTeam());
|
heart.setTeam(this->entity->getTeam());
|
||||||
}
|
}
|
||||||
@ -1,121 +0,0 @@
|
|||||||
#include "InputComponent.h"
|
|
||||||
|
|
||||||
InputComponent::InputComponent()
|
|
||||||
{
|
|
||||||
m_keyStates = SDL_GetKeyboardState(NULL);
|
|
||||||
InitKeyMappings();
|
|
||||||
}
|
|
||||||
|
|
||||||
InputComponent::~InputComponent() = default;
|
|
||||||
|
|
||||||
void InputComponent::init()
|
|
||||||
{
|
|
||||||
// m_keyStates = SDL_GetKeyboardState(NULL);
|
|
||||||
// InitKeyMappings();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputComponent::update()
|
|
||||||
{
|
|
||||||
SDL_PumpEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool InputComponent::isKeyDown(Key key)
|
|
||||||
{
|
|
||||||
return m_keyStates[mapKeyToSDL(key)];
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Scancode InputComponent::mapKeyToSDL(Key key)
|
|
||||||
{
|
|
||||||
auto it = m_keyMappings.find(key);
|
|
||||||
if (it == m_keyMappings.end())
|
|
||||||
{
|
|
||||||
return SDL_SCANCODE_UNKNOWN;
|
|
||||||
}
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputComponent::InitKeyMappings()
|
|
||||||
{
|
|
||||||
m_keyMappings =
|
|
||||||
{
|
|
||||||
{Key::UP, SDL_SCANCODE_UP},
|
|
||||||
{Key::DOWN, SDL_SCANCODE_DOWN},
|
|
||||||
{Key::LEFT, SDL_SCANCODE_LEFT},
|
|
||||||
{Key::RIGHT, SDL_SCANCODE_RIGHT},
|
|
||||||
{Key::SPACE, SDL_SCANCODE_SPACE},
|
|
||||||
{Key::ENTER, SDL_SCANCODE_RETURN},
|
|
||||||
{Key::ESCAPE, SDL_SCANCODE_ESCAPE},
|
|
||||||
{Key::TAB, SDL_SCANCODE_TAB},
|
|
||||||
{Key::BACKSPACE, SDL_SCANCODE_BACKSPACE},
|
|
||||||
{Key::DELETE, SDL_SCANCODE_DELETE},
|
|
||||||
{Key::HOME, SDL_SCANCODE_HOME},
|
|
||||||
{Key::END, SDL_SCANCODE_END},
|
|
||||||
{Key::PAGE_UP, SDL_SCANCODE_PAGEUP},
|
|
||||||
{Key::PAGE_DOWN, SDL_SCANCODE_PAGEDOWN},
|
|
||||||
{Key::INSERT, SDL_SCANCODE_INSERT},
|
|
||||||
{Key::CAPS_LOCK, SDL_SCANCODE_CAPSLOCK},
|
|
||||||
{Key::LEFT_SHIFT, SDL_SCANCODE_LSHIFT},
|
|
||||||
{Key::RIGHT_SHIFT, SDL_SCANCODE_RSHIFT},
|
|
||||||
{Key::LEFT_CTRL, SDL_SCANCODE_LCTRL},
|
|
||||||
{Key::RIGHT_CTRL, SDL_SCANCODE_RCTRL},
|
|
||||||
{Key::LEFT_ALT, SDL_SCANCODE_LALT},
|
|
||||||
{Key::RIGHT_ALT, SDL_SCANCODE_RALT},
|
|
||||||
{Key::F1, SDL_SCANCODE_F1},
|
|
||||||
{Key::F2, SDL_SCANCODE_F2},
|
|
||||||
{Key::F3, SDL_SCANCODE_F3},
|
|
||||||
{Key::F4, SDL_SCANCODE_F4},
|
|
||||||
{Key::F5, SDL_SCANCODE_F5},
|
|
||||||
{Key::F6, SDL_SCANCODE_F6},
|
|
||||||
{Key::F7, SDL_SCANCODE_F7},
|
|
||||||
{Key::F8, SDL_SCANCODE_F8},
|
|
||||||
{Key::F9, SDL_SCANCODE_F9},
|
|
||||||
{Key::F10, SDL_SCANCODE_F10},
|
|
||||||
{Key::F11, SDL_SCANCODE_F11},
|
|
||||||
{Key::F12, SDL_SCANCODE_F12},
|
|
||||||
{Key::A, SDL_SCANCODE_A},
|
|
||||||
{Key::B, SDL_SCANCODE_B},
|
|
||||||
{Key::C, SDL_SCANCODE_C},
|
|
||||||
{Key::D, SDL_SCANCODE_D},
|
|
||||||
{Key::E, SDL_SCANCODE_E},
|
|
||||||
{Key::F, SDL_SCANCODE_F},
|
|
||||||
{Key::G, SDL_SCANCODE_G},
|
|
||||||
{Key::H, SDL_SCANCODE_H},
|
|
||||||
{Key::I, SDL_SCANCODE_I},
|
|
||||||
{Key::J, SDL_SCANCODE_J},
|
|
||||||
{Key::K, SDL_SCANCODE_K},
|
|
||||||
{Key::L, SDL_SCANCODE_L},
|
|
||||||
{Key::M, SDL_SCANCODE_M},
|
|
||||||
{Key::N, SDL_SCANCODE_N},
|
|
||||||
{Key::O, SDL_SCANCODE_O},
|
|
||||||
{Key::P, SDL_SCANCODE_P},
|
|
||||||
{Key::Q, SDL_SCANCODE_Q},
|
|
||||||
{Key::R, SDL_SCANCODE_R},
|
|
||||||
{Key::S, SDL_SCANCODE_S},
|
|
||||||
{Key::T, SDL_SCANCODE_T},
|
|
||||||
{Key::U, SDL_SCANCODE_U},
|
|
||||||
{Key::V, SDL_SCANCODE_V},
|
|
||||||
{Key::W, SDL_SCANCODE_W},
|
|
||||||
{Key::X, SDL_SCANCODE_X},
|
|
||||||
{Key::Y, SDL_SCANCODE_Y},
|
|
||||||
{Key::Z, SDL_SCANCODE_Z},
|
|
||||||
{Key::NUM_0, SDL_SCANCODE_0},
|
|
||||||
{Key::NUM_1, SDL_SCANCODE_1},
|
|
||||||
{Key::NUM_2, SDL_SCANCODE_2},
|
|
||||||
{Key::NUM_3, SDL_SCANCODE_3},
|
|
||||||
{Key::NUM_4, SDL_SCANCODE_4},
|
|
||||||
{Key::NUM_5, SDL_SCANCODE_5},
|
|
||||||
{Key::NUM_6, SDL_SCANCODE_6},
|
|
||||||
{Key::NUM_7, SDL_SCANCODE_7},
|
|
||||||
{Key::NUM_8, SDL_SCANCODE_8},
|
|
||||||
{Key::NUM_9, SDL_SCANCODE_9},
|
|
||||||
{Key::LEFT_BRACKET, SDL_SCANCODE_LEFTBRACKET},
|
|
||||||
{Key::RIGHT_BRACKET, SDL_SCANCODE_RIGHTBRACKET},
|
|
||||||
{Key::SEMICOLON, SDL_SCANCODE_SEMICOLON},
|
|
||||||
{Key::APOSTROPHE, SDL_SCANCODE_APOSTROPHE},
|
|
||||||
{Key::COMMA, SDL_SCANCODE_COMMA},
|
|
||||||
{Key::PERIOD, SDL_SCANCODE_PERIOD},
|
|
||||||
{Key::SLASH, SDL_SCANCODE_SLASH},
|
|
||||||
{Key::BACKSLASH, SDL_SCANCODE_BACKSLASH},
|
|
||||||
{Key::GRAVE, SDL_SCANCODE_GRAVE}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
85
src/KeyboardController.cpp
Normal file
85
src/KeyboardController.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#include "KeyboardController.h"
|
||||||
|
|
||||||
|
#include "Game.h"
|
||||||
|
#include "Components.h"
|
||||||
|
#include "AssetManager.h"
|
||||||
|
#include "SpriteComponent.h"
|
||||||
|
|
||||||
|
KeyboardController::KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity)
|
||||||
|
{
|
||||||
|
this->up = up;
|
||||||
|
this->down = down;
|
||||||
|
this->left = left;
|
||||||
|
this->right = right;
|
||||||
|
this->fire = fire;
|
||||||
|
this->fireVelocity = fireVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyboardController::init()
|
||||||
|
{
|
||||||
|
sprite = &entity->getComponent<SpriteComponent>();
|
||||||
|
transform = &entity->getComponent<TransformComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyboardController::update()
|
||||||
|
{
|
||||||
|
// TODO: move this, this is definitely the wrong place to put this but i wanted to put it somewhere to test it
|
||||||
|
SoundManager::playMusic(this->entity->getManager().getGame(), "background_music", PLAY_LOOPED, 10, 15000);
|
||||||
|
|
||||||
|
transform->direction.x = 0;
|
||||||
|
transform->direction.y = 0;
|
||||||
|
sprite->playAnimation(IDLE);
|
||||||
|
|
||||||
|
if (keystates[this->up]) {
|
||||||
|
transform->direction.y = -1;
|
||||||
|
sprite->playAnimation(WALK);
|
||||||
|
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1);
|
||||||
|
}
|
||||||
|
if (keystates[this->left]) {
|
||||||
|
transform->direction.x = -1;
|
||||||
|
sprite->playAnimation(WALK);
|
||||||
|
sprite->setDirection(Direction::LEFT);
|
||||||
|
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1);
|
||||||
|
}
|
||||||
|
if (keystates[this->down]) {
|
||||||
|
transform->direction.y = 1;
|
||||||
|
sprite->playAnimation(WALK);
|
||||||
|
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1);
|
||||||
|
}
|
||||||
|
if (keystates[this->right]) {
|
||||||
|
transform->direction.x = 1;
|
||||||
|
sprite->playAnimation(WALK);
|
||||||
|
sprite->setDirection(Direction::RIGHT);
|
||||||
|
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keystates[this->fire]) {
|
||||||
|
|
||||||
|
Uint32 currentTicks = SDL_GetTicks();
|
||||||
|
|
||||||
|
if (currentTicks - lastFireTime >= fireCooldown) {
|
||||||
|
|
||||||
|
player = &entity->getComponent<TransformComponent>();
|
||||||
|
|
||||||
|
//checks player source via the firing velocity
|
||||||
|
//TODO: adding actual projectile textures
|
||||||
|
if (fireVelocity.x > 0) {
|
||||||
|
sprite->setDirection(Direction::RIGHT);
|
||||||
|
this->entity->getManager().getGame()->assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity,
|
||||||
|
1, 180, 2, "assets/egg.png", this->entity->getTeam());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sprite->setDirection(Direction::LEFT);
|
||||||
|
this->entity->getManager().getGame()->assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity,
|
||||||
|
1, 180, 2, "assets/egg.png", this->entity->getTeam());
|
||||||
|
}
|
||||||
|
|
||||||
|
lastFireTime = currentTicks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyboardController::modifyAtkSpeed(int8_t modifier)
|
||||||
|
{
|
||||||
|
this->fireCooldown -= modifier * 400;
|
||||||
|
}
|
||||||
@ -6,11 +6,11 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
#include "SDL_error.h"
|
#include "SDL_error.h"
|
||||||
#include "TileComponent.h"
|
#include "TileComponent.h"
|
||||||
|
|
||||||
void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */)
|
void Map::loadMap(const char* path, int sizeX, int sizeY, Game* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */)
|
||||||
{
|
{
|
||||||
std::string tileIDstr;
|
std::string tileIDstr;
|
||||||
char singleChar = 0;
|
char singleChar = 0;
|
||||||
@ -56,7 +56,7 @@ void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, co
|
|||||||
mapFile.close();
|
mapFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict) // tile entity
|
void Map::addTile(unsigned long id, int x, int y, Game* game, const std::map<int, std::pair<std::string, bool>>* textureDict) // tile entity
|
||||||
{
|
{
|
||||||
auto& tile(game->manager.addEntity());
|
auto& tile(game->manager.addEntity());
|
||||||
tile.addComponent<TileComponent>(x, y, TILE_SIZE, TILE_SIZE, id, textureDict);
|
tile.addComponent<TileComponent>(x, y, TILE_SIZE, TILE_SIZE, id, textureDict);
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "PopupWindow.h"
|
#include "PopupWindow.h"
|
||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
|
|
||||||
PopupWindow::PopupWindow(const char* title, const std::string &message) :
|
PopupWindow::PopupWindow(const char* title, const std::string &message) :
|
||||||
continueGame(false), interacted(false) {
|
continueGame(false), interacted(false) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#include "PowerupComponent.h"
|
#include "PowerupComponent.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
#include "CollisionHandler.h"
|
#include "CollisionHandler.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
#include "ProjectileComponent.h"
|
#include "ProjectileComponent.h"
|
||||||
|
|
||||||
#include "CollisionHandler.h"
|
#include "CollisionHandler.h"
|
||||||
#include "SoundManager.h"
|
#include "Components.h"
|
||||||
#include "TransformComponent.h"
|
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
#include "AssetManager.h"
|
#include "AssetManager.h"
|
||||||
|
|
||||||
Mix_Music* SoundManager::loadMusic(const char* fileName)
|
Mix_Music* SoundManager::loadMusic(const char* fileName)
|
||||||
@ -48,7 +48,7 @@ Mix_Chunk* SoundManager::loadSound(const char* fileName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: using a string here is probably... a less than stellar method, figure out how to change this
|
// TODO: using a string here is probably... a less than stellar method, figure out how to change this
|
||||||
void SoundManager::playSound(GameInternal* game, std::string sound, bool canOverlap, int loops, int volume, int channel)
|
void SoundManager::playSound(Game* game, std::string sound, bool canOverlap, int loops, int volume, int channel)
|
||||||
{
|
{
|
||||||
if(!canOverlap)
|
if(!canOverlap)
|
||||||
{
|
{
|
||||||
@ -67,7 +67,7 @@ void SoundManager::playSound(GameInternal* game, std::string sound, bool canOver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::playMusic(GameInternal* game, std::string music, int loops, int volume, int ms)
|
void SoundManager::playMusic(Game* game, std::string music, int loops, int volume, int ms)
|
||||||
{
|
{
|
||||||
if (Mix_PlayingMusic() != 0 || Mix_Fading() == Mix_Fading::MIX_FADING_IN)
|
if (Mix_PlayingMusic() != 0 || Mix_Fading() == Mix_Fading::MIX_FADING_IN)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "TransformComponent.h"
|
#include "TransformComponent.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
|
|
||||||
SpriteComponent::SpriteComponent(const char* path)
|
SpriteComponent::SpriteComponent(const char* path)
|
||||||
@ -17,17 +17,14 @@ SpriteComponent::SpriteComponent(const char* path)
|
|||||||
this->texturePath = path;
|
this->texturePath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteComponent::SpriteComponent(
|
SpriteComponent::SpriteComponent(const char* path, bool isAnimated)
|
||||||
const char* path,
|
|
||||||
bool isAnimated,
|
|
||||||
std::map<std::string, std::unique_ptr<Animation>>* animationMap,
|
|
||||||
std::string defaultAnimation)
|
|
||||||
{
|
{
|
||||||
animated = isAnimated;
|
animated = isAnimated;
|
||||||
|
|
||||||
animations = animationMap;
|
animations.emplace(IDLE, std::make_unique<Animation>((uint8_t)AnimationType::IDLE, 2, 200));
|
||||||
|
animations.emplace(WALK, std::make_unique<Animation>((uint8_t)AnimationType::WALK, 2, 200));
|
||||||
|
|
||||||
playAnimation(defaultAnimation);
|
playAnimation(IDLE);
|
||||||
|
|
||||||
this->texturePath = path;
|
this->texturePath = path;
|
||||||
}
|
}
|
||||||
@ -74,14 +71,14 @@ void SpriteComponent::draw()
|
|||||||
this->entity->getManager().getGame()->textureManager->draw(this->entity->getManager().getGame()->renderer, this->texture, this->srcRect, this->destRect, this->animated && this->flipped);
|
this->entity->getManager().getGame()->textureManager->draw(this->entity->getManager().getGame()->renderer, this->texture, this->srcRect, this->destRect, this->animated && this->flipped);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteComponent::playAnimation(std::string type)
|
void SpriteComponent::playAnimation(AnimationType type)
|
||||||
{
|
{
|
||||||
this->animationIndex = animations->at(type)->index;
|
this->animationIndex = animations.at(type)->index;
|
||||||
this->frames = animations->at(type)->frames;
|
this->frames = animations.at(type)->frames;
|
||||||
this->speed = animations->at(type)->speed;
|
this->speed = animations.at(type)->speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteComponent::setDirection(Direction direction)
|
void SpriteComponent::setDirection(Direction direction)
|
||||||
{
|
{
|
||||||
this->flipped = direction == Direction::RIGHT;
|
this->flipped = direction == Direction::RIGHT;
|
||||||
}
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#include "StatEffectsComponent.h"
|
#include "StatEffectsComponent.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "TransformComponent.h"
|
#include "TransformComponent.h"
|
||||||
// #include "KeyboardController.h"
|
#include "KeyboardController.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -15,15 +15,15 @@ void StatEffectsComponent::update()
|
|||||||
if (this->buffs.at(i) == 0) continue;
|
if (this->buffs.at(i) == 0) continue;
|
||||||
if (this->buffs.at(i) - 1 == 0)
|
if (this->buffs.at(i) - 1 == 0)
|
||||||
{
|
{
|
||||||
this->resetStatValue((Stats)i);
|
this->modifyStatValue((Stats)i, BUFF_VALUE * -1);
|
||||||
}
|
}
|
||||||
this->buffs.at(i) -= 1;
|
this->buffs.at(i) -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatEffectsComponent::modifyStatDur(Stats stat, int duration, int value)
|
void StatEffectsComponent::modifyStatDur(Stats stat, int duration)
|
||||||
{
|
{
|
||||||
if(this->buffs.at((uint8_t)stat) == 0) this->modifyStatValue(stat, value);
|
if(this->buffs.at((uint8_t)stat) == 0) this->modifyStatValue(stat, BUFF_VALUE);
|
||||||
this->buffs.at((uint8_t)stat) += duration;
|
this->buffs.at((uint8_t)stat) += duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,21 +35,7 @@ void StatEffectsComponent::modifyStatValue(Stats stat, int modifier) //modifier
|
|||||||
this->entity->getComponent<TransformComponent>().modifySpeed(modifier);
|
this->entity->getComponent<TransformComponent>().modifySpeed(modifier);
|
||||||
break;
|
break;
|
||||||
case Stats::ATTACK_SPEED:
|
case Stats::ATTACK_SPEED:
|
||||||
// this->entity->getComponent<KeyboardController>().modifyAtkSpeed(modifier);
|
this->entity->getComponent<KeyboardController>().modifyAtkSpeed(modifier);
|
||||||
break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void StatEffectsComponent::resetStatValue(Stats stat)
|
|
||||||
{
|
|
||||||
switch (stat)
|
|
||||||
{
|
|
||||||
case Stats::MOVEMENT_SPEED:
|
|
||||||
this->entity->getComponent<TransformComponent>().resetSpeedMod();
|
|
||||||
break;
|
|
||||||
case Stats::ATTACK_SPEED:
|
|
||||||
// this->entity->getComponent<KeyboardController>().resetAtkSpeedMod();
|
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
|
|
||||||
SDL_Texture* TextureManager::loadTexture(const char* fileName)
|
SDL_Texture* TextureManager::loadTexture(const char* fileName)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include "ColliderComponent.h"
|
#include "ColliderComponent.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
@ -56,8 +56,8 @@ 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°
|
float multiplier = direction.x != 0 && direction.y != 0 ? 0.707 : 1; // normalizes vector; only works if directions are in increments of 45°
|
||||||
Vector2D positionChange(
|
Vector2D positionChange(
|
||||||
direction.x * this->getSpeed() * multiplier,
|
direction.x * speed * multiplier,
|
||||||
direction.y * this->getSpeed() * multiplier
|
direction.y * speed * multiplier
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this->entity->hasGroup((size_t)Entity::GroupLabel::PLAYERS)){
|
if (this->entity->hasGroup((size_t)Entity::GroupLabel::PLAYERS)){
|
||||||
@ -69,7 +69,7 @@ void TransformComponent::update()
|
|||||||
|
|
||||||
void TransformComponent::modifySpeed(int8_t modifier)
|
void TransformComponent::modifySpeed(int8_t modifier)
|
||||||
{
|
{
|
||||||
this->speedMod += modifier;
|
this->speed += modifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransformComponent::setPositionAfterCollision(Vector2D& positionChange)
|
void TransformComponent::setPositionAfterCollision(Vector2D& positionChange)
|
||||||
|
|||||||
@ -2,11 +2,11 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "GameInternal.h"
|
#include "Game.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "PopupWindow.h"
|
#include "PopupWindow.h"
|
||||||
|
|
||||||
GameInternal* game = nullptr;
|
Game* game = nullptr;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
@ -18,10 +18,10 @@ int main(int argc, char* argv[])
|
|||||||
Uint32 frameStart;
|
Uint32 frameStart;
|
||||||
int frameTime;
|
int frameTime;
|
||||||
|
|
||||||
game = new GameInternal();
|
game = new Game();
|
||||||
|
|
||||||
game->init("No_Name_Chicken_Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_SIZE_WIDTH, SCREEN_SIZE_HEIGHT, false);
|
game->init("No_Name_Chicken_Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_SIZE_WIDTH, SCREEN_SIZE_HEIGHT, false);
|
||||||
while (game->isRunning()) {
|
while (game->running()) {
|
||||||
frameStart = SDL_GetTicks();
|
frameStart = SDL_GetTicks();
|
||||||
|
|
||||||
game->handleEvents();
|
game->handleEvents();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user