Hertog is now in the game dear god
parent
59560ced66
commit
fce1de6303
|
@ -12,7 +12,8 @@ class Game
|
|||
|
||||
private:
|
||||
sf::RenderWindow mWindow;
|
||||
sf::CircleShape mPlayer;
|
||||
sf::Texture mTexture;
|
||||
sf::Sprite mPlayer;
|
||||
|
||||
bool mIsMovingUp{false};
|
||||
bool mIsMovingDown{false};
|
||||
|
|
|
@ -6,22 +6,22 @@ const sf::Time Game::TimePerFrame = sf::seconds(1.f/60.f);
|
|||
|
||||
Game::Game()
|
||||
: mWindow(sf::VideoMode(640, 480), "SFML Application")
|
||||
, mPlayer()
|
||||
{
|
||||
mPlayer.setRadius(40.f);
|
||||
, mTexture()
|
||||
, mPlayer() {
|
||||
if(!mTexture.loadFromFile("Assets/blobcat_hertog.png")) {
|
||||
// Handle loading errors
|
||||
}
|
||||
mPlayer.setTexture(mTexture);
|
||||
mPlayer.setScale(0.25f, 0.25f);
|
||||
mPlayer.setPosition(100.f, 100.f);
|
||||
mPlayer.setFillColor(sf::Color::Cyan);
|
||||
}
|
||||
void Game::run()
|
||||
{
|
||||
void Game::run() {
|
||||
sf::Clock clock;
|
||||
sf::Time timeSinceLastUpdate = sf::Time::Zero;
|
||||
while (mWindow.isOpen())
|
||||
{
|
||||
while (mWindow.isOpen()) {
|
||||
processEvents();
|
||||
timeSinceLastUpdate += clock.restart();
|
||||
while (timeSinceLastUpdate > TimePerFrame)
|
||||
{
|
||||
while (timeSinceLastUpdate > TimePerFrame) {
|
||||
timeSinceLastUpdate -= TimePerFrame;
|
||||
processEvents();
|
||||
update(TimePerFrame);
|
||||
|
@ -30,13 +30,10 @@ void Game::run()
|
|||
}
|
||||
}
|
||||
|
||||
void Game::processEvents()
|
||||
{
|
||||
void Game::processEvents() {
|
||||
sf::Event event;
|
||||
while (mWindow.pollEvent(event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
while (mWindow.pollEvent(event)) {
|
||||
switch (event.type) {
|
||||
//For each time the while loop iterates, it means a new event that was registered by the window is being handled. While there can be many different events, we will only check for some types of events, which are of our interest right now.
|
||||
case sf::Event::KeyPressed:
|
||||
handlePlayerInput(event.key.code, true);
|
||||
|
@ -51,8 +48,7 @@ void Game::processEvents()
|
|||
}
|
||||
}
|
||||
|
||||
void Game::handlePlayerInput(sf::Keyboard::Key key,bool isPressed)
|
||||
{
|
||||
void Game::handlePlayerInput(sf::Keyboard::Key key,bool isPressed) {
|
||||
if (key == sf::Keyboard::W)
|
||||
mIsMovingUp = isPressed;
|
||||
else if (key == sf::Keyboard::S)
|
||||
|
@ -63,8 +59,7 @@ void Game::handlePlayerInput(sf::Keyboard::Key key,bool isPressed)
|
|||
mIsMovingRight = isPressed;
|
||||
}
|
||||
|
||||
void Game::update(sf::Time deltaTime)
|
||||
{
|
||||
void Game::update(sf::Time deltaTime) {
|
||||
sf::Vector2f movement(0.f, 0.f);
|
||||
if (mIsMovingUp)
|
||||
movement.y -= 100.f;
|
||||
|
@ -78,15 +73,13 @@ void Game::update(sf::Time deltaTime)
|
|||
mPlayer.move(movement * deltaTime.asSeconds());
|
||||
}
|
||||
|
||||
void Game::render()
|
||||
{
|
||||
void Game::render() {
|
||||
mWindow.clear();
|
||||
mWindow.draw(mPlayer);
|
||||
mWindow.display();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
Game game;
|
||||
game.run();
|
||||
}
|
Loading…
Reference in New Issue