generated from joshSi/cmake-sfml-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from joshSi/feature/collision-logic
Simple collision logic TODO: - Rectangle-Circle snap logic - Future: Rotated rectangles?
- Loading branch information
Showing
13 changed files
with
503 additions
and
232 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,63 @@ | ||
#ifndef OBJECT_H | ||
#define OBJECT_H | ||
#include <SFML/Graphics.hpp> | ||
|
||
class Object : virtual public sf::Sprite { | ||
public: | ||
Object(); | ||
Object(sf::Texture &tex); | ||
virtual bool checkCollision(Object *obj) const = 0; | ||
virtual void snapCollision(Object *obj) = 0; | ||
virtual void drawCollision(sf::RenderTarget *target) const = 0; | ||
|
||
sf::Vector2f m_spd_vec; | ||
float m_mass; // 0 if static | ||
static bool g_draw_collisions; | ||
}; | ||
|
||
class Circle; | ||
class Rectangle; | ||
|
||
class Circle : public Object { | ||
public: | ||
Circle() : Object(), m_radius(1) {} | ||
Circle(sf::Texture &tex); | ||
Circle(sf::Texture &tex, float r) : Object(tex), m_radius(r) {} | ||
|
||
bool checkCollision(Object *obj) const override; | ||
bool checkCollision(Circle *obj) const; | ||
bool checkCollision(Rectangle *obj) const; | ||
|
||
void snapCollision(Object *obj) override; | ||
void snapCollision(Circle *obj); | ||
void snapCollision(Rectangle *obj); | ||
|
||
void drawCollision(sf::RenderTarget *target) const override; | ||
float getRadius() const { return m_radius; } | ||
|
||
private: | ||
float m_radius; | ||
}; | ||
|
||
class Rectangle : public Object { | ||
public: | ||
Rectangle() : Object(), m_size(2, 2) {} | ||
Rectangle(sf::Texture &tex); | ||
Rectangle(sf::Texture &tex, sf::Vector2f size) : Object(tex), m_size(size) {} | ||
|
||
bool checkCollision(Object *obj) const override; | ||
bool checkCollision(Rectangle *obj) const; | ||
bool checkCollision(Circle *obj) const; | ||
|
||
void snapCollision(Object *obj) override; | ||
void snapCollision(Circle *obj); | ||
void snapCollision(Rectangle *obj); | ||
|
||
void drawCollision(sf::RenderTarget *target) const override; | ||
const sf::Vector2f getSize() const { return m_size; } | ||
|
||
private: | ||
sf::Vector2f m_size; | ||
}; | ||
|
||
#endif |
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 |
---|---|---|
@@ -1,28 +1,29 @@ | ||
#ifndef PLATFORM_UTILS_H | ||
#ifndef PLATFORM_UTILS_H | ||
#define PLATFORM_UTILS_H | ||
#ifdef __APPLE__ | ||
#include <CoreFoundation/CoreFoundation.h> | ||
#endif | ||
#include <string> | ||
|
||
std::string getResourcePath() | ||
{ | ||
#ifdef __APPLE__ | ||
CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); | ||
CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); | ||
const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); | ||
std::string path(pathPtr); | ||
std::string resourcePath = path + "/Contents/Resources/"; | ||
std::string getResourcePath() { | ||
#ifdef __APPLE__ | ||
CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); | ||
CFStringRef macPath = | ||
CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); | ||
const char *pathPtr = | ||
CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); | ||
std::string path(pathPtr); | ||
std::string resourcePath = path + "/Contents/Resources/"; | ||
|
||
CFRelease(appUrlRef); | ||
CFRelease(macPath); | ||
CFRelease(appUrlRef); | ||
CFRelease(macPath); | ||
|
||
return resourcePath; | ||
#elif defined(_WIN32) | ||
return "assets/"; | ||
#else | ||
return "assets/"; | ||
#endif | ||
return resourcePath; | ||
#elif defined(_WIN32) | ||
return "assets/"; | ||
#else | ||
return "assets/"; | ||
#endif | ||
} | ||
|
||
#endif | ||
#endif |
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.