示例#1
0
Vec2f Slime::ride(Vec2f player_pos, Vec2f player_size, Vec2f vec)
{
	if (collisionBox(ride_pos, ride_size, player_pos, player_size)) {
		return Vec2f(player_pos.x(), ride_pos.y() + ride_size.y());
	}
	return player_pos;
}
示例#2
0
void Slime::stan(Vec2f item_pos, Vec2f item_size)
{
	if (collisionBox(pos, size, item_pos, item_size)) {
		stan_flag = true;
	}
	if (stan_flag == true) {
		stan_inc++;
		if (500 >= stan_inc) {
			blind = stan_inc % 2;
		}
		else if (500 <= stan_inc) {
			stan_flag = false;
			stan_inc = 0;
			blind = 0;
			switch (direction)
			{
			case Direction::RIGHT:
				vec_.x() = 0.5f;
				break;
			case Direction::LEFT:
				vec_.x() = -0.5f;
				break;
			}
		}
	}
}
示例#3
0
// Indicates whether the first Object parameter is colliding with the second one.
// Returns 1 if it is, or if it is out of the bounds of the map (=colliding with the external walls), 0 otherwise.
// Both objects are supposed to have the same type (box or cylinder), otherwise 0 may be returned.
int inCollision(Object* obj1, Object* obj2)
{
	// Checks whether the object is out of bounds or not.
	if (obj1->x < -TAILLEBORD || obj1->x > TAILLEBORD) return 1;
	if (obj1->z < -TAILLEBORD || obj1->z > TAILLEBORD) return 1;

	// Call the appropriate collision test function
	if (obj1->type == TYPE_BOX && obj2->type == TYPE_BOX)
		return collisionBox(obj1, obj2);
	else if (obj1->type == TYPE_CYLINDER && obj2->type == TYPE_CYLINDER)
		return collisionCylinder(obj1, obj2);
	return 0;
}