-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe4dd30
commit 38d15c6
Showing
24 changed files
with
559 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,59 @@ | ||
{ | ||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" | ||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", | ||
"files.associations": { | ||
"algorithm": "cpp", | ||
"array": "cpp", | ||
"atomic": "cpp", | ||
"cctype": "cpp", | ||
"cmath": "cpp", | ||
"compare": "cpp", | ||
"concepts": "cpp", | ||
"cstddef": "cpp", | ||
"cstdint": "cpp", | ||
"cstdio": "cpp", | ||
"cstdlib": "cpp", | ||
"cstring": "cpp", | ||
"ctime": "cpp", | ||
"cwchar": "cpp", | ||
"deque": "cpp", | ||
"exception": "cpp", | ||
"initializer_list": "cpp", | ||
"ios": "cpp", | ||
"iosfwd": "cpp", | ||
"iostream": "cpp", | ||
"istream": "cpp", | ||
"iterator": "cpp", | ||
"limits": "cpp", | ||
"locale": "cpp", | ||
"map": "cpp", | ||
"memory": "cpp", | ||
"new": "cpp", | ||
"ostream": "cpp", | ||
"set": "cpp", | ||
"stack": "cpp", | ||
"stdexcept": "cpp", | ||
"streambuf": "cpp", | ||
"string": "cpp", | ||
"system_error": "cpp", | ||
"tuple": "cpp", | ||
"type_traits": "cpp", | ||
"typeinfo": "cpp", | ||
"utility": "cpp", | ||
"vector": "cpp", | ||
"xfacet": "cpp", | ||
"xiosbase": "cpp", | ||
"xlocale": "cpp", | ||
"xlocbuf": "cpp", | ||
"xlocinfo": "cpp", | ||
"xlocmes": "cpp", | ||
"xlocmon": "cpp", | ||
"xlocnum": "cpp", | ||
"xloctime": "cpp", | ||
"xmemory": "cpp", | ||
"xstddef": "cpp", | ||
"xstring": "cpp", | ||
"xtr1common": "cpp", | ||
"xtree": "cpp", | ||
"xutility": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "Body.hpp" | ||
|
||
struct Context; | ||
|
||
class Ball : public Body | ||
{ | ||
private: | ||
/** | ||
* \brief This method creates a new dynamic b2Body. It internally attaches a drawable object | ||
* as userData in body definition. Use b2Body::GetUserData() to get this drawable. | ||
* | ||
* \param radius Radius of circle in pixel space. | ||
* \param position Position of the ball in pixel space. | ||
* \return A new circular b2Body. | ||
*/ | ||
b2Body* CreateBall(const float& radius, const sf::Vector2f& position); | ||
public: | ||
Ball(std::shared_ptr<Context>& context, const float& radius, const sf::Vector2f position); | ||
|
||
virtual BodyType GetType() const override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <SFML/Graphics/Drawable.hpp> | ||
#include <SFML/Graphics/Transformable.hpp> | ||
#include <SFML/System/Time.hpp> | ||
#include <SFML/Graphics/Shape.hpp> | ||
|
||
#include <box2d/b2_body.h> | ||
|
||
#include <memory> | ||
|
||
struct Context; | ||
|
||
enum class BodyType | ||
{ | ||
Ball, | ||
Paddle, | ||
Wall, | ||
Brick | ||
}; | ||
|
||
class Body : public sf::Drawable | ||
{ | ||
protected: | ||
b2Body* m_body; | ||
sf::Shape* m_shape; | ||
|
||
std::shared_ptr<Context> m_context; | ||
|
||
public: | ||
Body(std::shared_ptr<Context> &context); | ||
virtual ~Body(); | ||
|
||
virtual BodyType GetType() const = 0; | ||
b2Body* GetB2Body(); | ||
|
||
void Update(const sf::Time& deltaTime); | ||
|
||
protected: | ||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "Body.hpp" | ||
|
||
class Brick : public Body | ||
{ | ||
private: | ||
/** | ||
* \brief This method creates a new dynamic b2Body. It internally attaches a drawable object | ||
* as userData in body definition. Use b2Body::GetUserData() to get this drawable. | ||
* | ||
* \param size Size of the paddle in pixel space. | ||
* \param position Position of the brick in pixel space. | ||
* \return A new rectangular b2Body. | ||
*/ | ||
b2Body* CreateBrick(const sf::Vector2f& size, const sf::Vector2f position); | ||
public: | ||
Brick(std::shared_ptr<Context>& context, const sf::Vector2f& size, const sf::Vector2f position); | ||
|
||
virtual BodyType GetType() const override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
#pragma once | ||
|
||
#include "Ball.hpp" | ||
|
||
#include <box2d/b2_world_callbacks.h> | ||
#include <box2d/b2_body.h> | ||
|
||
#include <vector> | ||
#include <map> | ||
|
||
class ContactListener : public b2ContactListener | ||
{ | ||
private: | ||
const b2Body* m_ball; | ||
const b2Body* m_paddle; | ||
std::shared_ptr<std::multimap<BodyType, std::unique_ptr<Body>>> m_entityMap; | ||
std::vector<b2Body*> m_bodiesToBeDeleted; | ||
|
||
public: | ||
ContactListener(); | ||
ContactListener(std::shared_ptr<std::multimap<BodyType, std::unique_ptr<Body>>>& entityMap); | ||
virtual ~ContactListener(); | ||
|
||
void SetBall(const b2Body* ball); | ||
void SetPaddle(const b2Body* paddle); | ||
|
||
virtual void EndContact(b2Contact* contact) final; | ||
|
||
void DeleteCollidedBodies(b2World* world, std::vector<b2Body*>& bricks); | ||
void DeleteCollidedBodies(b2World* world); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "Body.hpp" | ||
|
||
class Paddle : public Body | ||
{ | ||
private: | ||
/** | ||
* \brief This method creates a new dynamic b2Body. It internally attaches a drawable object | ||
* as userData in body definition. Use b2Body::GetUserData() to get this drawable. | ||
* | ||
* \param size Size of the paddle in pixel space. | ||
* \param position Position of the paddle in pixel space. | ||
* \return A new rectangular b2Body. | ||
*/ | ||
b2Body* CreatePaddle(const sf::Vector2f& size, const sf::Vector2f position); | ||
public: | ||
Paddle(std::shared_ptr<Context>& context, const sf::Vector2f& size, const sf::Vector2f position); | ||
|
||
virtual BodyType GetType() const override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "Body.hpp" | ||
|
||
class Wall : public Body | ||
{ | ||
private: | ||
/** | ||
* \brief This method creates a new static b2Body. It internally attaches a drawable object | ||
* as userData in body definition. Use b2Body::GetUserData() to get this drawable. | ||
* | ||
* \param size Size of the wall in pixel space. | ||
* \param position Position of the wall in pixel space. | ||
* \return A new rectangular b2Body. | ||
*/ | ||
b2Body* CreateWall(const sf::Vector2f& size, const sf::Vector2f position); | ||
public: | ||
Wall(std::shared_ptr<Context>& context, const sf::Vector2f& size, const sf::Vector2f position); | ||
|
||
virtual BodyType GetType() const override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.