Advertisement
Guest User

Untitled

a guest
May 2nd, 2015
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <SFML/Graphics.hpp>
  3. #include <SFML/System.hpp>
  4.  
  5. using namespace std;
  6. using namespace sf;
  7.  
  8. #define CANTIDAD_OBJETOS  1
  9.  
  10.  
  11. #include "Dummy.h"
  12.  
  13. int main()
  14. {
  15.     sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");
  16.  
  17.     GameObject *obj = new Dummy;
  18.  
  19.     //game loop
  20.     while (window.isOpen())
  21.     {
  22.         sf::Event event;
  23.         while (window.pollEvent(event))
  24.         {
  25.             if (event.type == sf::Event::Closed)
  26.                 window.close();
  27.         }
  28.         window.clear();
  29.         obj->draw(window);
  30.         window.display();
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  
  36. #ifndef GAME_OBJECT_H
  37. #define GAME_OBJECT_H
  38.  
  39. #include <SFML/Graphics.hpp>
  40.  
  41. class GameObject
  42. {
  43.     public:
  44.  
  45.         virtual ~GameObject();
  46.  
  47.         virtual void update(sf::Event &evento)=0;
  48.  
  49.         virtual void draw(sf::RenderWindow &ventana)=0;
  50.  
  51.     protected:
  52.         static int id;
  53.         sf::Vector2f posicion;
  54.         sf::Vector2f direccion;
  55.         float velocidad;
  56.         sf::Drawable * body;
  57. };
  58.  
  59. #endif
  60.  
  61.  
  62. #ifndef DUMMY_H
  63. #define DUMMY_H
  64.  
  65. #include <iostream>
  66. #include <SFML/Graphics.hpp>
  67. #include <SFML/Window.hpp>
  68. #include "GameObject.h"
  69.  
  70. using namespace std;
  71.  
  72. class Dummy : public GameObject
  73. {
  74. public:
  75.     Dummy();
  76.     virtual ~Dummy();
  77.     void update(sf::Event &evento);
  78.     void draw(sf::RenderWindow &ventana);
  79. };
  80.  
  81.  
  82. //#include "Dummy.cpp"
  83.  
  84.  
  85.  
  86. #endif /* DUMMY_H */
  87.  
  88.  
  89.  
  90. /*
  91.  * Dummy.cpp
  92.  *
  93.  *  Created on: 2/5/2015
  94.  *      Author: fenix
  95.  */
  96. #ifndef DUMMY_CPP
  97. #define DUMMY_CPP
  98.  
  99. #include "Dummy.h"
  100.  
  101. Dummy::Dummy()
  102. {
  103.     sf::Vector2f vec(200,200);
  104.     posicion = vec;
  105.  
  106.     sf::Texture textura;
  107.  
  108.     if(!textura.loadFromFile("recursos/sodium.png"))
  109.         {
  110.             cout << "Failed loading file 'recursos/sodium.png'" << endl;
  111.         }
  112.  
  113.         sf::Sprite sprite;
  114.         sprite.setTexture(textura);
  115.         sprite.setPosition(posicion);
  116.  
  117.         this->body = &sprite;
  118.     }
  119.  
  120.     Dummy::~Dummy()
  121.     {
  122.         // TODO Auto-generated destructor stub
  123.     }
  124.  
  125.     void Dummy::update(sf::Event &evento)
  126.     {
  127.  
  128.     }
  129.  
  130.     void Dummy::draw(sf::RenderWindow &ventana)
  131.     {
  132.  
  133.         ventana.draw(*body);
  134.     }
  135.  
  136.  
  137. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement