1 /* 2 Copyright (C) 2007, 2010 - Bit-Blot 3 4 This file is part of Aquaria. 5 6 Aquaria is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 2 9 of the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 15 See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 #ifndef COLLISION_H 22 #define COLLISION_H 23 24 #include "Base.h" 25 26 class RenderObject; 27 struct CollisionResult 28 { CollisionResultCollisionResult29 CollisionResult() 30 { 31 collided = false; 32 collider = 0; 33 project = true; 34 } 35 bool project; 36 bool collided; 37 Vector overlap; 38 RenderObject *collider; 39 reportCollisionCollisionResult40 void reportCollision(Vector overlap) 41 { 42 collided = true; 43 this->overlap = overlap; 44 } 45 }; 46 47 48 class CollisionShape 49 { 50 public: 51 CollisionShape(); 52 53 /* 54 void addCollisionGroup(int group); 55 void removeCollisionGroup(int group); 56 void canCollideWithGroup(); 57 */ 58 59 void updatePosition(const Vector &position); 60 activate()61 void activate() 62 { 63 active = true; 64 } deactivate()65 void deactivate() 66 { 67 active = false; 68 } 69 isActive()70 bool isActive() 71 { 72 return active; 73 } 74 75 float getX1(); 76 float getX2(); 77 float getY1(); 78 float getY2(); 79 float xw, yw; 80 float radius; 81 82 enum Type { NONE=0, AABB, CIRCLE, TOP_HALF_CIRCLE, TRIANGLE }; 83 84 void setType(Type type); 85 Type getType(); 86 87 88 89 bool isPointWithin(Vector point); 90 void render(); 91 92 CollisionResult findOverlap(CollisionShape &collisionShape); 93 Vector offsetPosition; 94 95 bool compareLayer(CollisionShape &c); 96 //bool compareMask(CollisionShape &c); getLayer()97 int getLayer() { return layer; } setLayer(int layer)98 void setLayer(int layer) { this->layer = layer; } 99 100 bool project; 101 protected: 102 int layer; 103 /* 104 typedef std::vector<int> CollisionLayerMask; 105 CollisionLayerMask colliderMask, collideeMask; 106 */ 107 std::vector<Vector> corners; 108 Vector position; 109 bool active; 110 CollisionResult collideCircleWithCircle(CollisionShape &collisionShape); 111 CollisionResult collideCircleWithTopHalfCircle(CollisionShape &collisionShape); 112 CollisionResult collideCircleWithAABB(CollisionShape &collisionShape, float x, float y, int oH, int oV); 113 114 115 116 Type type; 117 }; 118 119 /* 120 class CollisionObject 121 { 122 public: 123 void onCollision(); 124 void collide() 125 { 126 CollisionResult c; 127 for (int i = 0; i < collisionManager->colliders.size(); i++) 128 { 129 c = findOverlap(collisionManager->colliders[i]->collisionShape); 130 if (c.collided) 131 { 132 position -= c.overlap; 133 collisionShape.position = 134 } 135 } 136 } 137 }; 138 139 class CollisionManager 140 { 141 public: 142 void addCollider( 143 }; 144 */ 145 146 #endif 147