0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 10:13:42 +00:00

Merge branch 'powerups'

This commit is contained in:
Benedikt Galbavy 2024-01-30 16:09:25 +01:00
commit 325da0eb4c
26 changed files with 300 additions and 45 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

BIN
assets/heart_powerup.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include <stdint.h> #include <cstdint>
struct Animation struct Animation
{ {
uint8_t index; uint8_t index;

View File

@ -1,13 +1,21 @@
#include "Entity.h" #pragma once
#include <SDL_render.h> #include <SDL_render.h>
#include <SDL_mixer.h> #include <SDL_mixer.h>
#include <map> #include <map>
#include <string> #include <string>
#include "Entity.h"
class Vector2D; class Vector2D;
class Manager; class Manager;
enum class PowerupType
{
HEART,
WALKINGSPEED,
SHOOTINGSPEED
};
class AssetManager class AssetManager
{ {
public: public:
@ -16,6 +24,10 @@ public:
~AssetManager(); ~AssetManager();
void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, TeamLabel teamLabel); void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, TeamLabel teamLabel);
void createPowerup(Vector2D pos, PowerupType type);
Vector2D calculateSpawnPosition();
PowerupType calculateType();
//texture management //texture management
void addTexture(std::string id, const char* path); void addTexture(std::string id, const char* path);

View File

@ -9,7 +9,8 @@ constexpr int CHARACTER_COUNT = 4;
constexpr std::size_t MAX_COMPONENTS = 32; constexpr std::size_t MAX_COMPONENTS = 32;
constexpr std::size_t MAX_GROUPS = 32; constexpr std::size_t MAX_GROUPS = 32;
constexpr std::size_t MAX_TEAMS = 8; // constexpr std::size_t MAX_STATS = 8;
constexpr std::size_t MAX_TEAMS = 8;
constexpr int SCREEN_SIZE_HEIGHT = 640; constexpr int SCREEN_SIZE_HEIGHT = 640;
constexpr int SCREEN_SIZE_WIDTH = 800; constexpr int SCREEN_SIZE_WIDTH = 800;
@ -20,3 +21,10 @@ constexpr int TILE_SIZE = 32;
constexpr int MAP_SIZE_X = 25; constexpr int MAP_SIZE_X = 25;
constexpr int MAP_SIZE_Y = 20; constexpr int MAP_SIZE_Y = 20;
constexpr int SPAWN_ATTEMPTS = 20;
constexpr int BUFF_DURATION = 6000;
constexpr int BUFF_VALUE = 1;

View File

@ -23,7 +23,8 @@ enum class GroupLabel
ENEMIES, ENEMIES,
COLLIDERS, COLLIDERS,
PROJECTILE, PROJECTILE,
HEARTS HEARTS,
POWERUPS
}; };
enum class TeamLabel enum class TeamLabel

View File

@ -3,6 +3,7 @@
#include "Component.h" #include "Component.h"
#include "Vector2D.h" #include "Vector2D.h"
#include "Constants.h"
#include "SoundManager.h" #include "SoundManager.h"
class TransformComponent; class TransformComponent;
@ -23,8 +24,8 @@ public:
//for attack cooldown in between shots //for attack cooldown in between shots
uint32_t lastFireTime = 0; uint32_t lastFireTime = 0;
uint32_t fireCooldown = 800; //in ms can be adjusted to change possible attack-speed uint32_t fireCooldown = 1000; //in ms can be adjusted to change possible attack-speed
KeyboardController() = default; KeyboardController() = default;
KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity); KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity);
~KeyboardController() = default; ~KeyboardController() = default;
@ -32,6 +33,8 @@ public:
void init() override; void init() override;
void update() override; void update() override;
void modifyAtkSpeed(int8_t modifier);
private: private:
//for creation of projectiles //for creation of projectiles
TransformComponent* player; //for starting position of projectile TransformComponent* player; //for starting position of projectile

View File

