-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·67 lines (57 loc) · 1.3 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
#include <cstdlib>
#include <ctime>
#include "fight.hpp"
#include "bitmaps.hpp"
using namespace std;
using namespace cnv;
void redraw() // glutDisplayFunc
{
fight::draw();
glutSwapBuffers();
}
void tick (int)
{
fight::tick();
glutPostRedisplay();
glutTimerFunc(120, tick, 0);
}
void Mouse (int button, int state, int x, int y) // glutMouseFunc
{
int len = bitmaps::getWindowSize();
x -= max((glutGet(GLUT_WINDOW_WIDTH) - len)/2, 0);
y -= max((glutGet(GLUT_WINDOW_HEIGHT) - len)/2, 0);
if (x < 0 || y < 0 || x > len || y > len) return;
fight::mouse (button, state, x, y);
}
void Keyboard (unsigned char key, int, int) // glutKeyboardFunc
{
fight::keyboard (key);
}
void reshape (int width, int height)
{
int len = min (width, height);
int x = max((width - len)/2, 0);
int y = max((height - len)/2, 0);
glViewport (x, y, len, len);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluOrtho2D (0, len, len, 0); // l, r, b, t
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
bitmaps::setWindowSize (len);
fight::board().redraw();
glutPostRedisplay();
}
int main()
{
window (DEFAULT_WINDOW_SIZE, DEFAULT_WINDOW_SIZE);
glutDisplayFunc (redraw);
glutKeyboardFunc (Keyboard);
glutMouseFunc (Mouse);
glutReshapeFunc (reshape);
srand (time(0));
bitmaps::load();
fight::start();
tick(1);
glutMainLoop();
}