From 77be863f4f15d2481a64e4e8dadb4060a6e4e590 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 11 Feb 2018 12:34:52 -0500 Subject: Implemented map rendering and basic collision Only wall and platform collision currently works, and map edges are not currently implemented. --- src/components/mappable.h | 146 ++++++++++++++++++++++++++++++++++++++++++++ src/components/ponderable.h | 23 +++++-- 2 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 src/components/mappable.h (limited to 'src/components') diff --git a/src/components/mappable.h b/src/components/mappable.h new file mode 100644 index 0000000..7530919 --- /dev/null +++ b/src/components/mappable.h @@ -0,0 +1,146 @@ +#ifndef MAPPABLE_H_0B0316FB +#define MAPPABLE_H_0B0316FB + +#include +#include "component.h" +#include "renderer.h" +#include "map.h" + +class MappableComponent : public Component { +public: + + class Boundary { + public: + + enum class Type { + wall, + wrap, + teleport, + reverse, + platform, + danger + }; + + Boundary( + double axis, + double lower, + double upper, + Type type) : + axis_(axis), + lower_(lower), + upper_(upper), + type_(type) + { + } + + inline double getAxis() const + { + return axis_; + } + + inline double getLower() const + { + return lower_; + } + + inline double getUpper() const + { + return upper_; + } + + inline Type getType() const + { + return type_; + } + + private: + + double axis_; + double lower_; + double upper_; + Type type_; + }; + + MappableComponent( + Texture tileset, + Texture font) : + tileset_(std::move(tileset)), + font_(std::move(font)) + { + } + + using asc_boundaries_type = + std::multimap< + double, + Boundary, + std::less>; + + using desc_boundaries_type = + std::multimap< + double, + Boundary, + std::greater>; + + inline size_t getMapId() const + { + return mapId_; + } + + inline void setMapId(size_t v) + { + mapId_ = v; + } + + inline desc_boundaries_type& getLeftBoundaries() + { + return leftBoundaries_; + } + + inline asc_boundaries_type& getRightBoundaries() + { + return rightBoundaries_; + } + + inline desc_boundaries_type& getUpBoundaries() + { + return upBoundaries_; + } + + inline asc_boundaries_type& getDownBoundaries() + { + return downBoundaries_; + } + + inline const Texture& getTileset() const + { + return tileset_; + } + + inline void setTileset(Texture v) + { + tileset_ = std::move(v); + } + + inline const Texture& getFont() const + { + return font_; + } + + inline void setFont(Texture v) + { + font_ = std::move(v); + } + +private: + + size_t mapId_ = -1; + + desc_boundaries_type leftBoundaries_; + asc_boundaries_type rightBoundaries_; + desc_boundaries_type upBoundaries_; + asc_boundaries_type downBoundaries_; + Texture tileset_; + Texture font_; +}; + +#endif /* end of include guard: MAPPABLE_H_0B0316FB */ diff --git a/src/components/ponderable.h b/src/components/ponderable.h index dfbf908..ac759b6 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h @@ -6,13 +6,27 @@ class PonderableComponent : public Component { public: - enum class state { + enum class Type { + vacuumed, + freefalling + }; + + enum class State { grounded, jumping, falling, dropping }; + PonderableComponent(Type type) : type_(type) + { + } + + inline Type getType() const + { + return type_; + } + inline double getVelocityX() const { return velX_; @@ -53,12 +67,12 @@ public: accelY_ = v; } - inline state getState() const + inline State getState() const { return state_; } - inline void setState(state arg) + inline void setState(State arg) { state_ = arg; } @@ -69,7 +83,8 @@ private: double velY_ = 0.0; double accelX_ = 0.0; double accelY_ = 0.0; - state state_ = state::grounded; + Type type_ = Type::vacuumed; + State state_ = State::grounded; }; #endif /* end of include guard: TANGIBLE_H_746DB3EE */ -- cgit 1.4.1