From ea0a959c2405511255080cae9f9558f2711a887f Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 11 Mar 2015 11:15:28 -0400 Subject: Fixed bug where one could fall through the floor after changing maps --- src/components.cpp | 30 +++++++++++++++++++++++++----- src/components.h | 2 +- src/renderer.cpp | 6 +++--- src/renderer.h | 6 +++--- 4 files changed, 32 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/components.cpp b/src/components.cpp index 4d62a87..11350ea 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -395,7 +395,12 @@ void MapCollisionComponent::detectCollision(Game& game, Entity&, Entity& collide if ((fixed_oy+collider.size.second > collision.lower) && (fixed_oy < collision.upper)) { // We have a collision! - processCollision(game, collider, collision, Direction::left); + if (processCollision(game, collider, collision, Direction::left)) + { + collider.position.second = old_position.second; + + return; + } break; } @@ -410,7 +415,12 @@ void MapCollisionComponent::detectCollision(Game& game, Entity&, Entity& collide if ((fixed_oy+collider.size.second > collision.lower) && (fixed_oy < collision.upper)) { // We have a collision! - processCollision(game, collider, collision, Direction::right); + if (processCollision(game, collider, collision, Direction::right)) + { + collider.position.second = old_position.second; + + return; + } break; } @@ -430,7 +440,10 @@ void MapCollisionComponent::detectCollision(Game& game, Entity&, Entity& collide if ((fixed_x+collider.size.first > collision.lower) && (fixed_x < collision.upper)) { // We have a collision! - processCollision(game, collider, collision, Direction::up); + if (processCollision(game, collider, collision, Direction::up)) + { + return; + } break; } @@ -445,7 +458,10 @@ void MapCollisionComponent::detectCollision(Game& game, Entity&, Entity& collide if ((fixed_x+collider.size.first > collision.lower) && (fixed_x < collision.upper)) { // We have a collision! - processCollision(game, collider, collision, Direction::down); + if (processCollision(game, collider, collision, Direction::down)) + { + return; + } break; } @@ -453,7 +469,7 @@ void MapCollisionComponent::detectCollision(Game& game, Entity&, Entity& collide } } -void MapCollisionComponent::processCollision(Game& game, Entity& collider, Collision collision, Direction dir) +bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Collision collision, Direction dir) { if (collision.type == 0) { @@ -508,6 +524,8 @@ void MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli collider.position.first = -collider.size.first/2; game.loadMap(*rightMap); } + + return true; } else if (collision.type == 3) { if (dir == Direction::right) @@ -524,4 +542,6 @@ void MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli collider.send(game, msg); } + + return false; } diff --git a/src/components.h b/src/components.h index 985025c..2585d73 100644 --- a/src/components.h +++ b/src/components.h @@ -83,7 +83,7 @@ class MapCollisionComponent : public Component { }; void addCollision(int axis, int lower, int upper, Direction dir, int type); - void processCollision(Game& game, Entity& collider, Collision collision, Direction dir); + bool processCollision(Game& game, Entity& collider, Collision collision, Direction dir); std::list left_collisions; std::list right_collisions; diff --git a/src/renderer.cpp b/src/renderer.cpp index cf6b2bd..f01d72a 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -613,7 +613,7 @@ void Texture::fill(Rectangle dstrect, int r, int g, int b) glDeleteBuffers(1, &vertexbuffer); } -void Texture::blit(Texture& srctex, Rectangle srcrect, Rectangle dstrect) +void Texture::blit(const Texture& srctex, Rectangle srcrect, Rectangle dstrect) { if (!rendererInitialized) { @@ -710,7 +710,7 @@ void bloomPass1(GLuint srcTex, GLuint dstTex, bool horizontal, glm::vec2 srcRes, glDisableVertexAttribArray(0); } -void Texture::renderScreen() +void Texture::renderScreen() const { if (!rendererInitialized) { @@ -851,7 +851,7 @@ void Texture::renderScreen() curBuf = (curBuf + 1) % 2; } -Rectangle Texture::entirety() +Rectangle Texture::entirety() const { return {0, 0, width, height}; } diff --git a/src/renderer.h b/src/renderer.h index 509e935..377b9ee 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -21,9 +21,9 @@ class Texture { Texture& operator= (Texture tex); friend void swap(Texture& tex1, Texture& tex2); void fill(Rectangle loc, int r, int g, int b); - void blit(Texture& src, Rectangle srcrect, Rectangle dstrect); - void renderScreen(); - Rectangle entirety(); + void blit(const Texture& src, Rectangle srcrect, Rectangle dstrect); + void renderScreen() const; + Rectangle entirety() const; private: GLuint texID; -- cgit 1.4.1