Example #1
0
void MoveComponent::update() {
	setSpeed();
	collide();
	
	// Stamp on the ground.
	Boxf characterFeet = Boxf(
	  Vec2(_puppet->worldBox().min().x() + TILESIZE / 3.0,
	       _puppet->worldBox().max().y() + 0.1 * COLLISION_DELTA),
	  Vec2(_puppet->worldBox().max().x() - TILESIZE / 3.0,
	       _puppet->worldBox().max().y() + 0.9 * COLLISION_DELTA));
	
	CollisionList intersections = _obj->scene()->level().collide(0, characterFeet);
	float amount = 0.0;
	
	for (Boxf collision: intersections)
		amount += collision.volume();
	
	if (amount > 0.9 * characterFeet.volume())
		_airTime = 0;
	else if (!_airTime && !_ladder)
		_airTime = 1;
	
	// Check ladder.
	if (!onLadder())
		_ladder = false;
}
Example #2
0
bool MoveComponent::onLadder() {
	Boxf characterFeet = Boxf(
	  Vec2(_puppet->worldBox().min().x() + TILESIZE / 3.0,
	       _puppet->worldBox().max().y() - 1.9 * COLLISION_DELTA),
	  Vec2(_puppet->worldBox().max().x() - TILESIZE / 3.0,
	       _puppet->worldBox().max().y() - 1.1 * COLLISION_DELTA));
	
	CollisionList intersections = _obj->scene()->level().collide(1, characterFeet, true);
	float amount = 0.0;
	
	for (Boxf collision: intersections)
		amount += collision.volume();
	
	if (amount > 0.6 * characterFeet.volume())
		return true;
	return false;
}