@ -0,0 +1,19 @@
#pragma once
#include "Component.h"
#include "AssetManager.h"
class PowerupComponent : public Component
{
public:
PowerupComponent(PowerupType type);
~PowerupComponent() {};
void update() override;
void heartEffect(Entity* player);
void movementSpeedEffect(Entity* player);
void atkSpeedEffect(Entity* player);
private:
void (PowerupComponent::*pickupFunc)(Entity* player);
};

View File

@ -2,6 +2,7 @@
#include "Component.h" #include "Component.h"
#include "Vector2D.h" #include "Vector2D.h"
#include "Constants.h"
class TransformComponent; class TransformComponent;

View File

@ -0,0 +1,27 @@
#pragma once
#include "Component.h"
#include "Constants.h"
#include <cstdint>
#include <array>
enum class Stats
{
MOVEMENT_SPEED,
ATTACK_SPEED
};
class StatEffectsComponent : public Component{
public:
StatEffectsComponent() {};
~StatEffectsComponent() {};
void init() override;
void update() override;
void modifyStatDur(Stats stat, uint8_t duration);
void modifyStatValue(Stats stat, int modifier);
private:
std::array<int8_t, MAX_STATS> buffs = { 0 };
};

View File

@ -2,15 +2,23 @@
#include <map> #include <map>
#include <string> #include <string>
#include "AssetManager.h"
class TextureDict class TextureDict
{ {
public: public:
const std::map<int, std::string> textureDictionary = { const std::map<int, std::string> tileDictionary = {
{1, "assets/water.png"}, {1, "assets/water.png"},
{2, "assets/dirt.png"}, {2, "assets/dirt.png"},
{3, "assets/grass.png"}, {3, "assets/grass.png"},
{7, "assets/grass_water_left.png"}, {7, "assets/grass_water_left.png"},
{9, "assets/grass_water_right.png"} {9, "assets/grass_water_right.png"}
}; };
std::map<PowerupType, std::string> powerupDictionary = {
{PowerupType::HEART, "assets/heart_powerup.png"},
{PowerupType::WALKINGSPEED, "assets/movement_speed_powerup.png"},
{PowerupType::SHOOTINGSPEED, "assets/atk_speed_powerup.png"}
};
}; };

View File

@ -2,15 +2,10 @@
#include <SDL_render.h> #include <SDL_render.h>
#include <map> #include <map>
#include <memory>
#include <string>
#include <vector> #include <vector>
struct cmp_str
{
bool operator()(char const *a, char const *b) const {
return strcmp(a, b) < 0;
}
};
class TextureManager class TextureManager
{ {
public: public:
@ -21,7 +16,7 @@ class TextureManager
} }
} }
std::map<const char*, SDL_Texture*, cmp_str> texture_cache; std::map<std::string, SDL_Texture*> texture_cache;
SDL_Texture* loadTexture(const char* fileName); SDL_Texture* loadTexture(const char* fileName);
static std::vector<SDL_Rect> splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet); static std::vector<SDL_Rect> splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet);

View File

@ -2,6 +2,7 @@
#include "Component.h" #include "Component.h"
#include "Vector2D.h" #include "Vector2D.h"
#include "Constants.h"
class TransformComponent : public Component class TransformComponent : public Component
{ {
@ -23,4 +24,5 @@ public:
void init() override; void init() override;
void update() override; void update() override;
void modifySpeed(int8_t modifier);
}; };

View File

