Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SFML/Graphics.hpp>
- #include <SFML/System.hpp>
- using namespace std;
- using namespace sf;
- #define CANTIDAD_OBJETOS 1
- #include "Dummy.h"
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");
- GameObject *obj = new Dummy;
- //game loop
- while (window.isOpen())
- {
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- window.clear();
- obj->draw(window);
- window.display();
- }
- return 0;
- }
- #ifndef GAME_OBJECT_H
- #define GAME_OBJECT_H
- #include <SFML/Graphics.hpp>
- class GameObject
- {
- public:
- virtual ~GameObject();
- virtual void update(sf::Event &evento)=0;
- virtual void draw(sf::RenderWindow &ventana)=0;
- protected:
- static int id;
- sf::Vector2f posicion;
- sf::Vector2f direccion;
- float velocidad;
- sf::Drawable * body;
- };
- #endif
- #ifndef DUMMY_H
- #define DUMMY_H
- #include <iostream>
- #include <SFML/Graphics.hpp>
- #include <SFML/Window.hpp>
- #include "GameObject.h"
- using namespace std;
- class Dummy : public GameObject
- {
- public:
- Dummy();
- virtual ~Dummy();
- void update(sf::Event &evento);
- void draw(sf::RenderWindow &ventana);
- };
- //#include "Dummy.cpp"
- #endif /* DUMMY_H */
- /*
- * Dummy.cpp
- *
- * Created on: 2/5/2015
- * Author: fenix
- */
- #ifndef DUMMY_CPP
- #define DUMMY_CPP
- #include "Dummy.h"
- Dummy::Dummy()
- {
- sf::Vector2f vec(200,200);
- posicion = vec;
- sf::Texture textura;
- if(!textura.loadFromFile("recursos/sodium.png"))
- {
- cout << "Failed loading file 'recursos/sodium.png'" << endl;
- }
- sf::Sprite sprite;
- sprite.setTexture(textura);
- sprite.setPosition(posicion);
- this->body = &sprite;
- }
- Dummy::~Dummy()
- {
- // TODO Auto-generated destructor stub
- }
- void Dummy::update(sf::Event &evento)
- {
- }
- void Dummy::draw(sf::RenderWindow &ventana)
- {
- ventana.draw(*body);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement