mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 22:23:43 +00:00
Compare commits
5 Commits
cebe343e4c
...
fcb79bc2a3
| Author | SHA1 | Date | |
|---|---|---|---|
| fcb79bc2a3 | |||
| 705fe069cf | |||
| 57a0bead6a | |||
| 66a59d9666 | |||
| f2d7601480 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -14,3 +14,6 @@
|
|||||||
path = extern/SDL_ttf
|
path = extern/SDL_ttf
|
||||||
url = https://github.com/libsdl-org/SDL_ttf.git
|
url = https://github.com/libsdl-org/SDL_ttf.git
|
||||||
branch = release-2.22.x
|
branch = release-2.22.x
|
||||||
|
[submodule "docs/doxygen-awesome-css"]
|
||||||
|
path = docs/doxygen-awesome-css
|
||||||
|
url = https://github.com/jothepro/doxygen-awesome-css.git
|
||||||
|
|||||||
63
Doxyfile.bak
Normal file
63
Doxyfile.bak
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# Doxyfile
|
||||||
|
|
||||||
|
# Project information
|
||||||
|
PROJECT_NAME = "SDL Minigame"
|
||||||
|
PROJECT_NUMBER = "1.0"
|
||||||
|
PROJECT_ICON = assets/chicken_neutral_knight.png
|
||||||
|
OUTPUT_DIRECTORY = docs
|
||||||
|
|
||||||
|
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||||
|
EXTRACT_ALL = NO
|
||||||
|
EXTRACT_LOCAL_CLASSES = YES
|
||||||
|
|
||||||
|
CLASS_DIAGRAMS = YES
|
||||||
|
|
||||||
|
HIDE_UNDOC_RELATIONS = YES
|
||||||
|
HAVE_DOT = YES
|
||||||
|
DOT_PATH = /usr/bin/dot
|
||||||
|
|
||||||
|
CLASS_GRAPH = YES
|
||||||
|
COLLABORATION_GRAPH = YES
|
||||||
|
UML_LOOK = YES
|
||||||
|
UML_LIMIT_NUM_FIELDS = 50
|
||||||
|
TEMPLATE_RELATIONS = YES
|
||||||
|
DOT_TRANSPARENT = YES
|
||||||
|
|
||||||
|
# Source files
|
||||||
|
INPUT = ./include ./src
|
||||||
|
FILE_PATTERNS = *.cpp *.h *.hpp
|
||||||
|
EXAMPLE_PATH = ./include ./src
|
||||||
|
EXAMPLE_PATTERNS = *.cpp *.h *.hpp
|
||||||
|
|
||||||
|
# Output formats
|
||||||
|
GENERATE_XML = YES
|
||||||
|
GENERATE_HTML = YES
|
||||||
|
DOT_IMAGE_FORMAT = SVG
|
||||||
|
COLLABORATION_GRAPH = YES
|
||||||
|
GENERATE_LATEX = NO
|
||||||
|
|
||||||
|
# Extra settings
|
||||||
|
USE_MATHJAX = YES
|
||||||
|
CALL_GRAPH = YES
|
||||||
|
CALLER_GRAPH = YES
|
||||||
|
EXTRACT_PRIVATE = YES
|
||||||
|
EXTRACT_STATIC = YES
|
||||||
|
EXTRACT_LOCAL_CLASSES = YES
|
||||||
|
EXTRACT_LOCAL_METHODS = YES
|
||||||
|
EXTRACT_ANON_NSPACES = YES
|
||||||
|
SHOW_FILES = YES
|
||||||
|
SHOW_INCLUDE_FILES = YES
|
||||||
|
SHOW_USED_FILES = YES
|
||||||
|
RECURSIVE = YES
|
||||||
|
|
||||||
|
# Class diagram options
|
||||||
|
INCLUDE_GRAPH = YES
|
||||||
|
INCLUDED_BY_GRAPH = YES
|
||||||
|
GRAPHICAL_HIERARCHY = YES
|
||||||
|
DIRECTORY_GRAPH = YES
|
||||||
|
DISABLE_INDEX = YES
|
||||||
|
GENERATE_TREEVIEW = YES
|
||||||
|
HTML_COLLABORATION = YES
|
||||||
|
|
||||||
|
# idk everything else
|
||||||
|
TAB_SIZE = 4
|
||||||
54
docs/custom.css
Normal file
54
docs/custom.css
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
html {
|
||||||
|
/* primary theme color. This will affect the entire websites color scheme: links, arrows, labels, ... */
|
||||||
|
--primary-color: #bd93f9;
|
||||||
|
--primary-dark-color: #9270e4;
|
||||||
|
--primary-light-color: #9270e4;
|
||||||
|
|
||||||
|
/* page base colors */
|
||||||
|
--page-background-color: #ffffff;
|
||||||
|
--page-foreground-color: #2f4153;
|
||||||
|
--page-secondary-foreground-color: #6f7e8e;
|
||||||
|
|
||||||
|
/* color for all separators on the website: hr, borders, ... */
|
||||||
|
--separator-color: #bd93f965;
|
||||||
|
|
||||||
|
/* border radius for all rounded components. Will affect many components, like dropdowns, memitems, codeblocks, ... */
|
||||||
|
--border-radius-large: 22px;
|
||||||
|
--border-radius-small: 9px;
|
||||||
|
--border-radius-medium: 14px;
|
||||||
|
|
||||||
|
/* default spacings. Most components reference these values for spacing, to provide uniform spacing on the page. */
|
||||||
|
--spacing-small: 8px;
|
||||||
|
--spacing-medium: 14px;
|
||||||
|
--spacing-large: 19px;
|
||||||
|
|
||||||
|
--top-height: 125px;
|
||||||
|
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
html.dark-mode {
|
||||||
|
color-scheme: dark;
|
||||||
|
|
||||||
|
--primary-color: #bd93f9;
|
||||||
|
--primary-dark-color: #9270e4;
|
||||||
|
--primary-light-color: #9270e4;
|
||||||
|
--primary-lighter-color: #191e21;
|
||||||
|
--primary-lightest-color: #191a1c;
|
||||||
|
|
||||||
|
--page-background-color: #21222c;
|
||||||
|
--page-foreground-color: #d2dbde;
|
||||||
|
--page-secondary-foreground-color: #859399;
|
||||||
|
--separator-color: #3a3246;
|
||||||
|
--side-nav-background: #282a36;
|
||||||
|
--side-nav-foreground: #f8f8f2;
|
||||||
|
--toc-background: #282A36;
|
||||||
|
--searchbar-background: var(--page-background-color);
|
||||||
|
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
.paramname em {
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--primary-dark-color);
|
||||||
|
}
|
||||||
1
docs/doxygen-awesome-css
Submodule
1
docs/doxygen-awesome-css
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit df88fe4fdd97714fadfd3ef17de0b4401f804052
|
||||||
110
docs/header.html
Normal file
110
docs/header.html
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
<!-- HTML header for doxygen 1.10.0-->
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="$langISO">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=11" />
|
||||||
|
<meta name="generator" content="Doxygen $doxygenversion" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<!--BEGIN PROJECT_NAME-->
|
||||||
|
<title>$projectname: $title</title>
|
||||||
|
<!--END PROJECT_NAME-->
|
||||||
|
<!--BEGIN !PROJECT_NAME-->
|
||||||
|
<title>$title</title>
|
||||||
|
<!--END !PROJECT_NAME-->
|
||||||
|
<!--BEGIN PROJECT_ICON-->
|
||||||
|
<link rel="icon" href="$relpath^$projecticon" type="image/x-icon" />
|
||||||
|
<!--END PROJECT_ICON-->
|
||||||
|
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css" />
|
||||||
|
<!--BEGIN DISABLE_INDEX-->
|
||||||
|
<!--BEGIN FULL_SIDEBAR-->
|
||||||
|
<script type="text/javascript">
|
||||||
|
var page_layout = 1;
|
||||||
|
</script>
|
||||||
|
<!--END FULL_SIDEBAR-->
|
||||||
|
<!--END DISABLE_INDEX-->
|
||||||
|
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
||||||
|
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
||||||
|
<!--BEGIN COPY_CLIPBOARD-->
|
||||||
|
<script type="text/javascript" src="$relpath^clipboard.js"></script>
|
||||||
|
<!--END COPY_CLIPBOARD-->
|
||||||
|
<script type="text/javascript" src="$relpath^doxygen-awesome-darkmode-toggle.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
DoxygenAwesomeDarkModeToggle.init()
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript" src="$relpath^doxygen-awesome-fragment-copy-button.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
DoxygenAwesomeFragmentCopyButton.init()
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript" src="$relpath^doxygen-awesome-paragraph-link.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
DoxygenAwesomeParagraphLink.init()
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript" src="$relpath^doxygen-awesome-interactive-toc.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
DoxygenAwesomeInteractiveToc.init()
|
||||||
|
</script>
|
||||||
|
$treeview
|
||||||
|
$search
|
||||||
|
$mathjax
|
||||||
|
$darkmode
|
||||||
|
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
||||||
|
$extrastylesheet
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<!--BEGIN DISABLE_INDEX-->
|
||||||
|
<!--BEGIN FULL_SIDEBAR-->
|
||||||
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
||||||
|
<!-- do not remove this div, it is closed by doxygen! -->
|
||||||
|
<!--END FULL_SIDEBAR-->
|
||||||
|
<!--END DISABLE_INDEX-->
|
||||||
|
<div id="top">
|
||||||
|
<!-- do not remove this div, it is closed by doxygen! -->
|
||||||
|
<!--BEGIN TITLEAREA-->
|
||||||
|
<div id="titlearea">
|
||||||
|
<table cellspacing="0" cellpadding="0">
|
||||||
|
<tbody>
|
||||||
|
<tr id="projectrow">
|
||||||
|
<!--BEGIN PROJECT_LOGO-->
|
||||||
|
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo" $logosize /></td>
|
||||||
|
<!--END PROJECT_LOGO-->
|
||||||
|
<!--BEGIN PROJECT_NAME-->
|
||||||
|
<td id="projectalign">
|
||||||
|
<div id="projectname">$projectname
|
||||||
|
<!--BEGIN PROJECT_NUMBER--><span id="projectnumber"> $projectnumber</span>
|
||||||
|
<!--END PROJECT_NUMBER-->
|
||||||
|
</div>
|
||||||
|
<!--BEGIN PROJECT_BRIEF-->
|
||||||
|
<div id="projectbrief">$projectbrief</div>
|
||||||
|
<!--END PROJECT_BRIEF-->
|
||||||
|
</td>
|
||||||
|
<!--END PROJECT_NAME-->
|
||||||
|
<!--BEGIN !PROJECT_NAME-->
|
||||||
|
<!--BEGIN PROJECT_BRIEF-->
|
||||||
|
<td>
|
||||||
|
<div id="projectbrief">$projectbrief</div>
|
||||||
|
</td>
|
||||||
|
<!--END PROJECT_BRIEF-->
|
||||||
|
<!--END !PROJECT_NAME-->
|
||||||
|
<!--BEGIN DISABLE_INDEX-->
|
||||||
|
<!--BEGIN SEARCHENGINE-->
|
||||||
|
<!--BEGIN !FULL_SIDEBAR-->
|
||||||
|
<td>$searchbox</td>
|
||||||
|
<!--END !FULL_SIDEBAR-->
|
||||||
|
<!--END SEARCHENGINE-->
|
||||||
|
<!--END DISABLE_INDEX-->
|
||||||
|
</tr>
|
||||||
|
<!--BEGIN SEARCHENGINE-->
|
||||||
|
<!--BEGIN FULL_SIDEBAR-->
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">$searchbox</td>
|
||||||
|
</tr>
|
||||||
|
<!--END FULL_SIDEBAR-->
|
||||||
|
<!--END SEARCHENGINE-->
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!--END TITLEAREA-->
|
||||||
|
<!-- end header part -->
|
||||||
@ -23,7 +23,7 @@ public:
|
|||||||
AssetManager(Manager* manager);
|
AssetManager(Manager* manager);
|
||||||
~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, Entity::TeamLabel teamLabel);
|
||||||
void createPowerup(Vector2D pos, PowerupType type);
|
void createPowerup(Vector2D pos, PowerupType type);
|
||||||
|
|
||||||
Vector2D calculateSpawnPosition();
|
Vector2D calculateSpawnPosition();
|
||||||
|
|||||||
@ -49,8 +49,8 @@ public:
|
|||||||
|
|
||||||
// temporary function, remove once game.cpp cleaned up
|
// temporary function, remove once game.cpp cleaned up
|
||||||
std::vector<ColliderComponent*> getColliders(
|
std::vector<ColliderComponent*> getColliders(
|
||||||
std::initializer_list<GroupLabel> const& groupLabels,
|
std::initializer_list<Entity::GroupLabel> const& groupLabels,
|
||||||
std::initializer_list<TeamLabel> const& teamLabels = {},
|
std::initializer_list<Entity::TeamLabel> const& teamLabels = {},
|
||||||
bool negateTeam = false);
|
bool negateTeam = false);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -64,21 +64,15 @@ public:
|
|||||||
* \param groupLabels Entities need to have at least one listed GroupLabels to get checked against
|
* \param groupLabels Entities need to have at least one listed GroupLabels to get checked against
|
||||||
* \param teamLabels Entities need to have one of the specified TeamLabels to get checked against
|
* \param teamLabels Entities need to have one of the specified TeamLabels to get checked against
|
||||||
* \param negateTeam If set to true, entities will only be checked against if they **don't** have one of the specified TeamLabels
|
* \param negateTeam If set to true, entities will only be checked against if they **don't** have one of the specified TeamLabels
|
||||||
* \see GroupLabel
|
|
||||||
* \see TeamLabel
|
|
||||||
* \see Entity
|
|
||||||
* \see ColliderComponent
|
* \see ColliderComponent
|
||||||
* \see Entity::getTeam()
|
|
||||||
* \details Example usage for IntersectionBitSet (TransformComponent::update()):
|
|
||||||
* \snippet{trimleft} TransformComponent.cpp getAnyIntersection example code
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T getAnyIntersection(
|
T getAnyIntersection(
|
||||||
Entity* entity,
|
Entity* entity,
|
||||||
Vector2D posMod = {},
|
Vector2D posMod = {},
|
||||||
std::initializer_list<GroupLabel> const& groupLabels = {},
|
std::initializer_list<Entity::GroupLabel> const& groupLabels = {},
|
||||||
std::initializer_list<TeamLabel> const& teamLabels = {},
|
std::initializer_list<Entity::TeamLabel> const& teamLabels = {},
|
||||||
bool negateTeam = false);
|
bool negateTeam = false);
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@ -16,6 +16,10 @@ using ComponentBitSet = std::bitset<MAX_COMPONENTS>;
|
|||||||
using GroupBitSet = std::bitset<MAX_GROUPS>;
|
using GroupBitSet = std::bitset<MAX_GROUPS>;
|
||||||
using ComponentArray = std::array<Component*, MAX_COMPONENTS>;
|
using ComponentArray = std::array<Component*, MAX_COMPONENTS>;
|
||||||
|
|
||||||
|
class Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
/*! TODO */
|
/*! TODO */
|
||||||
enum class GroupLabel
|
enum class GroupLabel
|
||||||
{
|
{
|
||||||
@ -30,14 +34,11 @@ enum class GroupLabel
|
|||||||
|
|
||||||
enum class TeamLabel
|
enum class TeamLabel
|
||||||
{
|
{
|
||||||
NONE,
|
NONE, //!< No team
|
||||||
BLUE,
|
BLUE, //!< Team blue
|
||||||
RED
|
RED //!< Team red
|
||||||
};
|
};
|
||||||
|
|
||||||
class Entity
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit Entity(Manager& mManager) :
|
explicit Entity(Manager& mManager) :
|
||||||
manager(mManager) { };
|
manager(mManager) { };
|
||||||
|
|
||||||
|
|||||||
@ -6,12 +6,12 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
|
#include "Entity.h"
|
||||||
|
|
||||||
class AssetManager;
|
class AssetManager;
|
||||||
class CollisionHandler;
|
class CollisionHandler;
|
||||||
class TextureManager;
|
class TextureManager;
|
||||||
class SoundManager;
|
class SoundManager;
|
||||||
enum class TeamLabel;
|
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
@ -37,13 +37,13 @@ public:
|
|||||||
static SoundManager* soundManager;
|
static SoundManager* soundManager;
|
||||||
|
|
||||||
void refreshPlayers();
|
void refreshPlayers();
|
||||||
TeamLabel getWinner() const;
|
Entity::TeamLabel getWinner() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setWinner(TeamLabel winningTeam);
|
void setWinner(Entity::TeamLabel winningTeam);
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
bool isRunning = false;
|
bool isRunning = false;
|
||||||
SDL_Window* window;
|
SDL_Window* window;
|
||||||
TeamLabel winner;
|
Entity::TeamLabel winner;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,8 +3,9 @@
|
|||||||
#include <SDL_ttf.h>
|
#include <SDL_ttf.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "Entity.h"
|
||||||
|
|
||||||
class Game;
|
class Game;
|
||||||
enum class TeamLabel;
|
|
||||||
|
|
||||||
class PopupWindow {
|
class PopupWindow {
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ public:
|
|||||||
|
|
||||||
bool interacted;
|
bool interacted;
|
||||||
|
|
||||||
void renderWinnerPopup(TeamLabel winner);
|
void renderWinnerPopup(Entity::TeamLabel winner);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Renderer* renderer;
|
SDL_Renderer* renderer;
|
||||||
|
|||||||
@ -37,14 +37,14 @@ Mix_Chunk* AssetManager::getSound(std::string id) {
|
|||||||
return soundEffects.at(id);
|
return soundEffects.at(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, TeamLabel teamLabel) {
|
void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity::TeamLabel teamLabel) {
|
||||||
|
|
||||||
auto& projectile(man->addEntity());
|
auto& projectile(man->addEntity());
|
||||||
projectile.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, scale); //32x32 is standard size for objects
|
projectile.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, scale); //32x32 is standard size for objects
|
||||||
projectile.addComponent<SpriteComponent>(texturePath);
|
projectile.addComponent<SpriteComponent>(texturePath);
|
||||||
projectile.addComponent<ProjectileComponent>(range, speed, velocity);
|
projectile.addComponent<ProjectileComponent>(range, speed, velocity);
|
||||||
projectile.addComponent<ColliderComponent>("projectile", 0.6f);
|
projectile.addComponent<ColliderComponent>("projectile", 0.6f);
|
||||||
projectile.addGroup((size_t)GroupLabel::PROJECTILE);
|
projectile.addGroup((size_t)Entity::GroupLabel::PROJECTILE);
|
||||||
projectile.setTeam(teamLabel);
|
projectile.setTeam(teamLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ void AssetManager::createPowerup(Vector2D pos, PowerupType type) {
|
|||||||
|
|
||||||
powerups.addComponent<ColliderComponent>("powerup", 0.6f);
|
powerups.addComponent<ColliderComponent>("powerup", 0.6f);
|
||||||
powerups.addComponent<PowerupComponent>(type);
|
powerups.addComponent<PowerupComponent>(type);
|
||||||
powerups.addGroup((size_t)GroupLabel::POWERUPS);
|
powerups.addGroup((size_t)Entity::GroupLabel::POWERUPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2D AssetManager::calculateSpawnPosition()
|
Vector2D AssetManager::calculateSpawnPosition()
|
||||||
@ -81,7 +81,7 @@ Vector2D AssetManager::calculateSpawnPosition()
|
|||||||
spawnRect.x = rand() % (SCREEN_SIZE_WIDTH - spawnRect.w);
|
spawnRect.x = rand() % (SCREEN_SIZE_WIDTH - spawnRect.w);
|
||||||
spawnRect.y = rand() % (SCREEN_SIZE_HEIGHT - spawnRect.h);
|
spawnRect.y = rand() % (SCREEN_SIZE_HEIGHT - spawnRect.h);
|
||||||
conflict = false;
|
conflict = false;
|
||||||
for (auto cc : Game::collisionHandler->getColliders({ GroupLabel::MAPTILES }))
|
for (auto cc : Game::collisionHandler->getColliders({ Entity::GroupLabel::MAPTILES }))
|
||||||
{
|
{
|
||||||
if (SDL_HasIntersection(&spawnRect, &cc->collider) && strcmp(cc->tag, "projectile"))
|
if (SDL_HasIntersection(&spawnRect, &cc->collider) && strcmp(cc->tag, "projectile"))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -86,8 +86,8 @@ IntersectionBitSet CollisionHandler::getIntersectionWithBounds(Entity* entity, V
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ColliderComponent*> CollisionHandler::getColliders(
|
std::vector<ColliderComponent*> CollisionHandler::getColliders(
|
||||||
std::initializer_list<GroupLabel> const& groupLabels,
|
std::initializer_list<Entity::GroupLabel> const& groupLabels,
|
||||||
std::initializer_list<TeamLabel> const& teamLabels,
|
std::initializer_list<Entity::TeamLabel> const& teamLabels,
|
||||||
bool negateTeam)
|
bool negateTeam)
|
||||||
{
|
{
|
||||||
std::vector<ColliderComponent*> colliders;
|
std::vector<ColliderComponent*> colliders;
|
||||||
@ -122,14 +122,16 @@ std::vector<ColliderComponent*> CollisionHandler::getColliders(
|
|||||||
* \see Direction
|
* \see Direction
|
||||||
* \see IntersectionBitSet
|
* \see IntersectionBitSet
|
||||||
* \snippet CollisionHandler.h IntersectionBitSet
|
* \snippet CollisionHandler.h IntersectionBitSet
|
||||||
|
* \details Example usage for IntersectionBitSet (TransformComponent::update()):
|
||||||
|
* \snippet{trimleft} TransformComponent.cpp getAnyIntersection example code
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
IntersectionBitSet CollisionHandler::getAnyIntersection<IntersectionBitSet>(
|
IntersectionBitSet CollisionHandler::getAnyIntersection<IntersectionBitSet>(
|
||||||
Entity* entity,
|
Entity* entity,
|
||||||
Vector2D posMod,
|
Vector2D posMod,
|
||||||
std::initializer_list<GroupLabel> const& groupLabels,
|
std::initializer_list<Entity::GroupLabel> const& groupLabels,
|
||||||
std::initializer_list<TeamLabel> const& teamLabels,
|
std::initializer_list<Entity::TeamLabel> const& teamLabels,
|
||||||
bool negateTeam)
|
bool negateTeam)
|
||||||
{
|
{
|
||||||
if (!entity->hasComponent<ColliderComponent>()) return std::bitset<DIRECTION_C>();
|
if (!entity->hasComponent<ColliderComponent>()) return std::bitset<DIRECTION_C>();
|
||||||
@ -151,8 +153,8 @@ template<>
|
|||||||
Entity* CollisionHandler::getAnyIntersection<Entity*>(
|
Entity* CollisionHandler::getAnyIntersection<Entity*>(
|
||||||
Entity* entity,
|
Entity* entity,
|
||||||
Vector2D posMod,
|
Vector2D posMod,
|
||||||
std::initializer_list<GroupLabel> const& groupLabels,
|
std::initializer_list<Entity::GroupLabel> const& groupLabels,
|
||||||
std::initializer_list<TeamLabel> const& teamLabels,
|
std::initializer_list<Entity::TeamLabel> const& teamLabels,
|
||||||
bool negateTeam)
|
bool negateTeam)
|
||||||
{
|
{
|
||||||
if (!entity->hasComponent<ColliderComponent>()) return nullptr;
|
if (!entity->hasComponent<ColliderComponent>()) return nullptr;
|
||||||
@ -175,8 +177,8 @@ template<>
|
|||||||
bool CollisionHandler::getAnyIntersection<bool>(
|
bool CollisionHandler::getAnyIntersection<bool>(
|
||||||
Entity* entity,
|
Entity* entity,
|
||||||
Vector2D posMod,
|
Vector2D posMod,
|
||||||
std::initializer_list<GroupLabel> const& groupLabels,
|
std::initializer_list<Entity::GroupLabel> const& groupLabels,
|
||||||
std::initializer_list<TeamLabel> const& teamLabels,
|
std::initializer_list<Entity::TeamLabel> const& teamLabels,
|
||||||
bool negateTeam)
|
bool negateTeam)
|
||||||
{
|
{
|
||||||
if (!entity->hasComponent<ColliderComponent>()) return false;
|
if (!entity->hasComponent<ColliderComponent>()) return false;
|
||||||
|
|||||||
@ -35,13 +35,13 @@ std::bitset<MAX_GROUPS> Entity::getGroupBitSet()
|
|||||||
return groupBitSet;
|
return groupBitSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::setTeam(TeamLabel teamLabel)
|
void Entity::setTeam(Entity::TeamLabel teamLabel)
|
||||||
{
|
{
|
||||||
this->teamLabel = teamLabel;
|
this->teamLabel = teamLabel;
|
||||||
manager.addToTeam(this, (size_t) teamLabel);
|
manager.addToTeam(this, (size_t) teamLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
TeamLabel Entity::getTeam()
|
Entity::TeamLabel Entity::getTeam()
|
||||||
{
|
{
|
||||||
return teamLabel;
|
return teamLabel;
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/Game.cpp
26
src/Game.cpp
@ -159,24 +159,24 @@ void Game::init(const char* title, int xpos, int ypos, int width, int height, bo
|
|||||||
|
|
||||||
//ecs implementation
|
//ecs implementation
|
||||||
|
|
||||||
player1.setTeam(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);
|
player1.addComponent<HealthComponent>(5, Direction::LEFT);
|
||||||
player1.addComponent<StatEffectsComponent>();
|
player1.addComponent<StatEffectsComponent>();
|
||||||
player1.addGroup((size_t) 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(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);
|
player2.addComponent<HealthComponent>(5, Direction::RIGHT);
|
||||||
player2.addComponent<StatEffectsComponent>();
|
player2.addComponent<StatEffectsComponent>();
|
||||||
player2.addGroup((size_t) GroupLabel::PLAYERS);
|
player2.addGroup((size_t) Entity::GroupLabel::PLAYERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::selectCharacters(const char* &playerSprite, const char* &enemySprite)
|
void Game::selectCharacters(const char* &playerSprite, const char* &enemySprite)
|
||||||
@ -275,11 +275,11 @@ void Game::selectCharacters(const char* &playerSprite, const char* &enemySprite)
|
|||||||
this->isRunning = true;
|
this->isRunning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& tiles(manager.getGroup((size_t)GroupLabel::MAPTILES));
|
auto& tiles(manager.getGroup((size_t)Entity::GroupLabel::MAPTILES));
|
||||||
auto& players(manager.getGroup((size_t)GroupLabel::PLAYERS));
|
auto& players(manager.getGroup((size_t)Entity::GroupLabel::PLAYERS));
|
||||||
auto& projectiles(manager.getGroup((size_t)GroupLabel::PROJECTILE));
|
auto& projectiles(manager.getGroup((size_t)Entity::GroupLabel::PROJECTILE));
|
||||||
auto& hearts(manager.getGroup((size_t)GroupLabel::HEARTS));
|
auto& hearts(manager.getGroup((size_t)Entity::GroupLabel::HEARTS));
|
||||||
auto& powerups(manager.getGroup((size_t)GroupLabel::POWERUPS));
|
auto& powerups(manager.getGroup((size_t)Entity::GroupLabel::POWERUPS));
|
||||||
|
|
||||||
void Game::handleEvents()
|
void Game::handleEvents()
|
||||||
{
|
{
|
||||||
@ -311,7 +311,7 @@ void Game::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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) Entity::GroupLabel::PLAYERS)) {
|
||||||
if (player->getComponent<HealthComponent>().getHealth() <= 0) {
|
if (player->getComponent<HealthComponent>().getHealth() <= 0) {
|
||||||
this->setWinner(player->getTeam());
|
this->setWinner(player->getTeam());
|
||||||
}
|
}
|
||||||
@ -353,7 +353,7 @@ void Game::addTile(unsigned long id, int x, int y)
|
|||||||
auto& tile(manager.addEntity());
|
auto& tile(manager.addEntity());
|
||||||
tile.addComponent<TileComponent>(x, y, TILE_SIZE, TILE_SIZE, id);
|
tile.addComponent<TileComponent>(x, y, TILE_SIZE, TILE_SIZE, id);
|
||||||
if (id == 1) tile.addComponent<ColliderComponent>("water");
|
if (id == 1) tile.addComponent<ColliderComponent>("water");
|
||||||
tile.addGroup((size_t)GroupLabel::MAPTILES);
|
tile.addGroup((size_t)Entity::GroupLabel::MAPTILES);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Game::running() const
|
bool Game::running() const
|
||||||
@ -361,13 +361,13 @@ bool Game::running() const
|
|||||||
return isRunning;
|
return isRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::setWinner(TeamLabel winningTeam)
|
void Game::setWinner(Entity::TeamLabel winningTeam)
|
||||||
{
|
{
|
||||||
this->winner = winningTeam;
|
this->winner = winningTeam;
|
||||||
this->isRunning = false;
|
this->isRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TeamLabel Game::getWinner() const
|
Entity::TeamLabel Game::getWinner() const
|
||||||
{
|
{
|
||||||
return this->winner;
|
return this->winner;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ void HealthComponent::setHealth(int health)
|
|||||||
void HealthComponent::refreshHearts()
|
void HealthComponent::refreshHearts()
|
||||||
{
|
{
|
||||||
// clear hearts if exist
|
// clear hearts if exist
|
||||||
for (auto& heart : this->entity->getManager().getGroup((size_t) GroupLabel::HEARTS)) {
|
for (auto& heart : this->entity->getManager().getGroup((size_t) Entity::GroupLabel::HEARTS)) {
|
||||||
if (heart->getTeam() == this->entity->getTeam()) {
|
if (heart->getTeam() == this->entity->getTeam()) {
|
||||||
heart->destroy();
|
heart->destroy();
|
||||||
}
|
}
|
||||||
@ -59,6 +59,6 @@ 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>("assets/heart.png");
|
heart.addComponent<SpriteComponent>("assets/heart.png");
|
||||||
heart.addGroup((size_t)GroupLabel::HEARTS);
|
heart.addGroup((size_t)Entity::GroupLabel::HEARTS);
|
||||||
heart.setTeam(this->entity->getTeam());
|
heart.setTeam(this->entity->getTeam());
|
||||||
}
|
}
|
||||||
@ -62,12 +62,12 @@ bool PopupWindow::shouldContinue() const {
|
|||||||
return continueGame;
|
return continueGame;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopupWindow::renderWinnerPopup(TeamLabel winner) {
|
void PopupWindow::renderWinnerPopup(Entity::TeamLabel winner) {
|
||||||
|
|
||||||
SDL_RenderClear(this->renderer);
|
SDL_RenderClear(this->renderer);
|
||||||
|
|
||||||
//Maybe use texture manager (changes need to be made that it does not use game::renderer automatically, but receives one instead)
|
//Maybe use texture manager (changes need to be made that it does not use game::renderer automatically, but receives one instead)
|
||||||
this->texture = winner == TeamLabel::BLUE ?
|
this->texture = winner == Entity::TeamLabel::BLUE ?
|
||||||
IMG_LoadTexture(this->renderer, "assets/Player1Victory.png") :
|
IMG_LoadTexture(this->renderer, "assets/Player1Victory.png") :
|
||||||
IMG_LoadTexture(this->renderer, "assets/Player2Victory.png");
|
IMG_LoadTexture(this->renderer, "assets/Player2Victory.png");
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ void PowerupComponent::update()
|
|||||||
if ((player = Game::collisionHandler->getAnyIntersection<Entity*>(
|
if ((player = Game::collisionHandler->getAnyIntersection<Entity*>(
|
||||||
entity,
|
entity,
|
||||||
Vector2D(0, 0),
|
Vector2D(0, 0),
|
||||||
{ GroupLabel::PLAYERS },
|
{ Entity::GroupLabel::PLAYERS },
|
||||||
{},
|
{},
|
||||||
true)) != nullptr)
|
true)) != nullptr)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -34,7 +34,7 @@ void ProjectileComponent::update()
|
|||||||
if ((player = Game::collisionHandler->getAnyIntersection<Entity*>(
|
if ((player = Game::collisionHandler->getAnyIntersection<Entity*>(
|
||||||
entity,
|
entity,
|
||||||
Vector2D(0,0),
|
Vector2D(0,0),
|
||||||
{GroupLabel::PLAYERS},
|
{Entity::GroupLabel::PLAYERS},
|
||||||
{entity->getTeam()},
|
{entity->getTeam()},
|
||||||
true)) != nullptr) {
|
true)) != nullptr) {
|
||||||
player->getComponent<HealthComponent>().modifyHealth();
|
player->getComponent<HealthComponent>().modifyHealth();
|
||||||
|
|||||||
@ -62,15 +62,15 @@ 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)Entity::GroupLabel::PLAYERS)) {
|
||||||
|
|
||||||
// [getAnyIntersection example code]
|
// [getAnyIntersection example code]
|
||||||
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), { Entity::GroupLabel::MAPTILES, Entity::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), { Entity::GroupLabel::MAPTILES, Entity::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))
|
||||||
|
|||||||
@ -35,9 +35,9 @@ int main(int argc, char* argv[])
|
|||||||
SDL_Delay(frameDelay - frameTime);
|
SDL_Delay(frameDelay - frameTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TeamLabel winner = game->getWinner();
|
Entity::TeamLabel winner = game->getWinner();
|
||||||
|
|
||||||
PopupWindow popupWindow("Game over", winner == TeamLabel::BLUE ?
|
PopupWindow popupWindow("Game over", winner == Entity::TeamLabel::BLUE ?
|
||||||
"Player1 won! Press 'C' to continue or 'Q' to quit." :
|
"Player1 won! Press 'C' to continue or 'Q' to quit." :
|
||||||
"Player2 won! Press 'C' to continue or 'Q' to quit.");
|
"Player2 won! Press 'C' to continue or 'Q' to quit.");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user