Guest User

Untitled

a guest
May 3rd, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. Game.h
  2. ------------------------------------------------------------------------------------------------------------------
  3. #pragma once
  4. #ifndef Game_Header
  5. #define Game_Header
  6.  
  7.  
  8. #include <SFML/Graphics.hpp>
  9. #include <SFML/Audio.hpp>
  10. #include "Character.h"
  11. #include "FloorPlatform.h"
  12.  
  13. class Game
  14. {
  15. public:
  16.     Game();
  17.     ~Game();
  18.     int Run();
  19.     void HandleKeyPressed(sf::Keyboard::Key);
  20.     Character MyCharacter;
  21. };
  22.  
  23. #endif // !Game_Header
  24.  
  25.  
  26.  
  27.  
  28. --------------------------------------------------------------------------------
  29. Game.cpp
  30. --------------------------------------------------------------------------------
  31. #include "Game.h"
  32.  
  33.  
  34. Game::Game()
  35. {
  36. }
  37.  
  38.  
  39. Game::~Game()
  40. {
  41. }
  42.  
  43. int Run(){
  44.     sf::RenderWindow MainGameWindow(sf::VideoMode::getDesktopMode(), "A Test Game");
  45.  
  46.     sf::Event event;
  47.     bool bGamePaused = false;
  48.     FloorPlatform Platform;
  49.  
  50.    
  51.  
  52.     //Start Game Loop
  53.     while (MainGameWindow.isOpen()){
  54.         while (MainGameWindow.pollEvent(event)){
  55.             if (event.type == sf::Event::Closed){
  56.                 MainGameWindow.close();
  57.             }
  58.             if (event.type == sf::Event::GainedFocus && bGamePaused == true){
  59.                 //bGamePaused == false;
  60.             }
  61.             if (event.type == sf::Event::LostFocus){
  62.                 bGamePaused = true;
  63.             }
  64.             if (event.type == sf::Event::KeyPressed){
  65.                 HandleKeyPressed(event.key.code);
  66.             }
  67.         }
  68.  
  69.  
  70.         MainGameWindow.clear(sf::Color::White);
  71.  
  72.         MyCharacter.Instance.Circle.setPosition(MyCharacter.PlayerLocation);
  73.         MainGameWindow.draw(MyCharacter.Instance.Circle);
  74.         MainGameWindow.draw(Platform.Shape);
  75.        
  76.         MainGameWindow.display();
  77.  
  78.     }
  79.  
  80.     return 0;
  81. }
  82.  
  83. void HandleKeyPressed(sf::Keyboard::Key PressedKey){
  84.     switch (PressedKey)
  85.     {
  86.     case sf::Keyboard::Unknown:
  87.     break;
  88.     case sf::Keyboard::A:
  89.         MyCharacter.PlayerLocation.x -= 16;
  90.     break;
  91.     case sf::Keyboard::D:
  92.         MyCharacter.PlayerLocation.x += 16;
  93.     break;
  94.     case sf::Keyboard::S:
  95.         MyCharacter.PlayerLocation.y += 16;
  96.     break;
  97.     case sf::Keyboard::W:
  98.         MyCharacter.PlayerLocation.y -= 16;
  99.     break;
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment