Guest User

Game.cpp

a guest
Sep 9th, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include <iostream>
  2. #include "Game.h"
  3. #include <SFML/Graphics.hpp>
  4. #include <SFML/System.hpp>
  5. #include <SFML/Window.hpp>
  6. #include <SFML/Audio.hpp>
  7. #include <SFML/Network.hpp>
  8.  
  9. //if there isn't a comment then don't fuck with it
  10.  
  11. void Game::initVariables()
  12. {
  13.     this->window = nullptr;
  14. }
  15.  
  16. void Game::initWindow()
  17. {
  18.     this->vidMode.height = 480;
  19.     this->vidMode.width = 640;
  20.     this->window = new sf::RenderWindow(this->vidMode, "gaymer time", sf::Style::Close | sf::Style::Titlebar | sf::Style::Resize);
  21.     this->window->setFramerateLimit(60);
  22. }
  23.  
  24. void Game::initEntities()
  25. {
  26.     sf::RectangleShape Player;
  27. }
  28.  
  29. Game::Game()
  30. {
  31.     this->initVariables();
  32.     this->initWindow();
  33.     this->initEntities();
  34. }
  35.  
  36. Game::~Game()
  37. {
  38.     delete this->window;
  39. }
  40.  
  41. const bool Game::isRunning() const
  42. {
  43.     return this->window->isOpen();
  44. }
  45.  
  46. void Game::spawnEntities()
  47. {
  48.    
  49. }
  50.  
  51. void Game::pollEvents()
  52. {
  53.     while (this->window->pollEvent(this->event)) //Does sumthin idk
  54.     {
  55.         switch (this->event.type)
  56.         {
  57.         case sf::Event::Closed:
  58.             this->window->close();
  59.             break;
  60.         case sf::Event::KeyPressed:
  61.             if (event.key.code == sf::Keyboard::Escape)
  62.                 this->window->close();
  63.             break;
  64.         }
  65.     }
  66. }
  67.  
  68. void Game::updateMousePositions()
  69. {
  70.     this->mousePosWindow = sf::Mouse::getPosition(*this->window);
  71.     this->mousePosWindowX = sf::Mouse::getPosition(*this->window).x;
  72.     this->mousePosWindowY = sf::Mouse::getPosition(*this->window).y;
  73. }
  74.  
  75. void Game::updateEntities()
  76. {
  77.     //Enemies
  78.    
  79.  
  80.     //Player
  81.     //Edits rectangleShape Player's properties
  82.     this->Player.setPosition(mousePosWindowX - 5, mousePosWindowY - 5); //Remember to set this to half of the dementions of the shape
  83.     this->Player.setSize(sf::Vector2f(10.f, 10.f));
  84.     this->Player.setFillColor(sf::Color::Magenta);
  85. }
  86.  
  87. //Functions
  88. void Game::update()//Updates game (does the actual gamer stuff)
  89. {
  90.     this->pollEvents();
  91.     this->updateMousePositions();
  92.     this->updateEntities();
  93. }
  94.  
  95. void Game::renderEntities()
  96. {
  97.     //Enemies
  98.     this->window->draw(this->Player);
  99.    
  100.     //Player
  101.  
  102. }
  103.  
  104. void Game::render()//Renders game (just puts the pixels on the screen)
  105. {
  106.     this->window->clear(); //Clear old frame
  107.  
  108.     //Draw new frame
  109.     this->renderEntities();
  110.  
  111.     this->window->display(); //Displays new frame
  112. }
  113.  
Add Comment
Please, Sign In to add comment