/
main.cpp
281 lines (232 loc) · 9.49 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//Graficos
#include "windows.h"
#include "OpenGL.h"
#include "glut.h"
//Standar C++
#include <time.h>
#include <math.h>
#include <iostream>
#include <stdlib.h>
//Recursos de juego
#include "FuncionesIni.h"
#include "Elemento.h"
#include "World.h"
#include "Camera.h"
#include "Interfaz.h"
#include "funciones_inline.h"
#include "Vector.h"
#include "Barco.h"
#include "Roca.h"
#include "PlayerList.h"
#include "GameCounter.h"
#include "Info.h"
#include "ButtonList.h"
using namespace std;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//// ////
//// Inicializacion ////
//// ////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Funciones glut //
//////////////////////////////////////////////////////////////////////////
void OnDraw(void);
void OnTimer(int value);
void OnKeyboardDown(BYTE key, int x, int y);
void OnMouseMotion(int x, int y);
void OnMouseMotionClick(int, int, int x, int y);
//////////////////////////////////////////////////////////////////////////
// Flags y variables globales //
//////////////////////////////////////////////////////////////////////////
Posicion pti; //Variable de click inicio
Posicion ptf; //Variable de click final
Posicion posRatonW; //Guarda la posicion del raton en la ventana
Vector posRaton; //Guarda la posicion del raton en todo momento
Posicion *periferias[((WORLDSIZE - 1) / 2)]; //Vector de periferias de analisis
Camera *camera = new Camera(20,20,20); //Camara en uso por el jugador
bool flagMove = 0;
bool flagAttack = 0;
bool flagRangeD = 1;
//////////////////////////////////////////////////////////////////////////
// Inicializacion de jugadores //
//////////////////////////////////////////////////////////////////////////
PlayerList pList;
//////////////////////////////////////////////////////////////////////////
// Mundo //
//////////////////////////////////////////////////////////////////////////
World superficie(0);
//////////////////////////////////////////////////////////////////////////
// Intrefaz Jugador //
//////////////////////////////////////////////////////////////////////////
Interfaz interfaz;
Info cuadro;
ButtonList dialog;
//////////////////////////////////////////////////////////////////////////
// Gestion del turno //
//////////////////////////////////////////////////////////////////////////
GameCounter turno;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//// ////
//// Main ////
//// ////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void func(int value)
{
std::cout << value;
}
int main(int argc,char* argv[])
{
//////////////////////////Abre la ventana y GL//////////////////////////
inicializaVentana(argc, argv);
////////////////////Llama a los calbacks del juego///////////////////////
glutDisplayFunc(OnDraw);
glutTimerFunc(10, OnTimer, 0); //10 ms
glutKeyboardFunc(OnKeyboardDown);
glutMouseFunc(OnMouseMotionClick);
glutMotionFunc(OnMouseMotion);
glutPassiveMotionFunc(OnMouseMotion);
srand(time(NULL));
glClearColor(0.7, 1.0, 1.0, 0);
//////////////////////Inicia la musica del juego/////////////////////////
//PlaySound(L"MaC.wav", NULL, SND_ASYNC | SND_FILENAME | SND_LOOP);
///////////////////////Creacion de periferias////////////////////////////
for (int i = 0; i < ((WORLDSIZE - 1) / 2); i++)
periferias[i] = periferiaFinder(i+1);
///////////////////////////////////////////////////////////////////////
////////////////////////////Mundo//////////////////////////////////////
/////////////////////////////////////////////////////////////////////
///////////////////////Añade Rocas////////////////////////////////////
int v1 = rand() % 25 - 10;
for (int i = -10; i < 11;i++)
if (i<-4 || (i>-2 && i<2) || i>4){
v1 = rand() % 20 - 13;
pList[0].myShips.addElem(new Roca(i, v1));
}
//////////////Jugador 1////////////
system("CLS");
int num = 0;
pList.addPlayer(new Player("Jugador 1", 1, ePlayer));
system("CLS");
cout << "\n" << "Jugador 1: \n Numero de Light Cruisier:";
cin >> num;
for (int i = 0; i < num; i++)
pList[1].myShips.addElem(new Barco(2, -1 + i, 1, lightCrusier));
///////////////////////////////////////////////////////////
cout << "\n" << "\n Numero de Cruisier:";
cin >> num;
for (int i = 0; i < num; i++)
pList[1].myShips.addElem(new Barco(3, -1 + i, 1, Crusier));
///////////////////////////////////////////////////////////
cout << "\n" << "\n Numero de Battle Cruisier:";
cin >> num;
for (int i = 0; i < num; i++)
pList[1].myShips.addElem(new Barco(4, -1 + i, 1, battleCrusier));
/////////////Jugador 2 ///////////////////
pList.addPlayer(new Player("Jugador 2", 2, ePlayer));
system("CLS");
cout << "\n" << "Jugador 2: \n Numero de Light Cruisier:";
cin >> num;
for (int i = 0; i < num; i++)
pList[2].myShips.addElem(new Barco(-2, -3 + i, 2, lightCrusier));
///////////////////////////////////////////////////////////
cout << "\n" << "\n Numero de Cruisier:";
cin >> num;
for (int i = 0; i < num; i++)
pList[2].myShips.addElem(new Barco(-3, -4 + i, 2, Crusier));
///////////////////////////////////////////////////////////
cout << "\n" << "\n Numero de Battle Cruisier:";
cin >> num;
for (int i = 0; i < num; i++)
pList[2].myShips.addElem(new Barco(-4, -5 + i, 2, battleCrusier));
turno.iniGameCounter(&pList);
pList.addWorldContent(&superficie);
///////////////////////////////////////////////////////////////
//Entrada en el bucle de funcion
glutMainLoop();
return 0;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//// ////
//// funciones CALLBACK ////
//// ////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Dibujo //
//////////////////////////////////////////////////////////////////////////
void OnDraw(void) {
float vista[9];
camera->getBackCamera(vista);
switch (interfaz.sMenu){
//Menu
case 0:
interfaz.Menu(camera);
break;
//Juego normal
default:
camera = &pList[turno.thisSubturn()].pCamera;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Para definir el punto de vista
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(
vista[0], vista[1], vista[2], // posicion del ojo
vista[3], vista[4], vista[5], // hacia que punto mira (0,0,0)
vista[6], vista[7], vista[8] // definimos hacia arriba (eje Y)
);
Casilla::lightUp(posRaton[x], posRaton[y]); //Es la funcion que ilumina la casilla donde esta el raton
glColor3ub(2, 2, 2);
glTranslatef(posRaton[x], posRaton[y], posRaton[z]);
glutSolidSphere(0.05, 20, 20);
glTranslatef(-posRaton[x], -posRaton[y], -posRaton[z]);
superficie.doDrawWorldMap();
superficie.doDrawWorldContent();
//////////////////////////Dibujo de rango////////////////////////////
if (flagAttack&&flagRangeD)
superficie.doDrawRange(pti, Interfaz::interactuable(turno.enableFaction()), 1);
if (flagMove&&flagRangeD)
superficie.doDrawRange(pti, Interfaz::interactuable(turno.enableFaction()), 0);
//////////////////////////Dibujo de menus////////////////////////////
cuadro.putInfoFull(pti, posRatonW);
dialog.drawButtos();
break;
}
glutSwapBuffers();//Cambia los buffer de dibujo, no borrar esta linea ni poner nada despues
}
//////////////////////////////////////////////////////////////////////////
// Temporizada //
//////////////////////////////////////////////////////////////////////////
void OnTimer(int value) //poner aqui el codigo de animacion
{
glutTimerFunc(10,OnTimer,0); //Temporizador de actulizacion
glutPostRedisplay(); //Actualizacion de pantalla
}
//////////////////////////////////////////////////////////////////////////
// Movimiento de raton //
//////////////////////////////////////////////////////////////////////////
void OnMouseMotion(int _x, int _y)
{
interfaz.MovimientoRaton(_x, _y);
}
//////////////////////////////////////////////////////////////////////////
// Click de raton //
//////////////////////////////////////////////////////////////////////////
void OnMouseMotionClick(int p, int pp, int _x, int _y)
{
interfaz.InterfazRaton(p, pp, _x, _y);
}
//////////////////////////////////////////////////////////////////////////
// Pulsacion de teclado //
//////////////////////////////////////////////////////////////////////////
void OnKeyboardDown(BYTE key, int x_t, int y_t)
{
interfaz.InterfazTeclado(key, camera);
std::cout << "Key";
}
//////////////////////////////////////////////////////////////////////////
// FIN //
//////////////////////////////////////////////////////////////////////////