#include "Ball.h"
#include "agk.h"

float const Ball::launch_speed = 600.0f;

Ball::Ball()
{
	sprite = agk::LoadSprite("media/pinball_1.png");
	agk::SetSpritePhysicsOn(sprite, 2);
	agk::SetSpriteShape(sprite, 0);
	agk::AddSpriteShapeCircle(sprite, 0, 0, 16.0f);
	agk::SetSpritePhysicsCanRotate(sprite, 0);
	agk::SetSpritePositionByOffset(sprite, 550.0f, 50.0f);
}

void Ball::launch()
{
	const float angle = static_cast<float>(agk::Random(0, 90));
	const float dir_x = -1.0f * agk::Sin(angle);
	const float dir_y = 1.0f * agk::Cos(angle);
	agk::SetSpritePositionByOffset(sprite, 550.0f, 50.0f);
	agk::SetSpritePhysicsVelocity(sprite, dir_x * launch_speed, dir_y * launch_speed);
}

bool Ball::is_on_screen() const
{
	return agk::GetSpriteY(sprite) < agk::GetVirtualHeight();
}