forked from LucaFeggi/PacMan_SDL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
78 lines (62 loc) · 2.01 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
71
72
73
74
75
76
77
78
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <SDL_mixer.h>
#include <cmath>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include "Headers/Globals.hpp"
#include "Headers/Texture.hpp"
#include "Headers/Timer.hpp"
#include "Headers/Position.hpp"
#include "Headers/Entity.hpp"
#include "Headers/Pac.hpp"
#include "Headers/Ghost.hpp"
#include "Headers/Blinky.hpp"
#include "Headers/Inky.hpp"
#include "Headers/Pinky.hpp"
#include "Headers/Clyde.hpp"
#include "Headers/Fruit.hpp"
#include "Headers/Board.hpp"
#include "Headers/Sound.hpp"
#include "Headers/Game.hpp"
//Use arrow keys or WASD to move
int main(int argc, char* args[]){
InitializeSDL();
Game mGame;
Timer GameTimer;
SDL_Event event;
bool quit = false;
unsigned short StartTicks = 4500;
std::vector<unsigned char> mover;
mover.push_back(Right);
GameTimer.Start();
mGame.mSound.PlayIntro();
while(!quit){
uint64_t IterationStart = SDL_GetPerformanceCounter();
while(SDL_PollEvent(&event) != 0){
if(event.type == SDL_QUIT)
quit = true;
if(event.key.state == SDL_PRESSED){
if((event.key.keysym.sym == SDLK_RIGHT || event.key.keysym.sym == SDLK_d)) mover.push_back(Right);
else if((event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_w)) mover.push_back(Up);
else if((event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_a)) mover.push_back(Left);
else if((event.key.keysym.sym == SDLK_DOWN || event.key.keysym.sym == SDLK_s)) mover.push_back(Down);
if(mover.size() > 2)
mover.erase(mover.begin() + 1);
}
}
SDL_RenderClear(renderer);
if(mGame.Process(GameTimer, mover, StartTicks)){
mGame.Draw();
SDL_RenderPresent(renderer);
}
uint64_t IterationEnd = SDL_GetPerformanceCounter();
float elapsedMS = (IterationEnd - IterationStart) / ((float)SDL_GetPerformanceFrequency() * 1000.0f);
SDL_Delay(floor(11.111f - elapsedMS));
}
CloseSDL();
return 0;
}