63 if(!self->mSprites || !self->mSprites)
67 if(self->mPosition.x + self->mSprites[0]->mSize.x < other->mPosition.x || self->mPosition.y + self->mSprites[0]->mSize.y < other->mPosition.y
68 || self->mPosition.x > other->mPosition.x + other->mSprites[0]->mSize.x || self->mPosition.y > other->mPosition.y + other->mSprites[0]->mSize.y)
77 vec2_t self_min, self_max, self_res, other_min, other_max, other_res;
78 int left, right, bottom, top;
81 self->Touch(
self, other, other->mCollisionType);
85 other->Touch(other,
self, self->mCollisionType);
87 if(strcmp(self->mName, other->mName))
89 printf(
"%s collided with %s \n", self->mName, other->mName);
91 self_min =
self->mPosition;
92 Vec2Add(&self->mPosition, &self->mSprites[0]->mSize, &self_max);
93 other_min = other->mPosition;
94 Vec2Add(&other->mPosition, &other->mSprites[0]->mSize, &other_max);
96 left = other_min.
x - self_max.
x;
97 right = other_max.
x - self_min.
x;
98 top = other_min.
y - self_max.
y;
99 bottom = other_max.
y - self_min.
y;
100 if(abs(left) < right)
110 if(abs(top) < bottom)
113 other_res.
y = bottom;
120 if(abs(self_res.
x) < abs(self_res.
y))
128 if(abs(other_res.
x) < abs(other_res.
y))
138 Vec2Add(&self->mPosition, &self_res, &self->mPosition);
141 self->mVelocity.x = -
self->mVelocity.x/2;
144 self->mVelocity.y = -
self->mVelocity.y/2;
149 Vec2Add(&other->mPosition, &other_res, &other->mPosition);
152 other->mVelocity.x = -
self->mVelocity.x/2;
155 other->mVelocity.y = -
self->mVelocity.y/2;
170 if(ent->mPosition.x < 0)
172 ent->mPosition.x = 0;
173 ent->mVelocity.x = 0;
178 ent->mVelocity.x = 0;
181 if(ent->mPosition.y < 0)
183 ent->mPosition.y = 0;
184 ent->mVelocity.y = 0;
189 ent->mVelocity.y = 0;
void ApplyFriction(vec2_t *a)
int CheckCollision(entity_t *self, entity_t *other)
void ApplyBounds(entity_t *ent)
void DoCollision(entity_t *self, entity_t *other)
void Vec2Add(vec2_t *A, vec2_t *B, vec2_t *C)
void ApplySpeedLimit(vec2_t *a)