@ -1,11 +1,21 @@
#include "AssetManager.h" #include "AssetManager.h"
#include "Entity.h"
#include "TextureManager.h" #include "TextureManager.h"
#include "SoundManager.h" #include "SoundManager.h"
#include "Components.h" #include "Components.h"
#include "Game.h" #include "Game.h"
#include "TransformComponent.h"
#include "CollisionHandler.h"
#include "ColliderComponent.h"
#include "Constants.h"
#include "Entity.h"
#include "Game.h"
#include "Vector2D.h"
#include "PowerupComponent.h"
#include <iostream>
AssetManager::AssetManager(Manager* manager) : man(manager) {} AssetManager::AssetManager(Manager* manager) : man(manager) {}
AssetManager::~AssetManager() {} AssetManager::~AssetManager() {}
@ -36,4 +46,57 @@ void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale,
projectile.addComponent<ColliderComponent>("projectile", 0.6f); projectile.addComponent<ColliderComponent>("projectile", 0.6f);
projectile.addGroup((size_t)GroupLabel::PROJECTILE); projectile.addGroup((size_t)GroupLabel::PROJECTILE);
projectile.setTeam(teamLabel); projectile.setTeam(teamLabel);
}
void AssetManager::createPowerup(Vector2D pos, PowerupType type) {
TextureDict textureDict;
auto& powerups(man->addEntity());
powerups.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, 1); //32x32 is standard size for objects
auto it = textureDict.powerupDictionary.find(type);
if (it == textureDict.powerupDictionary.end()) {
std::cout << "it end" << std::endl;
}
try {
powerups.addComponent<SpriteComponent>(it->second.data());
}
catch (std::runtime_error e) {
std::cout << e.what() << std::endl;
}
powerups.addComponent<ColliderComponent>("powerup", 0.6f);
powerups.addComponent<PowerupComponent>(type);
powerups.addGroup((size_t)GroupLabel::POWERUPS);
}
Vector2D AssetManager::calculateSpawnPosition()
{
Vector2D spawnPos = Vector2D(-1, -1);
bool conflict = false;
for (int i = 0; i <= SPAWN_ATTEMPTS; i++)
{
SDL_Rect spawnRect;
spawnRect.h = spawnRect.w = 32;
spawnRect.x = rand() % (SCREEN_SIZE_WIDTH - spawnRect.w);
spawnRect.y = rand() % (SCREEN_SIZE_HEIGHT - spawnRect.h);
conflict = false;
for (auto cc : Game::collisionHandler->getColliders({ GroupLabel::MAPTILES }))
{
if (SDL_HasIntersection(&spawnRect, &cc->collider) && strcmp(cc->tag, "projectile"))
{
conflict = true;
break;
}
}
if (conflict) continue;
spawnPos = Vector2D(spawnRect.x, spawnRect.y);
}
return spawnPos;
}
PowerupType AssetManager::calculateType()
{
PowerupType type = PowerupType(rand() % 3);
return type;
} }

View File

