-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.cpp
56 lines (45 loc) · 1016 Bytes
/
game.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
#include "headers/game.h"
Game::Game()
{
mWindow->CreateWindow();
mInput->CreateInstance();
mSnake = new Snake();
mCoin = new Coin(5,5);
mSnake->SetCoin(mCoin);
Update();
}
void Game::Render()
{
glClearColor( 0.1f, 0.4f, 0.4f, 1.f );
//Clear color buffer
glClear( GL_COLOR_BUFFER_BIT );
mSnake->Render();
if(mCoin->IsDetectable())
mCoin->Render();
glfwSwapBuffers(Window::GetWindow()->GetGLFWWindow());
// SDL_GL_SwapBuffers();
}
void Game::Update()
{
while(!glfwWindowShouldClose(Window::GetWindow()->GetGLFWWindow()))
{
double lCurrentFrame = glfwGetTime();
mDeltaTime = lCurrentFrame - mLastFrame;
mLastFrame = lCurrentFrame;
HandleInput();
mSnake->Update(mDeltaTime);
mCoin->Update(mDeltaTime);
Render();
//std::cout << 1/mDeltaTime << std::endl;
}
glfwTerminate();
}
void Game::HandleInput()
{
glfwPollEvents();
}
Game::~Game()
{
delete mSnake;
delete mCoin;
}