summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/components.cpp30
-rw-r--r--src/components.h2
-rw-r--r--src/renderer.cpp6
-rw-r--r--src/renderer.h6
4 files changed, 32 insertions, 12 deletions
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
395 if ((fixed_oy+collider.size.second > collision.lower) && (fixed_oy < collision.upper)) 395 if ((fixed_oy+collider.size.second > collision.lower) && (fixed_oy < collision.upper))
396 { 396 {
397 // We have a collision! 397 // We have a collision!
398 processCollision(game, collider, collision, Direction::left); 398 if (processCollision(game, collider, collision, Direction::left))
399 {
400 collider.position.second = old_position.second;
401
402 return;
403 }
399 404
400 break; 405 break;
401 } 406 }
@@ -410,7 +415,12 @@ void MapCollisionComponent::detectCollision(Game& game, Entity&, Entity& collide
410 if ((fixed_oy+collider.size.second > collision.lower) && (fixed_oy < collision.upper)) 415 if ((fixed_oy+collider.size.second > collision.lower) && (fixed_oy < collision.upper))
411 { 416 {
412 // We have a collision! 417 // We have a collision!
413 processCollision(game, collider, collision, Direction::right); 418 if (processCollision(game, collider, collision, Direction::right))
419 {
420 collider.position.second = old_position.second;
421
422 return;
423 }
414 424
415 break; 425 break;
416 } 426 }
@@ -430,7 +440,10 @@ void MapCollisionComponent::detectCollision(Game& game, Entity&, Entity& collide
430 if ((fixed_x+collider.size.first > collision.lower) && (fixed_x < collision.upper)) 440 if ((fixed_x+collider.size.first > collision.lower) && (fixed_x < collision.upper))
431 { 441 {
432 // We have a collision! 442 // We have a collision!
433 processCollision(game, collider, collision, Direction::up); 443 if (processCollision(game, collider, collision, Direction::up))
444 {
445 return;
446 }
434 447
435 break; 448 break;
436 } 449 }
@@ -445,7 +458,10 @@ void MapCollisionComponent::detectCollision(Game& game, Entity&, Entity& collide
445 if ((fixed_x+collider.size.first > collision.lower) && (fixed_x < collision.upper)) 458 if ((fixed_x+collider.size.first > collision.lower) && (fixed_x < collision.upper))
446 { 459 {
447 // We have a collision! 460 // We have a collision!
448 processCollision(game, collider, collision, Direction::down); 461 if (processCollision(game, collider, collision, Direction::down))
462 {
463 return;
464 }
449 465
450 break; 466 break;
451 } 467 }
@@ -453,7 +469,7 @@ void MapCollisionComponent::detectCollision(Game& game, Entity&, Entity& collide
453 } 469 }
454} 470}
455 471
456void MapCollisionComponent::processCollision(Game& game, Entity& collider, Collision collision, Direction dir) 472bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Collision collision, Direction dir)
457{ 473{
458 if (collision.type == 0) 474 if (collision.type == 0)
459 { 475 {
@@ -508,6 +524,8 @@ void MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli
508 collider.position.first = -collider.size.first/2; 524 collider.position.first = -collider.size.first/2;
509 game.loadMap(*rightMap); 525 game.loadMap(*rightMap);
510 } 526 }
527
528 return true;
511 } else if (collision.type == 3) 529 } else if (collision.type == 3)
512 { 530 {
513 if (dir == Direction::right) 531 if (dir == Direction::right)
@@ -524,4 +542,6 @@ void MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli
524 542
525 collider.send(game, msg); 543 collider.send(game, msg);
526 } 544 }
545
546 return false;
527} 547}
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 {
83 }; 83 };
84 84
85 void addCollision(int axis, int lower, int upper, Direction dir, int type); 85 void addCollision(int axis, int lower, int upper, Direction dir, int type);
86 void processCollision(Game& game, Entity& collider, Collision collision, Direction dir); 86 bool processCollision(Game& game, Entity& collider, Collision collision, Direction dir);
87 87
88 std::list<Collision> left_collisions; 88 std::list<Collision> left_collisions;
89 std::list<Collision> right_collisions; 89 std::list<Collision> 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)
613 glDeleteBuffers(1, &vertexbuffer); 613 glDeleteBuffers(1, &vertexbuffer);
614} 614}
615 615
616void Texture::blit(Texture& srctex, Rectangle srcrect, Rectangle dstrect) 616void Texture::blit(const Texture& srctex, Rectangle srcrect, Rectangle dstrect)
617{ 617{
618 if (!rendererInitialized) 618 if (!rendererInitialized)
619 { 619 {
@@ -710,7 +710,7 @@ void bloomPass1(GLuint srcTex, GLuint dstTex, bool horizontal, glm::vec2 srcRes,
710 glDisableVertexAttribArray(0); 710 glDisableVertexAttribArray(0);
711} 711}
712 712
713void Texture::renderScreen() 713void Texture::renderScreen() const
714{ 714{
715 if (!rendererInitialized) 715 if (!rendererInitialized)
716 { 716 {
@@ -851,7 +851,7 @@ void Texture::renderScreen()
851 curBuf = (curBuf + 1) % 2; 851 curBuf = (curBuf + 1) % 2;
852} 852}
853 853
854Rectangle Texture::entirety() 854Rectangle Texture::entirety() const
855{ 855{
856 return {0, 0, width, height}; 856 return {0, 0, width, height};
857} 857}
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 {
21 Texture& operator= (Texture tex); 21 Texture& operator= (Texture tex);
22 friend void swap(Texture& tex1, Texture& tex2); 22 friend void swap(Texture& tex1, Texture& tex2);
23 void fill(Rectangle loc, int r, int g, int b); 23 void fill(Rectangle loc, int r, int g, int b);
24 void blit(Texture& src, Rectangle srcrect, Rectangle dstrect); 24 void blit(const Texture& src, Rectangle srcrect, Rectangle dstrect);
25 void renderScreen(); 25 void renderScreen() const;
26 Rectangle entirety(); 26 Rectangle entirety() const;
27 27
28 private: 28 private:
29 GLuint texID; 29 GLuint texID;