-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
70 lines (56 loc) · 1.7 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <SFML/Graphics.hpp>
#include <Windows.h>
#include <iostream>
#include "WordsDatabase.h"
#include "Game.h"
//Constant Game Speed indepenent of Variable FPS Game Loop implementation
//USING: http://www.koonsolo.com/news/dewitters-gameloop/
//TICKS_PER_SECOND = Update Speed
const int TICKS_PER_SECOND = 60;
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 5;
//int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
int main()
{
//Initialize variables to regulate update speed
sf::Clock clock;
int nextGameTick = clock.getElapsedTime().asMilliseconds();
int loops;
float interpolation;
//--------------------------------------------
WordsDatabase wd(eEASY);
Game mGame();
std::cout << wd.GetBoss();
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "TCSU!");
while (window.isOpen())
{
window.clear();
loops = 0;
//input here
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::TextEntered)
{
if (event.text.unicode < 128)
std::cout << static_cast<char>(event.text.unicode);
}
}
//controls update speed
while (clock.getElapsedTime().asMilliseconds() > nextGameTick && loops < MAX_FRAMESKIP)
{
//std::cout << wd.GetBoss() + "\n";
//updates here
nextGameTick += SKIP_TICKS;
loops++;
}
//calculate interpolation to (try to) smooth rendering between update
interpolation = float(clock.getElapsedTime().asMilliseconds() + SKIP_TICKS - nextGameTick)
/ float(SKIP_TICKS);
//draw methods here
window.display();
}
return 0;
}