@ -10,6 +10,7 @@
#include "HealthComponent.h" #include "HealthComponent.h"
#include "Map.h" #include "Map.h"
#include "TextureManager.h" #include "TextureManager.h"
#include "StatEffectsComponent.h"
#include "Constants.h" #include "Constants.h"
Map* map; Map* map;
@ -29,7 +30,6 @@ auto& player1(manager.addEntity());
auto& player2(manager.addEntity()); auto& player2(manager.addEntity());
auto& wall(manager.addEntity()); auto& wall(manager.addEntity());
//auto& projectile (manager.addEntity());
Game::Game() = default; Game::Game() = default;
@ -153,18 +153,20 @@ void Game::init(const char* title, int xpos, int ypos, int width, int height, bo
player1.setTeam(TeamLabel::BLUE); player1.setTeam(TeamLabel::BLUE);
player1.addComponent<TransformComponent>(80,80,2); //posx, posy, scale player1.addComponent<TransformComponent>(80,80,2); //posx, posy, scale
player1.addComponent<SpriteComponent>("assets/chicken_knight_spritesheet.png", true); //adds sprite (32x32px), path needed player1.addComponent<SpriteComponent>("assets/chicken_knight_spritesheet.png", 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(1, 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); player1.addComponent<HealthComponent>(5, Direction::LEFT);
player1.addComponent<StatEffectsComponent>();
player1.addGroup((size_t) GroupLabel::PLAYERS); //tell programm what group it belongs to for rendering order player1.addGroup((size_t) GroupLabel::PLAYERS); //tell programm what group it belongs to for rendering order
player2.setTeam(TeamLabel::RED); player2.setTeam(TeamLabel::RED);
player2.addComponent<TransformComponent>(600, 500, 2); player2.addComponent<TransformComponent>(600, 500, 2);
player2.addComponent<SpriteComponent>("assets/chicken_spritesheet.png", true); player2.addComponent<SpriteComponent>("assets/chicken_spritesheet.png", true);
player2.addComponent<KeyboardController>(SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_RCTRL, Vector2D(-1, 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); player2.addComponent<HealthComponent>(5, Direction::RIGHT);
player2.addComponent<StatEffectsComponent>();
player2.addGroup((size_t) GroupLabel::PLAYERS); player2.addGroup((size_t) GroupLabel::PLAYERS);
} }
@ -269,6 +271,7 @@ auto& tiles(manager.getGroup((size_t)GroupLabel::MAPTILES));
auto& players(manager.getGroup((size_t)GroupLabel::PLAYERS)); auto& players(manager.getGroup((size_t)GroupLabel::PLAYERS));
auto& projectiles(manager.getGroup((size_t)GroupLabel::PROJECTILE)); auto& projectiles(manager.getGroup((size_t)GroupLabel::PROJECTILE));
auto& hearts(manager.getGroup((size_t)GroupLabel::HEARTS)); auto& hearts(manager.getGroup((size_t)GroupLabel::HEARTS));
auto& powerups(manager.getGroup((size_t)GroupLabel::POWERUPS));
void Game::handleEvents() void Game::handleEvents()
{ {
@ -289,9 +292,16 @@ void Game::update()
Vector2D playerPos = player1.getComponent<TransformComponent>().position; Vector2D playerPos = player1.getComponent<TransformComponent>().position;
Vector2D enemyPos = player2.getComponent<TransformComponent>().position; Vector2D enemyPos = player2.getComponent<TransformComponent>().position;
int powerupSpawn = rand() % 500;
manager.refresh(); manager.refresh();
manager.update(); manager.update();
if (powerupSpawn == 0)
{
assets->createPowerup(assets->calculateSpawnPosition(), assets->calculateType());
}
// needs to be in game.cpp to have access to internal functions // needs to be in game.cpp to have access to internal functions
for (auto& player : manager.getGroup((size_t) GroupLabel::PLAYERS)) { for (auto& player : manager.getGroup((size_t) GroupLabel::PLAYERS)) {
if (player->getComponent<HealthComponent>().getHealth() <= 0) { if (player->getComponent<HealthComponent>().getHealth() <= 0) {
@ -304,13 +314,14 @@ void Game::render()
{ {
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
for (auto& t : tiles) for (auto& t : tiles)
{
t->draw(); t->draw();
}
for (auto& p : players) for (auto& p : powerups)
{
p->draw(); p->draw();
}
for (auto& p : players)
p->draw();
for (auto& p : projectiles) for (auto& p : projectiles)
p->draw(); p->draw();

View File

@ -63,15 +63,20 @@ void KeyboardController::update()
if (fireVelocity.x > 0) { if (fireVelocity.x > 0) {
sprite->setDirection(Direction::RIGHT); sprite->setDirection(Direction::RIGHT);
Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity, Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity,
1, 180, 1, "assets/egg.png", this->entity->getTeam()); 1, 180, 2, "assets/egg.png", this->entity->getTeam());
} }
else { else {
sprite->setDirection(Direction::LEFT); sprite->setDirection(Direction::LEFT);
Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity, Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity,
1, 180, 1, "assets/egg.png", this->entity->getTeam()); 1, 180, 2, "assets/egg.png", this->entity->getTeam());
} }
lastFireTime = currentTicks; lastFireTime = currentTicks;
} }
} }
}
void KeyboardController::modifyAtkSpeed(int8_t modifier)
{
this->fireCooldown -= modifier * 400;
} }

57
src/PowerupComponent.cpp Normal file
View File

