-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphic.h
164 lines (145 loc) · 4.78 KB
/
graphic.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
Copyright (C) 2016 Meritxell Jordana
Copyright (C) 2016 Marc Sanchez
*/
#ifndef __GRAPHIC_H
#define __GRAPHIC_H
#include "map.h"
#include "particle.h"
#include "tank_particle.h"
#include "strategy.h"
#include <GL/glut.h>
#include <string>
#ifdef ARDUINO
#include "arduino/arduino.h"
#include "texture_loader.h"
#endif
using namespace std;
typedef struct Color {
const GLfloat red;
const GLfloat green;
const GLfloat blue;
const GLfloat alpha;
Color(const GLfloat red, const GLfloat green, const GLfloat blue,
const GLfloat alpha = 1.0);
GLfloat * getArray();
} Color;
typedef struct Size {
const float width;
const float height;
Size(const float width, const float height);
} Size;
typedef struct Point {
const GLfloat x;
const GLfloat y;
const GLfloat z;
Point(const GLfloat x, const GLfloat y, const GLfloat z);
} Point;
void display();
void keyboard(unsigned char c, int x, int y);
void keyboardSpecial(int key, int x, int y);
void idle();
class Graphic {
static const Color backgroundColor;
static const GLfloat* const foodColor;
static const GLfloat* const playerColor;
static const GLfloat* const enemyColor;
static const GLfloat* const tankColor;
static const GLfloat* const tankWeelsColor;
static const GLfloat* const tankCanonColor;
static const GLfloat* const textColor;
static const GLfloat* const headlightColor;
static const GLfloat* const fullColor;
static const GLfloat* const ambientColor;
static const GLfloat* const diffuseColor;
static const GLfloat* const specularColor;
static const GLfloat* const bulletColor;
static const GLfloat* const spotLightColor;
static const char* const gameTitle;
static const Size scoreInfoPosition;
static const double glutRatio;
static const Direction defaultPlayerTankDirection;
static const Direction defaultEnemyTankDirection;
Map* map;
int width;
int height;
int glutWidth;
int glutHeight;
TankParticle playerParticle;
TankParticle enemyParticle;
Particle bulletParticle;
Position *bulletPosition;
long lastTime;
Strategy *enemyStrategy;
Strategy *playerStrategy;
int angleAlpha;
int angleBeta;
bool gameRunning;
bool training;
double speedFactor;
int playerWins;
int enemyWins;
#ifdef ARDUINO
static const Size arduinoInfoPosition;
Arduino *arduino;
Texture waterTexture;
int lastTemperature;
int lastHeartRate;
void arduinoController();
static Texture choiseTextureFromTemperature(int temperatureInCelcius);
void setSpeedFactorFromHeartRate(int heartRate);
void printArduinoInfo();
#endif
Graphic(bool training = false);
Graphic(Graphic const&);
void operator=(Graphic const&);
void playerMove(Direction d);
void printPlayer(int row, int col, TankParticle &particle,
const GLfloat* color, CellType player);
void printBullet(int row, int col, Particle &particle, const GLfloat* color);
void tankShoot();
void enemyMove(Direction d);
public:
static const int cellWidth;
static const int cellHeight;
static const int cellDepth;
static const GLfloat tankWidth;
static const GLfloat tankHeight;
static const GLfloat tankDepth;
static const int foodRadius;
static const GLint sphereSlices;
static const GLint sphereStacks;
static const GLint cylinderSlices;
static const GLint cylinderStacks;
static const long bulletMovementTime;
static Graphic& getInstance();
static Size getTranslation(Direction d);
void setMap(Map& map);
void setGlutDimensions(int width, int height);
void glutInitialize(int *argcp, char **argv);
void glutRun();
void glutDisplay();
void glutKeyboard(unsigned char key, int x, int y);
void glutKeyboardSpecial(int key, int x, int y);
void glutIdle();
int getScreenWidth();
int getScreenHeight();
void drawWall(int row, int col);
void drawFood(int row, int col);
void drawTank(int row, int col, TankParticle &p, const GLfloat* color,
CellType player);
void drawCylinder(const GLfloat* color, Point p, GLdouble radius,
GLdouble height);
void drawSphere(const GLfloat* color, Point p, GLdouble radius);
void drawCube(const GLfloat* color, Point p, GLfloat width, GLfloat height,
GLfloat depth);
void printText(float width, float height, string str);
void printScore(float width, float height);
void initDisplay();
void positionObserver(float alpha, float beta, int radius);
void drawFloor(int row, int col);
void setSpotLight(GLenum light, Point p, const GLfloat* color);
void setTraining(bool training);
void printWins(float width, float height);
};
#endif