Reupload
This commit is contained in:
55
include/damncute/AAction.hh
Normal file
55
include/damncute/AAction.hh
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef _AACTION_H_
|
||||
# define _AACTION_H_
|
||||
|
||||
#include <SFML/Window/Joystick.hpp>
|
||||
#include "Core/Core.hh"
|
||||
|
||||
#define DC_INPUT_NONE 99999
|
||||
|
||||
namespace DamnCute
|
||||
{
|
||||
template <typename T>
|
||||
class AAction
|
||||
{
|
||||
|
||||
protected:
|
||||
sf::Keyboard::Key _key1;
|
||||
sf::Keyboard::Key _key2;
|
||||
sf::Joystick::Axis _stickAxis;
|
||||
int _stickButton;
|
||||
int _stickButton2;
|
||||
bool _hasAxis;
|
||||
T* _entity;
|
||||
|
||||
public:
|
||||
explicit AAction(T *p, sf::Keyboard::Key k, sf::Joystick::Axis s)
|
||||
: _key1(k), _key2(sf::Keyboard::Unknown), _stickAxis(s), _stickButton(DC_INPUT_NONE), _stickButton2(DC_INPUT_NONE), _hasAxis(true), _entity(p) { }
|
||||
|
||||
explicit AAction(T *p, sf::Keyboard::Key k1, sf::Keyboard::Key k2, sf::Joystick::Axis s)
|
||||
: _key1(k1), _key2(k2), _stickAxis(s), _stickButton(DC_INPUT_NONE), _stickButton2(DC_INPUT_NONE), _hasAxis(true), _entity(p) { }
|
||||
|
||||
explicit AAction(T *p, sf::Keyboard::Key k, int s)
|
||||
: _key1(k), _key2(sf::Keyboard::Unknown), _stickAxis(sf::Joystick::Axis::X), _stickButton(s), _stickButton2(DC_INPUT_NONE), _hasAxis(false), _entity(p) { }
|
||||
|
||||
explicit AAction(T *p, sf::Keyboard::Key k1, sf::Keyboard::Key k2, int s1, int s2)
|
||||
: _key1(k1), _key2(k2), _stickAxis(sf::Joystick::Axis::X), _stickButton(s1), _stickButton2(s2), _hasAxis(false), _entity(p) {}
|
||||
|
||||
virtual ~AAction() = default;
|
||||
|
||||
virtual void execute() = 0;
|
||||
virtual const std::string& getName() const = 0;
|
||||
virtual bool hasInput(int) = 0;
|
||||
|
||||
inline bool hasStickAxis() const { return _hasAxis; }
|
||||
|
||||
void setStickInput(sf::Joystick::Axis input) { _stickAxis = input; }
|
||||
void setStickInput(int input) { _stickButton = input; }
|
||||
void setKeyboardInput1(sf::Keyboard::Key input) { _key1 = input; }
|
||||
void setKeyboardInput2(sf::Keyboard::Key input) { _key2 = input; }
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
37
include/damncute/AGame.hh
Normal file
37
include/damncute/AGame.hh
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef AGAME_H_
|
||||
# define AGAME_H_
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include "Core/Core.hh"
|
||||
#include "APlayer.hh"
|
||||
#include "Background.hh"
|
||||
|
||||
namespace DamnCute {
|
||||
class AGame {
|
||||
|
||||
public:
|
||||
explicit AGame(const std::string&, const std::string&);
|
||||
explicit AGame();
|
||||
virtual ~AGame();
|
||||
virtual void pause() = 0;
|
||||
virtual void run() = 0;
|
||||
template <typename T>
|
||||
unsigned int addPlayer();
|
||||
APlayer* getPlayer(unsigned int);
|
||||
unsigned int addPlayer(APlayer*);
|
||||
void delPlayer(unsigned int);
|
||||
void stopRender();
|
||||
|
||||
private:
|
||||
std::list<APlayer*> _players;
|
||||
|
||||
protected:
|
||||
Core* _engine;
|
||||
std::string _baseResourcesPath;
|
||||
Background* _bg;
|
||||
bool _isEnd;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* !AGAME_H_ */
|
75
include/damncute/APattern.hh
Normal file
75
include/damncute/APattern.hh
Normal file
@ -0,0 +1,75 @@
|
||||
#ifndef APATTERN_H_
|
||||
# define APATTERN_H_
|
||||
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include "Path.hh"
|
||||
#include "Core/Core.hh"
|
||||
#include "IRenderable.hh"
|
||||
|
||||
namespace DamnCute {
|
||||
#ifdef __BULLER_PHYSIC_ID__
|
||||
#undef __BULLER_PHYSIC_ID__
|
||||
#endif
|
||||
#define __BULLER_PHYSIC_ID__ 0
|
||||
class APattern : public IRenderable {
|
||||
public:
|
||||
APattern() = default;
|
||||
|
||||
~APattern() {
|
||||
for (unsigned int i = 0; i != _paths.size(); ++i) {
|
||||
delete _paths[i];
|
||||
}
|
||||
}
|
||||
virtual void initialize() = 0;
|
||||
virtual int addPath(Path* p) {
|
||||
_paths.push_back(p);
|
||||
return _paths.size() - 1;
|
||||
}
|
||||
virtual void update(sf::RenderTarget* w_ptr) {
|
||||
for (unsigned int i = 0; i != _paths.size(); ++i) {
|
||||
_paths[i]->update(w_ptr);
|
||||
}
|
||||
up();
|
||||
}
|
||||
virtual void moveOrigin(glm::vec2&& n) noexcept {
|
||||
for (unsigned int i = 0; i != _paths.size(); ++i) {
|
||||
_paths[i]->moveOrigin(std::move(n));
|
||||
}
|
||||
}
|
||||
virtual void switchGen() {
|
||||
for (unsigned int i = 0; i != _paths.size(); ++i) {
|
||||
_paths[i]->switchGen();
|
||||
}
|
||||
}
|
||||
virtual void setStatusGen(bool&& b) {
|
||||
for (unsigned int i = 0; i != _paths.size(); ++i) {
|
||||
_paths[i]->setStatusGen(std::move(b));
|
||||
}
|
||||
}
|
||||
virtual void countdownPushMoveModifier(unsigned int f, const glm::mat4& m, unsigned int pathNumber) {
|
||||
_paths[pathNumber]->countdownPushMoveModifier(f, m);
|
||||
}
|
||||
virtual void setTimeSeparator(unsigned int newT, unsigned int p) {
|
||||
_paths[p]->setTimeSeparator(newT);
|
||||
}
|
||||
virtual void deletePath(unsigned int p) {
|
||||
if (p > _paths.size()) {
|
||||
return;
|
||||
}
|
||||
delete _paths[p];
|
||||
std::vector<Path*>::iterator it = _paths.begin();
|
||||
while (p) {
|
||||
--p;
|
||||
++it;
|
||||
}
|
||||
_paths.erase(it);
|
||||
}
|
||||
protected:
|
||||
virtual void up() {}
|
||||
std::vector<Path*> _paths;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* !APATTERN_H_ */
|
155
include/damncute/APhysics.hh
Normal file
155
include/damncute/APhysics.hh
Normal file
@ -0,0 +1,155 @@
|
||||
#ifndef APHISICS_H_
|
||||
# define APHISICS_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <map>
|
||||
#include "Core/Core.hh"
|
||||
|
||||
/*
|
||||
* -----
|
||||
* |A|B|
|
||||
* -----
|
||||
* |C|D|
|
||||
* -----
|
||||
*/
|
||||
|
||||
namespace DamnCute {
|
||||
class APhysics {
|
||||
private:
|
||||
bool _physicallyActive;
|
||||
bool _destructible;
|
||||
bool _destructor;
|
||||
unsigned int _type;
|
||||
|
||||
QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>* _quadTree;
|
||||
QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>::Array_Type_ _path;
|
||||
|
||||
std::map<std::list<APhysics*>*, std::list<APhysics*>::iterator> _where;
|
||||
|
||||
template <unsigned int sizeX, unsigned int sizeY, unsigned short iter>
|
||||
inline QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>::Array_Type_&& _generateQuadTreePos(unsigned int x, unsigned int y) noexcept {
|
||||
unsigned int nodeX = sizeX / 2;
|
||||
unsigned int nodeY = sizeY / 2;
|
||||
|
||||
for (unsigned short i = 0; i < iter; ++i)
|
||||
{
|
||||
if (x < nodeX && y > nodeY)
|
||||
{
|
||||
_path[i] = QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>::AZone;
|
||||
nodeX -= nodeX / 2;
|
||||
nodeY += nodeY / 2;
|
||||
}
|
||||
else if (x > nodeX && y > nodeY)
|
||||
{
|
||||
_path[i] = QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>::BZone;
|
||||
nodeX += nodeX / 2;
|
||||
nodeY += nodeY / 2;
|
||||
}
|
||||
else if (x < nodeX && y < nodeY)
|
||||
{
|
||||
_path[i] = QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>::CZone;
|
||||
nodeX -= nodeX / 2;
|
||||
nodeY -= nodeY / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_path[i] = QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>::DZone;
|
||||
nodeX += nodeX / 2;
|
||||
nodeY -= nodeY / 2;
|
||||
}
|
||||
}
|
||||
return std::move(_path);
|
||||
}
|
||||
|
||||
template <unsigned int sizeX, unsigned int sizeY, unsigned short iter>
|
||||
inline std::list<QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>::Array_Type_>&& _generateQuadTreePos(unsigned int x, unsigned int y, unsigned int w, unsigned int
|
||||
h) noexcept {
|
||||
std::list<QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>::Array_Type_> list;
|
||||
unsigned int quadWidth = sizeX / (2 * __DQUADTREE_COMPLEXITY__);
|
||||
unsigned int quadHeight = sizeY / (2 * __DQUADTREE_COMPLEXITY__);
|
||||
|
||||
for (unsigned int i = 0; i < w; i += quadWidth) {
|
||||
for (unsigned int j = 0; j < h; j += quadHeight) {
|
||||
list.push_back(_generateQuadTreePos<sizeX, sizeY, __DQUADTREE_COMPLEXITY__>(x + i, y + j));
|
||||
}
|
||||
}
|
||||
return std::move(list);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit APhysics(unsigned int x, unsigned int y, bool destructibility, bool destructor, unsigned int type = 0) : _physicallyActive(true), _destructible(destructibility), _destructor(destructor), _type(type), _quadTree(sCore->getQuadTree()) {
|
||||
_generateQuadTreePos<1920, 1080, __DQUADTREE_COMPLEXITY__>(x, y);
|
||||
}
|
||||
|
||||
virtual ~APhysics() {
|
||||
for (std::map<std::list<APhysics*>*, std::list<APhysics*>::iterator>::iterator it = _where.begin(); it != _where.end(); ++it) {
|
||||
it->first->erase(it->second);
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int getType() const {
|
||||
return _type;
|
||||
}
|
||||
|
||||
inline void setType(unsigned int id) {
|
||||
_type = id;
|
||||
}
|
||||
|
||||
inline bool isDestructible() {
|
||||
return _destructible;
|
||||
}
|
||||
|
||||
inline bool isDestructor() {
|
||||
return _destructor;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void collisionHandler(APhysics*) = 0;
|
||||
|
||||
bool preciseDetection(const sf::Sprite& s1, const sf::Sprite& s2) {
|
||||
if (s1.getGlobalBounds().intersects(s2.getGlobalBounds())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void updateQuadTreePos(unsigned int x, unsigned int y, unsigned int width = 1, unsigned int height = 1) {
|
||||
const unsigned int quadWidth = 1920 / (2 * __DQUADTREE_COMPLEXITY__);
|
||||
const unsigned int quadHeight = 1080 / (2 * __DQUADTREE_COMPLEXITY__);
|
||||
|
||||
std::list<APhysics*>* potentialDangerList;
|
||||
std::list<APhysics*>::iterator whereInList;
|
||||
|
||||
if (!_physicallyActive)
|
||||
return;
|
||||
for (std::map<std::list<APhysics*>*, std::list<APhysics*>::iterator>::iterator it = _where.begin(); it != _where.end(); ++it) {
|
||||
it->first->erase(it->second);
|
||||
}
|
||||
_where.clear();
|
||||
|
||||
for (unsigned int i = 0; i <= (width + quadWidth); i += quadWidth) {
|
||||
for (unsigned int j = 0; j <= (height + quadHeight); j += quadHeight) {
|
||||
_generateQuadTreePos<1920, 1080, __DQUADTREE_COMPLEXITY__>(x + i, y + j);
|
||||
potentialDangerList = _quadTree->getDataTreeNode(_path);
|
||||
if (_destructible && potentialDangerList) {
|
||||
for (std::list<APhysics*>::iterator potentialDanger = potentialDangerList->begin(); potentialDanger != potentialDangerList->end(); ++potentialDanger) {
|
||||
if ((*potentialDanger)->isDestructor()) {
|
||||
collisionHandler(*potentialDanger);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!potentialDangerList) {
|
||||
potentialDangerList = new std::list<APhysics*>();
|
||||
_quadTree->setTreeNode(potentialDangerList, _path);
|
||||
}
|
||||
potentialDangerList->push_front(this);
|
||||
whereInList = potentialDangerList->begin();
|
||||
_where[potentialDangerList] = whereInList;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* !APHISICS_H_ */
|
65
include/damncute/APlayer.hh
Normal file
65
include/damncute/APlayer.hh
Normal file
@ -0,0 +1,65 @@
|
||||
#ifndef APLAYER_H_
|
||||
# define APLAYER_H_
|
||||
|
||||
# include <iostream>
|
||||
# include <vector>
|
||||
# include <type_traits>
|
||||
# include "AAction.hh"
|
||||
# include "IRenderable.hh"
|
||||
# include "Core/Core.hh"
|
||||
# include "APhysics.hh"
|
||||
|
||||
namespace DamnCute
|
||||
{
|
||||
|
||||
# ifdef __PLAYER_PHYSIC_ID__
|
||||
# undef __PLAYER_PHYSIC_ID__
|
||||
# endif
|
||||
# define __PLAYER_PHYSIC_ID__ 1
|
||||
|
||||
class APlayer : public IRenderable, public APhysics {
|
||||
|
||||
private:
|
||||
void action();
|
||||
std::vector<AAction<APlayer>*> _actions;
|
||||
|
||||
sf::Sprite _entity;
|
||||
sf::Texture _tex;
|
||||
int _speed;
|
||||
int _nbPlayer;
|
||||
|
||||
public:
|
||||
explicit APlayer(const std::string& = "resources/player.tga",
|
||||
float = 100, float = 100, int nbPlayer = 1, int speed = 5);
|
||||
virtual ~APlayer() = default;
|
||||
APlayer& operator=(const APlayer&) = delete;
|
||||
|
||||
void update(sf::RenderTarget*);
|
||||
void addAction(AAction<APlayer>*);
|
||||
|
||||
inline sf::Sprite& getSprite() { return _entity; }
|
||||
inline sf::Texture& getTexture() { return _tex; }
|
||||
inline int& getSpeed() { return _speed; }
|
||||
inline int getNumPlayer() const { return _nbPlayer; }
|
||||
inline AAction<APlayer>* getAction(std::string);
|
||||
|
||||
template <int inputNumber, typename T>
|
||||
void setAction(const std::string& name, T t) {
|
||||
|
||||
for (size_t i = 0; i < _actions.size(); ++i) {
|
||||
if (name == (_actions[i])->getName())
|
||||
setActionInput(i, t, inputNumber);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void setActionInput(int i, T t, int a) {
|
||||
(void)i; (void)t; (void)a;
|
||||
static_assert(std::is_same<T, int>::value || std::is_same<T, sf::Keyboard::Key>::value || std::is_same<T, sf::Joystick::Axis>::value, "Error: type is not defined for input.");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
32
include/damncute/Background.hh
Normal file
32
include/damncute/Background.hh
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef BACKGROUND_H_
|
||||
# define BACKGROUND_H_
|
||||
|
||||
#include <string>
|
||||
#include <glm/glm.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "IRenderable.hh"
|
||||
#include "Core/Core.hh"
|
||||
|
||||
namespace DamnCute {
|
||||
class Background : public IRenderable {
|
||||
|
||||
private:
|
||||
Background(const Background&);
|
||||
float _XSpeed;
|
||||
float _YSpeed;
|
||||
sf::Sprite _bg;
|
||||
sf::Texture _tex;
|
||||
|
||||
public:
|
||||
Background(const std::string&, int = 0, int = 0);
|
||||
virtual ~Background() = default;
|
||||
float getXScrollSpeed() const ;
|
||||
float getYScrollSpeed() const ;
|
||||
|
||||
void setScrollSpeed(float, float);
|
||||
void setPosition(int, int);
|
||||
virtual void update(sf::RenderTarget*);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* !BACKGROUND_H_ */
|
51
include/damncute/Bullet.hh
Normal file
51
include/damncute/Bullet.hh
Normal file
@ -0,0 +1,51 @@
|
||||
#ifndef BULLET_H_
|
||||
# define BULLET_H_
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "APhysics.hh"
|
||||
|
||||
namespace DamnCute {
|
||||
class Bullet : public APhysics {
|
||||
|
||||
public:
|
||||
explicit Bullet(const glm::vec2&, const float = 0.0f, unsigned int = 60);
|
||||
explicit Bullet(const Bullet&) = delete;
|
||||
explicit Bullet(Bullet&&);
|
||||
virtual ~Bullet() = default;
|
||||
Bullet& operator=(const Bullet&) = delete;
|
||||
Bullet& operator=(Bullet&&);
|
||||
void update(const glm::mat4&, sf::RenderTarget*);
|
||||
unsigned int decreaseLifeTime();
|
||||
inline const sf::Sprite& getSprite() const noexcept {
|
||||
return _s;
|
||||
}
|
||||
inline const glm::vec2& getOrigin() const noexcept {
|
||||
return _origin;
|
||||
}
|
||||
inline float getRot() const noexcept {
|
||||
return _rot;
|
||||
}
|
||||
inline unsigned int getLife() const noexcept {
|
||||
return _lifeTime;
|
||||
}
|
||||
void setLife(unsigned int l) noexcept {
|
||||
_lifeTime = l;
|
||||
}
|
||||
inline void moveOrigin(glm::vec2&& n) noexcept {
|
||||
_origin = n;
|
||||
}
|
||||
void setTexure(sf::Texture*);
|
||||
virtual void collisionHandler(APhysics*);
|
||||
|
||||
private:
|
||||
glm::vec2 _origin;
|
||||
float _rot;
|
||||
glm::mat4 _selfTransform;
|
||||
sf::Texture* _tex; // TODO : need to be deleted or changed by referance
|
||||
sf::Sprite _s;
|
||||
unsigned int _lifeTime;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
59
include/damncute/Button.hh
Normal file
59
include/damncute/Button.hh
Normal file
@ -0,0 +1,59 @@
|
||||
#ifndef __BUTTON_H__
|
||||
# define __BUTTON_H__
|
||||
|
||||
# include <vector>
|
||||
# include <string>
|
||||
# include "Core/Core.hh"
|
||||
# include "SubMenu.hh"
|
||||
|
||||
namespace DamnCute {
|
||||
class Button : public IRenderable {
|
||||
|
||||
private:
|
||||
std::vector<SubMenu*>::iterator _itSub;
|
||||
std::vector<SubMenu*> _sub;
|
||||
const std::string _name;
|
||||
bool _alive;
|
||||
int _x;
|
||||
int _y;
|
||||
int _offsetx = 0;
|
||||
int _offsety = 0;
|
||||
bool _start = false;
|
||||
sf::Sprite _s;
|
||||
sf::Texture& _tex;
|
||||
sf::Text _text;
|
||||
|
||||
public:
|
||||
explicit Button(const std::string &, sf::Text &, int, int, sf::Texture&);
|
||||
virtual ~Button() = default;
|
||||
|
||||
inline void operator=(const Button& b) {
|
||||
_tex = b._tex;
|
||||
_s = b._s;
|
||||
_text = b._text;
|
||||
}
|
||||
virtual void update(sf::RenderTarget*);
|
||||
|
||||
int getX();
|
||||
int getY();
|
||||
bool getStart();
|
||||
const std::string getName();
|
||||
|
||||
void setAlive();
|
||||
void setAlive2();
|
||||
void setOffsets(int, int);
|
||||
void setPos(int, int);
|
||||
void setStart();
|
||||
|
||||
bool hasField(const std::string &);
|
||||
const std::string getField(const std::string &);
|
||||
void moveDown();
|
||||
void moveUp();
|
||||
void moveRight();
|
||||
void moveLeft();
|
||||
void addSubMenu(SubMenu *b);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
123
include/damncute/Core/Core.hh
Normal file
123
include/damncute/Core/Core.hh
Normal file
@ -0,0 +1,123 @@
|
||||
#ifndef CORE_H_
|
||||
# define CORE_H_
|
||||
|
||||
#include <list>
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "QuadTree.hh"
|
||||
#include "../IRenderable.hh"
|
||||
|
||||
# ifndef __DWIDTH
|
||||
# define __DWIDTH 1920
|
||||
# define __DHEIGHT 1080
|
||||
# endif
|
||||
|
||||
#ifndef __DQUADTREE_COMPLEXITY__
|
||||
#define __DQUADTREE_COMPLEXITY__ 6
|
||||
#endif
|
||||
|
||||
#if __DQUADTREE_COMPLEXITY__ > 10
|
||||
#warning "you will use more than 300 Mb =O"
|
||||
#endif
|
||||
|
||||
namespace DamnCute {
|
||||
class APhysics;
|
||||
class Core {
|
||||
public:
|
||||
Core(const Core&) = delete;
|
||||
Core(const Core&&) = delete;
|
||||
Core& operator=(const Core&) = delete;
|
||||
Core& operator=(const Core&&) = delete;
|
||||
|
||||
static Core* getInstance();
|
||||
void closeWin();
|
||||
void reset();
|
||||
void freeAll();
|
||||
void addObject(IRenderable*);
|
||||
void delObject(IRenderable*);
|
||||
void hideObject(IRenderable*);
|
||||
void addOnBg(IRenderable*);
|
||||
void flushScene();
|
||||
void flushEvent();
|
||||
template <unsigned int SIZEX = __DWIDTH, unsigned int SIZEY = __DHEIGHT>
|
||||
void createWindow(unsigned int width = 0, unsigned int height = 0, bool full = false) {
|
||||
unsigned int style = full << 3 | sf::Style::Titlebar;
|
||||
sf::VideoMode v;
|
||||
|
||||
if (full) {
|
||||
v = sf::VideoMode::getFullscreenModes()[0];
|
||||
} else if (width == 0 && height == 0) {
|
||||
v = sf::VideoMode::getDesktopMode();
|
||||
} else {
|
||||
v = sf::VideoMode(width, height);
|
||||
}
|
||||
_win = new sf::RenderWindow(v, "DamnCute Engine", style);
|
||||
_Rtex.create(SIZEX, SIZEY);
|
||||
_Rtex.setSmooth(true);
|
||||
_rsp.setTexture(_Rtex.getTexture());
|
||||
_rsp.setScale((float)getWindowSizeX() / (float)__DWIDTH , (float)getWindowSizeY() / (float)__DHEIGHT);
|
||||
_win->setVerticalSyncEnabled(true);
|
||||
_win->setFramerateLimit(60);
|
||||
}
|
||||
int getWindowStatus();
|
||||
int getWindowSizeX();
|
||||
int getWindowSizeY();
|
||||
sf::Music& getMusic();
|
||||
void musicPath(std::string);
|
||||
void musicPlay(int);
|
||||
int getMusicListSize();
|
||||
|
||||
inline bool getGameStatus() const {
|
||||
return _gameStatus;
|
||||
}
|
||||
inline void switchGameStatus() {
|
||||
_gameStatus = !_gameStatus;
|
||||
}
|
||||
inline sf::Event getEvent() const {
|
||||
return event;
|
||||
}
|
||||
inline void setFPSDisplay(bool value) {
|
||||
_displayFPS = value;
|
||||
}
|
||||
inline void addBulletsCounter() {
|
||||
++_numberOfBullets;
|
||||
}
|
||||
inline QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>* getQuadTree() {
|
||||
return &_physicTree;
|
||||
}
|
||||
private:
|
||||
|
||||
Core();
|
||||
~Core();
|
||||
void refresh();
|
||||
|
||||
static Core* __coreInstance;
|
||||
QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__> _physicTree;
|
||||
sf::RenderWindow* _win;
|
||||
sf::RenderTexture _Rtex;
|
||||
std::list<IRenderable*> _objects;
|
||||
bool _gameStatus;
|
||||
bool _displayFPS;
|
||||
unsigned int _numberOfBullets;
|
||||
unsigned int _Pframmes;
|
||||
unsigned int _tmpFrammes;
|
||||
|
||||
sf::Sprite _rsp;
|
||||
sf::Clock _gameClock;
|
||||
sf::Event event;
|
||||
sf::Music _music;
|
||||
std::string _musicPath;
|
||||
std::vector<std::string> _musicList;
|
||||
|
||||
void saveFolderMusic(std::string);
|
||||
bool supportedFileFormat(std::string);
|
||||
};
|
||||
}
|
||||
|
||||
#define sCore Core::getInstance()
|
||||
|
||||
#endif /* !CORE_H_ */
|
76
include/damncute/Core/QuadTree.hh
Normal file
76
include/damncute/Core/QuadTree.hh
Normal file
@ -0,0 +1,76 @@
|
||||
#include <array>
|
||||
#include <utility>
|
||||
|
||||
#ifndef QUADTREE_H_
|
||||
# define QUADTREE_H_
|
||||
|
||||
namespace DamnCute {
|
||||
template <typename T, unsigned int LEVEL>
|
||||
class QuadTree {
|
||||
public:
|
||||
enum TDir {
|
||||
AZone,
|
||||
BZone,
|
||||
CZone,
|
||||
DZone
|
||||
};
|
||||
enum _CQTREEVALUES_ {
|
||||
_COMPLEXITY_ = LEVEL,
|
||||
};
|
||||
private:
|
||||
#include "TreeNode.hh"
|
||||
typedef std::array<TDir, LEVEL> __path_ar_;
|
||||
TreeNode<T>* _head;
|
||||
|
||||
inline TreeNode<T>* _getNode(__path_ar_ path) const {
|
||||
TreeNode<T>* x = _head;
|
||||
for (typename __path_ar_::const_iterator it = path.cbegin(); it != path.cend(); ++it) {
|
||||
if (*it == AZone)
|
||||
x = x->up;
|
||||
else if (*it == BZone)
|
||||
x = x->down;
|
||||
else if (*it == CZone)
|
||||
x = x->right;
|
||||
else if (*it == DZone)
|
||||
x = x->left;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit QuadTree() : _head(new TreeNode<T>(LEVEL)) {}
|
||||
|
||||
T* getDataTreeNode(__path_ar_& path) const {
|
||||
return _getNode(path)->data;
|
||||
}
|
||||
|
||||
void setTreeNode(T* value, const __path_ar_& path) {
|
||||
_getNode(path)->data = value;
|
||||
}
|
||||
|
||||
void swap(__path_ar_& path1, const __path_ar_& path2) {
|
||||
T* a = _getNode(path1)->data;
|
||||
T* b = _getNode(path2)->data;
|
||||
T* tmp;
|
||||
|
||||
tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
bool thereIsObject(const __path_ar_& p) {
|
||||
if (_getNode(p)->data) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline unsigned int&& getLevel() const {
|
||||
return std::move(LEVEL);
|
||||
}
|
||||
|
||||
typedef __path_ar_ Array_Type_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* !QUADTREE_H_ */
|
38
include/damncute/Core/TreeNode.hh
Normal file
38
include/damncute/Core/TreeNode.hh
Normal file
@ -0,0 +1,38 @@
|
||||
#include <type_traits>
|
||||
|
||||
#ifndef NODE_H_
|
||||
# define NODE_H_
|
||||
|
||||
template <typename DATANODE>
|
||||
struct TreeNode {
|
||||
|
||||
DATANODE* data; // TODO must exist only for final recurtion
|
||||
TreeNode<DATANODE>* up;
|
||||
TreeNode<DATANODE>* down;
|
||||
TreeNode<DATANODE>* right;
|
||||
TreeNode<DATANODE>* left;
|
||||
|
||||
explicit TreeNode(unsigned short level) {
|
||||
if (level) {
|
||||
up = new TreeNode<DATANODE>(level - 1);
|
||||
down = new TreeNode<DATANODE>(level - 1);
|
||||
left = new TreeNode<DATANODE>(level - 1);
|
||||
right = new TreeNode<DATANODE>(level - 1);
|
||||
} else {
|
||||
up = NULL;
|
||||
down = NULL;
|
||||
left = NULL;
|
||||
right = NULL;
|
||||
}
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
virtual ~TreeNode() {
|
||||
delete up;
|
||||
delete down;
|
||||
delete left;
|
||||
delete right;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* !NODE_H_ */
|
14
include/damncute/IRenderable.hh
Normal file
14
include/damncute/IRenderable.hh
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef IRENDERABLE_H_
|
||||
# define IRENDERABLE_H_
|
||||
|
||||
# include <SFML/Graphics.hpp>
|
||||
|
||||
namespace DamnCute {
|
||||
class IRenderable {
|
||||
public:
|
||||
virtual void update(sf::RenderTarget*) = 0;
|
||||
virtual ~IRenderable() {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* !IRENDERABLE_H_ */
|
97
include/damncute/Menu.hh
Normal file
97
include/damncute/Menu.hh
Normal file
@ -0,0 +1,97 @@
|
||||
#ifndef IMENU_H_
|
||||
# define IMENU_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "Background.hh"
|
||||
#include "AAction.hh"
|
||||
#include "Core/Core.hh"
|
||||
#include "SubMenu.hh"
|
||||
#include "Button.hh"
|
||||
|
||||
namespace DamnCute {
|
||||
class Menu : public IRenderable {
|
||||
|
||||
private:
|
||||
template<bool C>
|
||||
class IfThenElse {
|
||||
public:
|
||||
enum {
|
||||
value = C
|
||||
};
|
||||
};
|
||||
|
||||
int _offsetSubMenuX = 15;
|
||||
int _offsetSubMenuY = 25;
|
||||
unsigned int _characterSize = 20;
|
||||
sf::Font _font;
|
||||
std::string _font_path;
|
||||
bool _alive;
|
||||
bool _clicked;
|
||||
bool _clicked2;
|
||||
int _cursPosX;
|
||||
int _cursPosY;
|
||||
sf::Texture _tex;
|
||||
sf::Texture _tex2;
|
||||
Game *_game;
|
||||
Core* _core;
|
||||
Background *_bgPTR;
|
||||
std::string _bg;
|
||||
sf::Sprite *_cursor = NULL;
|
||||
std::vector<Button*>::iterator _itButtons;
|
||||
std::vector<Button*> _buttons;
|
||||
std::vector<AAction<Menu>*> _actions;
|
||||
bool _isGame;
|
||||
|
||||
public:
|
||||
explicit Menu(const std::string& texfile);
|
||||
virtual ~Menu() = default;
|
||||
void addStartButton(int x, int y, const std::string& text);
|
||||
void setTextureCursor(const std::string&, int, int);
|
||||
virtual void update(sf::RenderTarget* win);
|
||||
|
||||
template <int ID> void setButton(Button* b) {
|
||||
static_assert(IfThenElse<_buttons.size() < ID>::value,
|
||||
"ID is out of bounds");
|
||||
_buttons[ID] = b;
|
||||
}
|
||||
|
||||
void setFontPath(std::string path){
|
||||
_font_path = path;
|
||||
_font.loadFromFile(_font_path);
|
||||
}
|
||||
|
||||
void setTextureButton(const std::string&);
|
||||
|
||||
bool getAlive() {
|
||||
return (_alive);
|
||||
}
|
||||
void addButton(int x, int y, const std::string&);
|
||||
void addSubMenu(const std::string &Button, const std::string &Option, std::vector<std::string> listOption, int x, int y);
|
||||
|
||||
void setButtonPos(const std::string &Button, int x, int y);
|
||||
void setButtonOffset(const std::string &Button, int x, int y);
|
||||
void setSubMenuOffset(int x, int y) {
|
||||
_offsetSubMenuX = x;
|
||||
_offsetSubMenuY = y;
|
||||
}
|
||||
|
||||
void update() {
|
||||
_alive = DamnCute::Core::getInstance()->getWindowStatus();
|
||||
}
|
||||
|
||||
const std::string getSubMenuField(const std::string &);
|
||||
void delAll();
|
||||
void gameMode();
|
||||
|
||||
void moveDown();
|
||||
void moveUp();
|
||||
void moveRight();
|
||||
void moveLeft();
|
||||
void moveReturn();
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* !IMENU_H_ */
|
52
include/damncute/Path.hh
Normal file
52
include/damncute/Path.hh
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef PATTERN_H_
|
||||
# define PATTERN_H_
|
||||
|
||||
#include <list>
|
||||
#include <glm/glm.hpp>
|
||||
#include <utility>
|
||||
#include <stack>
|
||||
#include "APlayer.hh"
|
||||
#include "Bullet.hh"
|
||||
#include "IRenderable.hh"
|
||||
#include "Core/Core.hh"
|
||||
|
||||
namespace DamnCute {
|
||||
class Path : public IRenderable {
|
||||
private:
|
||||
sf::Texture _tex;
|
||||
Bullet _bulletModel;
|
||||
std::list<Bullet> _bullets;
|
||||
unsigned int _timeLoad;
|
||||
unsigned int _timeSeparator;
|
||||
glm::mat4 _stepModifier;
|
||||
bool _generate;
|
||||
|
||||
typedef struct __SmodEvent {
|
||||
unsigned int _futureframe;
|
||||
glm::mat4 _newMat;
|
||||
} modEvent;
|
||||
std::stack<modEvent> _modEventStack;
|
||||
|
||||
public:
|
||||
explicit Path(const glm::mat4&, unsigned int frameStep = 5, Bullet&& = Bullet(glm::vec2(0,0)), const std::string& = "resources/test.tga");
|
||||
virtual ~Path() = default;
|
||||
virtual void update(sf::RenderTarget*);
|
||||
void countdownPushMoveModifier(unsigned int, const glm::mat4&);
|
||||
void setPhysicBulletModelId(unsigned int);
|
||||
void setAllPhysicBulletId(unsigned int);
|
||||
inline void moveOrigin(glm::vec2&& n) noexcept {
|
||||
_bulletModel.moveOrigin(std::move(n));
|
||||
}
|
||||
inline void switchGen() {
|
||||
_generate = !_generate;
|
||||
}
|
||||
inline void setStatusGen(bool&& b) {
|
||||
_generate = b;
|
||||
}
|
||||
inline void setTimeSeparator(unsigned int newTs) {
|
||||
_timeSeparator = newTs;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* !PATTERN_H_ */
|
48
include/damncute/SubMenu.hh
Normal file
48
include/damncute/SubMenu.hh
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef SUBMENU_H_
|
||||
# define SUBMENU_H_
|
||||
|
||||
# include <vector>
|
||||
# include <string>
|
||||
# include "Core/Core.hh"
|
||||
|
||||
namespace DamnCute {
|
||||
class SubMenu : public IRenderable {
|
||||
|
||||
private:
|
||||
bool _alive;
|
||||
sf::Text _text;
|
||||
std::vector<sf::Text *>::iterator _it;
|
||||
std::vector<sf::Text *> _options;
|
||||
|
||||
public:
|
||||
explicit SubMenu(sf::Text &, const std::string & , std::vector<sf::Text *>);
|
||||
virtual ~SubMenu() = default;
|
||||
|
||||
inline void operator=(const SubMenu& b) {
|
||||
_text = b._text;
|
||||
}
|
||||
|
||||
void moveRight();
|
||||
void moveLeft();
|
||||
|
||||
const std::string getName() {
|
||||
return (_text.getString());
|
||||
}
|
||||
|
||||
const std::string getField() {
|
||||
return ((*_it)->getString());
|
||||
}
|
||||
|
||||
void setAlive() {
|
||||
if (_alive == false)
|
||||
_alive = true;
|
||||
else
|
||||
_alive = false;
|
||||
}
|
||||
|
||||
virtual void update(sf::RenderTarget*);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user