@ -0,0 +1,57 @@
#include "PowerupComponent.h"
#include "Game.h"
#include "CollisionHandler.h"
#include "Entity.h"
#include "HealthComponent.h"
#include "StatEffectsComponent.h"
#include "Constants.h"
#include <cstdint>
PowerupComponent::PowerupComponent(PowerupType type)
{
switch (type)
{
case PowerupType::HEART:
this->pickupFunc = (&PowerupComponent::heartEffect);
break;
case PowerupType::WALKINGSPEED:
this->pickupFunc = (&PowerupComponent::movementSpeedEffect);
break;
case PowerupType::SHOOTINGSPEED:
this->pickupFunc = (&PowerupComponent::atkSpeedEffect);
break;
default:
break;
}
}
void PowerupComponent::update()
{
Entity* player;
if ((player = Game::collisionHandler->getAnyIntersection<Entity*>(
entity,
Vector2D(0, 0),
{ GroupLabel::PLAYERS },
{},
true)) != nullptr)
{
(this->*pickupFunc)(player);
this->entity->destroy();
}
}
void PowerupComponent::heartEffect(Entity* player)
{
if(player->getComponent<HealthComponent>().getHealth() < 5)
player->getComponent<HealthComponent>().modifyHealth(1);
}
void PowerupComponent::movementSpeedEffect(Entity* player)
{
player->getComponent<StatEffectsComponent>().modifyStatDur(Stats::MOVEMENT_SPEED, (uint8_t) BUFF_DURATION);
}
void PowerupComponent::atkSpeedEffect(Entity* player)
{
player->getComponent<StatEffectsComponent>().modifyStatDur(Stats::ATTACK_SPEED, (uint8_t) BUFF_DURATION);
}

View File

@ -76,10 +76,5 @@ void SpriteComponent::playAnimation(AnimationType type)
void SpriteComponent::setDirection(Direction direction) void SpriteComponent::setDirection(Direction direction)
{ {
if (direction == Direction::RIGHT) { this->flipped = direction == Direction::RIGHT;
this->flipped = true;
return;
}
this->flipped = false;
} }

View File

@ -0,0 +1,42 @@
#include "StatEffectsComponent.h"
#include "Entity.h"
#include "TransformComponent.h"
#include "KeyboardController.h"
#include <algorithm>
#include <iostream>
void StatEffectsComponent::init()
{}
void StatEffectsComponent::update()
{
for (int i = 0; i < MAX_STATS; i++)
{
if (this->buffs.at(i) == 0) continue;
if (this->buffs.at(i) - 1 == 0)
{
this->modifyStatValue((Stats)i, BUFF_VALUE * -1);
}
this->buffs.at(i) -= 1;
}
}
void StatEffectsComponent::modifyStatDur(Stats stat, uint8_t duration)
{
if(this->buffs.at((uint8_t)stat) == 0) this->modifyStatValue(stat, BUFF_VALUE);
this->buffs.at((uint8_t)stat) += duration;
}
void StatEffectsComponent::modifyStatValue(Stats stat, int modifier) //modifier is basically there so the modifyfuncs in the components know if stats should be increased or decreased
{
switch (stat)
{
case Stats::MOVEMENT_SPEED:
this->entity->getComponent<TransformComponent>().modifySpeed(modifier);
break;
case Stats::ATTACK_SPEED:
this->entity->getComponent<KeyboardController>().modifyAtkSpeed(modifier);
break;
default: break;
}
}

View File

@ -1,5 +1,6 @@
#include "TextureManager.h" #include "TextureManager.h"
#include <memory>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@ -13,7 +14,7 @@ SDL_Texture* TextureManager::loadTexture(const char* fileName)
} }
auto texture = IMG_LoadTexture(Game::renderer, fileName); auto texture = IMG_LoadTexture(Game::renderer, fileName);
if (texture == NULL) throw std::runtime_error(std::string("Couldn't load texture '") + fileName + "'"); if (texture == NULL) throw std::runtime_error(std::string("Couldn't load texture '") + fileName + "'");
this->texture_cache.emplace(fileName, texture); this->texture_cache.emplace(std::string(fileName), texture);
printf("Loaded texture at '%s'\n", fileName); printf("Loaded texture at '%s'\n", fileName);
return texture; return texture;
} }

View File

@ -15,13 +15,11 @@ TileComponent::TileComponent(int x, int y, int w, int h, int id)
this->tileRect.h = h; this->tileRect.h = h;
tileID = id; tileID = id;
auto it = textureDict.textureDictionary.find(tileID); //every id has its own distinct texture (in texturedict.h) auto it = textureDict.tileDictionary.find(tileID); //every id has its own distinct texture (in texturedict.h)
if (it == textureDict.textureDictionary.end()) { if (it == textureDict.tileDictionary.end()) {
std::cout << "it end" << std::endl; std::cout << "it end" << std::endl;
return; return;
} }
bool test = it == textureDict.textureDictionary.end();
// std::cout << it->second.data() << std::endl;
this->path = it->second.data(); this->path = it->second.data();
} }

View File

@ -62,21 +62,26 @@ void TransformComponent::update()
// TODO: move to separate functions // TODO: move to separate functions
if (this->entity->hasGroup((size_t) GroupLabel::PLAYERS)) { if (this->entity->hasGroup((size_t)GroupLabel::PLAYERS)) {
IntersectionBitSet intersections = IntersectionBitSet intersections =
(CollisionHandler::getIntersectionWithBounds(entity, Vector2D(positionChange.x, 0)) | (CollisionHandler::getIntersectionWithBounds(entity, Vector2D(positionChange.x, 0)) |
(Game::collisionHandler->getAnyIntersection<IntersectionBitSet>(entity, Vector2D(positionChange.x, 0), {GroupLabel::MAPTILES, GroupLabel::COLLIDERS})) & (Game::collisionHandler->getAnyIntersection<IntersectionBitSet>(entity, Vector2D(positionChange.x, 0), { GroupLabel::MAPTILES, GroupLabel::COLLIDERS })) &
IntersectionBitSet("0011")) | IntersectionBitSet("0011")) |
(CollisionHandler::getIntersectionWithBounds(entity, Vector2D(0, positionChange.y)) | (CollisionHandler::getIntersectionWithBounds(entity, Vector2D(0, positionChange.y)) |
(Game::collisionHandler->getAnyIntersection<IntersectionBitSet>(entity, Vector2D(0, positionChange.y), {GroupLabel::MAPTILES, GroupLabel::COLLIDERS})) & (Game::collisionHandler->getAnyIntersection<IntersectionBitSet>(entity, Vector2D(0, positionChange.y), { GroupLabel::MAPTILES, GroupLabel::COLLIDERS })) &
IntersectionBitSet("1100")); IntersectionBitSet("1100"));
if (intersections.test((size_t) direction::LEFT) || intersections.test((size_t) direction::RIGHT)) if (intersections.test((size_t)direction::LEFT) || intersections.test((size_t)direction::RIGHT))
positionChange.x = 0; positionChange.x = 0;
if (intersections.test((size_t) direction::UP) || intersections.test((size_t) direction::DOWN)) if (intersections.test((size_t)direction::UP) || intersections.test((size_t)direction::DOWN))
positionChange.y = 0; positionChange.y = 0;
} }
position += positionChange; position += positionChange;
}; }
void TransformComponent::modifySpeed(int8_t modifier)
{
this->speed += modifier;
}

View File

@ -1,10 +1,12 @@
#include "Game.h" #include "Game.h"
#include "Constants.h" #include "Constants.h"
#include <ctime>
Game* game = nullptr; Game* game = nullptr;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
srand(time(NULL));
const int frameDelay = 1000 / FPS; const int frameDelay = 1000 / FPS;
Uint32 frameStart; Uint32 frameStart;