Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. PentrisGame.h
  2.  
  3. #pragma once
  4.  
  5. #include <SFML/Graphics.hpp>
  6. #include "Block.h"
  7.  
  8. namespace Pentris
  9. {
  10.  
  11.     class PentrisGame
  12.     {
  13.  
  14.     public:
  15.  
  16.         PentrisGame();
  17.         ~PentrisGame();
  18.  
  19.         void Update(sf::RenderWindow&);
  20.  
  21.     private:
  22.  
  23.         sf::RenderWindow window;
  24.         sf::Texture bgTexture;
  25.         sf::Sprite bgSprite;
  26.         Block b;
  27.  
  28.         void Draw(sf::RenderWindow&);
  29.  
  30.     };
  31.  
  32. }
  33.  
  34. ----
  35.  
  36. PentrisGame.cpp
  37.  
  38. #include "PentrisGame.h"
  39.  
  40. namespace Pentris
  41. {
  42.  
  43.     PentrisGame::PentrisGame()
  44.     {
  45.  
  46.         sf::RenderWindow window(sf::VideoMode(1280, 720), "Pentris");
  47.         bgTexture.loadFromFile("Background.png");
  48.         bgSprite.setTexture(bgTexture);
  49.         bgSprite.setPosition(0.0f, 0.0f);
  50.  
  51.         Block b(sf::Vector2i(96, 32), sf::Color(222, 14, 14, 128));
  52.  
  53.         while (window.isOpen())
  54.         {
  55.  
  56.             sf::Event event;
  57.             while (window.pollEvent(event))
  58.             {
  59.  
  60.                  if (event.type == sf::Event::Closed)
  61.                  {
  62.  
  63.                      window.close();
  64.  
  65.                  }
  66.  
  67.             }
  68.  
  69.             Update(window);
  70.  
  71.         }
  72.  
  73.     }
  74.  
  75.     PentrisGame::~PentrisGame()
  76.     {
  77.  
  78.         window.close();
  79.  
  80.     }
  81.  
  82.     void PentrisGame::Update(sf::RenderWindow& w)
  83.     {
  84.  
  85.         b.Update(w);
  86.  
  87.         Draw(w);
  88.  
  89.     }
  90.  
  91.     void PentrisGame::Draw(sf::RenderWindow& w)
  92.     {
  93.  
  94.         w.clear();
  95.  
  96.         w.draw(bgSprite);
  97.  
  98.         b.Draw(w);
  99.  
  100.         w.display();
  101.  
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement