void SpaceInvadersDemo::init()
{
shipImage.LoadFromFile("myC++/images/asprite1.png");
shipImage2.LoadFromFile("myC++/images/asprite2.png");
shipSprite=sf::Sprite(shipImage), (shipImage2);
shipSprite.SetCenter(shipSprite.GetSize().x/2,shipSprite.GetSize().y/2);
s.setRadius(shipSprite.GetSize().x/2);
s.setPosX(width/2);s.setPosY(height/10);
}
void SpaceInvadersDemo::draw()
{
win.Clear(sf::Color(0,0,0));
shipSprite.SetPosition(s.getPosX(),s.getPosY());
win.Draw(shipSprite);
}
void SpaceInvadersDemo::getInput()
{
sf::Event Event;
while (win.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
win.Close();
//Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
win.Close();
}
}
void SpaceInvadersDemo::update()
{
sf::Clock Clock;
if (Clock.GetElapsedTime()>=Timestep)
{
shipSprite.SetImage(shipImage2);
s.setPosX(s.getPosX()+moveIncrement);
Clock.Reset();
}
void SpaceInvadersDemo::play()
{
//the game loop
draw();//the offscreen buffer
getInput();//from the user
update();//integrate user input and any game movement which is automatic
}