0% found this document useful (0 votes)
3 views1 page

Main - Копия

The document is a C++ program that implements a simple game loop using a Renderer and KeyboardInput class. It allows a player to move in various directions on a grid based on keyboard input. The player's position is updated and rendered continuously in an infinite loop.

Uploaded by

will.am.4277
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Main - Копия

The document is a C++ program that implements a simple game loop using a Renderer and KeyboardInput class. It allows a player to move in various directions on a grid based on keyboard input. The player's position is updated and rendered continuously in an infinite loop.

Uploaded by

will.am.4277
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include "Renderer.

h"
#include "KeyboardInput.h"
#include <iostream>

int main() {
Renderer renderer(20, 10);
KeyboardInput input;

int playerX = 10;


int playerY = 5;

while (true) {
renderer.clear();
renderer.drawPlayer(playerX, playerY);
renderer.render();

auto direction = input.getDirection();

switch (direction) {
case KeyboardInput::Direction::UP:
playerY--; break;
case KeyboardInput::Direction::DOWN:
playerY++; break;
case KeyboardInput::Direction::LEFT:
playerX--; break;
case KeyboardInput::Direction::RIGHT:
playerX++; break;
case KeyboardInput::Direction::UP_LEFT:
playerY--; playerX--; break;
case KeyboardInput::Direction::UP_RIGHT:
playerY--; playerX++; break;
case KeyboardInput::Direction::DOWN_LEFT:
playerY++; playerX--; break;
case KeyboardInput::Direction::DOWN_RIGHT:
playerY++; playerX++; break;
default:
break;
}
}

return 0;
}

You might also like