Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Game.h"
- #include <SFML/Graphics.hpp>
- #include <SFML/System.hpp>
- #include <SFML/Window.hpp>
- #include <SFML/Audio.hpp>
- #include <SFML/Network.hpp>
- //if there isn't a comment then don't fuck with it
- void Game::initVariables()
- {
- this->window = nullptr;
- }
- void Game::initWindow()
- {
- this->vidMode.height = 480;
- this->vidMode.width = 640;
- this->window = new sf::RenderWindow(this->vidMode, "gaymer time", sf::Style::Close | sf::Style::Titlebar | sf::Style::Resize);
- this->window->setFramerateLimit(60);
- }
- void Game::initEntities()
- {
- sf::RectangleShape Player;
- }
- Game::Game()
- {
- this->initVariables();
- this->initWindow();
- this->initEntities();
- }
- Game::~Game()
- {
- delete this->window;
- }
- const bool Game::isRunning() const
- {
- return this->window->isOpen();
- }
- void Game::spawnEntities()
- {
- }
- void Game::pollEvents()
- {
- while (this->window->pollEvent(this->event)) //Does sumthin idk
- {
- switch (this->event.type)
- {
- case sf::Event::Closed:
- this->window->close();
- break;
- case sf::Event::KeyPressed:
- if (event.key.code == sf::Keyboard::Escape)
- this->window->close();
- break;
- }
- }
- }
- void Game::updateMousePositions()
- {
- this->mousePosWindow = sf::Mouse::getPosition(*this->window);
- this->mousePosWindowX = sf::Mouse::getPosition(*this->window).x;
- this->mousePosWindowY = sf::Mouse::getPosition(*this->window).y;
- }
- void Game::updateEntities()
- {
- //Enemies
- //Player
- //Edits rectangleShape Player's properties
- this->Player.setPosition(mousePosWindowX - 5, mousePosWindowY - 5); //Remember to set this to half of the dementions of the shape
- this->Player.setSize(sf::Vector2f(10.f, 10.f));
- this->Player.setFillColor(sf::Color::Magenta);
- }
- //Functions
- void Game::update()//Updates game (does the actual gamer stuff)
- {
- this->pollEvents();
- this->updateMousePositions();
- this->updateEntities();
- }
- void Game::renderEntities()
- {
- //Enemies
- this->window->draw(this->Player);
- //Player
- }
- void Game::render()//Renders game (just puts the pixels on the screen)
- {
- this->window->clear(); //Clear old frame
- //Draw new frame
- this->renderEntities();
- this->window->display(); //Displays new frame
- }
Add Comment
Please, Sign In to add comment