1
General / Pure Virtual Function call
« on: June 15, 2009, 10:53:45 pm »
I think it's 3.4.5
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
/* Player.h*/
class Player
{
public:
/* Constructeur */
Player(int r_numero = 1);
/* Accesseur */
const sf::Sprite& Player::getSprite();
private:
/* Atributs */
int numero;
sf::Image image;
sf::Sprite sprite;
};
/* Playe.cpp */
Player::Player(int r_numero) : numero(r_numero)
{
image.LoadFromFile("bar.bmp");
sprite.SetImage(image);
sprite.SetPosition(200, 100);
}
const sf::Sprite& Player::getSprite()
{
return sprite;
}
/*balle.h */
class Balle
{
public:
/* Constructeur */
Balle();
/* Accesseur */
const sf::Sprite& Balle::getSprite();
private:
/* Atributs */
sf::Image image;
sf::Sprite sprite;
};
/*balle.h*/
#include "balle.h"
Balle::Balle()
{
image.LoadFromFile("balle.png");
sprite.SetImage(image);
sprite.SetPosition(400, 300);
}
const sf::Sprite& Balle::getSprite()
{
return sprite;
}
/* main.cpp */
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include "Player.h"
#include "balle.h"
int main()
{
sf::RenderWindow App(sf::VideoMode(900, 575), "Pong!");
App.SetFramerateLimit(60);
sf::Event Event;
sf::Image imgFond;
imgFond.LoadFromFile("fond.png");
sf::Sprite fond;
fond.SetImage(imgFond);
fond.SetPosition(0,0);
Player player1(1);
Balle balle;
while (App.IsOpened())
{
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
App.Clear();
App.Draw(fond);
App.Draw( player1.getSprite() );
App.Draw( balle.getSprite() );
App.Display();
}
return EXIT_SUCCESS;
}