Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Game.h
- ------------------------------------------------------------------------------------------------------------------
- #pragma once
- #ifndef Game_Header
- #define Game_Header
- #include <SFML/Graphics.hpp>
- #include <SFML/Audio.hpp>
- #include "Character.h"
- #include "FloorPlatform.h"
- class Game
- {
- public:
- Game();
- ~Game();
- int Run();
- void HandleKeyPressed(sf::Keyboard::Key);
- Character MyCharacter;
- };
- #endif // !Game_Header
- --------------------------------------------------------------------------------
- Game.cpp
- --------------------------------------------------------------------------------
- #include "Game.h"
- Game::Game()
- {
- }
- Game::~Game()
- {
- }
- int Run(){
- sf::RenderWindow MainGameWindow(sf::VideoMode::getDesktopMode(), "A Test Game");
- sf::Event event;
- bool bGamePaused = false;
- FloorPlatform Platform;
- //Start Game Loop
- while (MainGameWindow.isOpen()){
- while (MainGameWindow.pollEvent(event)){
- if (event.type == sf::Event::Closed){
- MainGameWindow.close();
- }
- if (event.type == sf::Event::GainedFocus && bGamePaused == true){
- //bGamePaused == false;
- }
- if (event.type == sf::Event::LostFocus){
- bGamePaused = true;
- }
- if (event.type == sf::Event::KeyPressed){
- HandleKeyPressed(event.key.code);
- }
- }
- MainGameWindow.clear(sf::Color::White);
- MyCharacter.Instance.Circle.setPosition(MyCharacter.PlayerLocation);
- MainGameWindow.draw(MyCharacter.Instance.Circle);
- MainGameWindow.draw(Platform.Shape);
- MainGameWindow.display();
- }
- return 0;
- }
- void HandleKeyPressed(sf::Keyboard::Key PressedKey){
- switch (PressedKey)
- {
- case sf::Keyboard::Unknown:
- break;
- case sf::Keyboard::A:
- MyCharacter.PlayerLocation.x -= 16;
- break;
- case sf::Keyboard::D:
- MyCharacter.PlayerLocation.x += 16;
- break;
- case sf::Keyboard::S:
- MyCharacter.PlayerLocation.y += 16;
- break;
- case sf::Keyboard::W:
- MyCharacter.PlayerLocation.y -= 16;
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment