|
@@ -1,7 +1,3 @@
|
1
|
|
-///
|
2
|
|
-/// Modifications:
|
3
|
|
-/// - 2015-06-05 [Ian Davila] - Changed Frogger's location
|
4
|
|
-///
|
5
|
1
|
#include "frog.h"
|
6
|
2
|
#include <QDebug>
|
7
|
3
|
#include <cstdlib>
|
|
@@ -11,87 +7,59 @@
|
11
|
7
|
#include "mainwindow.h"
|
12
|
8
|
#include "ui_mainwindow.h"
|
13
|
9
|
|
14
|
|
-/// \fn frog::frog(QWidget *parent)
|
15
|
|
-/// \~English
|
16
|
|
-/// \brief Default constructor.
|
17
|
|
-/// * Ysapo: Y coordinate of the frog, set at 190 so it sits on top of the leaf
|
18
|
|
-/// * Xsapo: X coordinate of the frog, a random number from 0 to -30
|
19
|
|
-/// * xnenu, xnenu2, xnenu3: X coordinates of the leafs
|
20
|
|
-/// * textBool: Boolean for the labels on the leafs
|
21
|
|
-/// * temp, temp2: X coordinate of the background
|
22
|
|
-/// \~Spanish
|
23
|
|
-/// \ brief Constructor por defecto.
|
24
|
|
-/// * Ysapo: Coordenada Y del sapo, inicializado a 190 para que aparesca encima del nenufar
|
25
|
|
-/// * Xsapo: Coordenada X del sapo, un numero aleatorio de 0 a -30
|
26
|
|
-/// * xnenu, xnenu2, xnenu3: coordenadas x de las hojas
|
27
|
|
-/// * textBool: Booleana para las etiquetas de los nenufares
|
28
|
|
-/// * temp, temp2: Coordenada X del fondo
|
29
|
|
-///
|
30
|
10
|
frog::frog(QWidget *parent) :
|
31
|
11
|
QWidget(parent)
|
32
|
12
|
{
|
33
|
13
|
myTimer= new QTimer(this);
|
34
|
|
- flag = xFlag = backFlag = moved = textBool = false;
|
|
14
|
+ flag = xFlag = false;
|
35
|
15
|
Ysapo = 190;
|
36
|
16
|
A = B = C = 0;
|
37
|
17
|
temp = 580;
|
38
|
18
|
temp2 = 0;
|
39
|
|
- xnenu = -(rand()%30);
|
40
|
|
- initialX = Xsapo = xnenu;
|
|
19
|
+ backFlag = false;
|
|
20
|
+ moved = false;
|
|
21
|
+ textBool = false;
|
|
22
|
+ buttonCounter = 0;
|
|
23
|
+ xnenu = -(rand() %30);
|
|
24
|
+ Xsapo = xnenu;
|
|
25
|
+ initialX = Xsapo;
|
41
|
26
|
xnenu2 = (rand() % 100) + 100;
|
42
|
27
|
xnenu3 = xnenu2 + (rand() % 100) + 200;
|
43
|
28
|
}
|
44
|
29
|
|
45
|
|
-/// \fn void frog::updatenenu()
|
46
|
|
-/// \~English
|
47
|
|
-/// \brief Function that updates the position of the frog and the leafs
|
48
|
|
-/// when the frog reaches the end of the screen when it's sliding back.
|
49
|
|
-/// \~Spanish
|
50
|
|
-/// \brief Funcion que actualiza la posicion del sapo y los nenufares
|
51
|
|
-/// cuando el sapo llega al final de la pantalla cuando se desliza hacia atras.
|
52
|
|
-///
|
53
|
30
|
void frog::updatenenu(){
|
54
|
31
|
xnenu = -(rand() % 30);
|
55
|
|
- initialX = Xsapo = xnenu;
|
|
32
|
+ Xsapo = xnenu;
|
|
33
|
+ initialX = Xsapo;
|
56
|
34
|
xnenu2 = (rand() % 100) + 100;
|
57
|
35
|
xnenu3 = xnenu2 + (rand() % 100) + 200;
|
58
|
36
|
}
|
59
|
37
|
|
60
|
|
-/// \fn void frog::reset()
|
61
|
|
-/// \~English
|
62
|
|
-/// \brief Function that is invoked when the retry button is clicked, resets
|
63
|
|
-/// the frog and the leafs to a random starting position.
|
64
|
|
-/// \~Spanish
|
65
|
|
-/// \brief Funcion que es invocada cuando el boton de "retry" es presionado,
|
66
|
|
-/// restablece el sapo y los nenufares a una posicion de partida aleatoria.
|
67
|
|
-///
|
68
|
38
|
void frog::reset(){
|
69
|
|
- flag = xFlag = backFlag = moved = textBool = false;
|
|
39
|
+ flag = xFlag = false;
|
70
|
40
|
Ysapo = 190;
|
71
|
41
|
A = B = C = 0;
|
72
|
42
|
temp = 580;
|
73
|
43
|
temp2 = 0;
|
|
44
|
+ backFlag = false;
|
|
45
|
+ moved = false;
|
|
46
|
+ buttonCounter = 0;
|
|
47
|
+ textBool = false;
|
74
|
48
|
repaint();
|
|
49
|
+
|
75
|
50
|
myTimer->stop();
|
76
|
51
|
delete myTimer;
|
77
|
52
|
myTimer = new QTimer;
|
78
|
53
|
connect(myTimer, SIGNAL(timeout()), this, SLOT(mySlot()));
|
79
|
54
|
xnenu = -(rand() %30);
|
80
|
|
- initialX = Xsapo = xnenu;
|
|
55
|
+ Xsapo = xnenu;
|
|
56
|
+ initialX = Xsapo;
|
81
|
57
|
xnenu2 = (rand() % 100) + 100;
|
82
|
58
|
xnenu3 = xnenu2 + (rand() % 100) + 200;
|
83
|
59
|
|
84
|
60
|
}
|
85
|
61
|
|
86
|
|
-/// \fn void frog::paintEvent(QPaintEvent *event)
|
87
|
|
-/// \~English
|
88
|
|
-/// \brief Function that is invoked each time the widget or
|
89
|
|
-/// its parent receives a repaint signal.
|
90
|
|
-/// \~Spanish
|
91
|
|
-/// \brief Funcion que es invocada automaticamente cada vez que el widget
|
92
|
|
-/// o su padre recive una senal de repintar.
|
93
|
|
-///
|
94
|
|
-void frog::paintEvent(QPaintEvent *){
|
|
62
|
+void frog::paintEvent(QPaintEvent *event){
|
95
|
63
|
QPainter p(this);
|
96
|
64
|
QString frogger = ":/images/Frogger1.png";
|
97
|
65
|
QString frogger2 = ":/images/Frogger2.png";
|
|
@@ -99,12 +67,20 @@ void frog::paintEvent(QPaintEvent *){
|
99
|
67
|
QString leaf = ":/images/Nenufar1.png";
|
100
|
68
|
QString back = ":/images/background.jpg";
|
101
|
69
|
|
102
|
|
- //Conditions that allow a margin of error (not landing in the exact x calculated)
|
|
70
|
+// Condiciones que permitian un rango de error (no caer en la x exacta de los nenufares)
|
|
71
|
+
|
103
|
72
|
if(backFlag == true || (Xsapo <= (xnenu3 + 55) && Xsapo >= (xnenu3 - 55) && Ysapo == 190)
|
104
|
73
|
|| (Xsapo > xnenu && Ysapo == 190 && Xsapo < (xnenu2-55))
|
105
|
74
|
|| (Xsapo > xnenu2 && Ysapo == 190 && Xsapo < (xnenu3-55))
|
106
|
75
|
|| (Xsapo > xnenu3 && Ysapo == 190)){
|
107
|
76
|
|
|
77
|
+// if(backFlag == true || (Ysapo == 190 && (Xsapo != xnenu && Xsapo != xnenu2))){
|
|
78
|
+ if (inter1Label == NULL){
|
|
79
|
+ delete inter1Label;
|
|
80
|
+ }
|
|
81
|
+ if (inter2Label == NULL){
|
|
82
|
+ delete inter2Label;
|
|
83
|
+ }
|
108
|
84
|
backFlag = true;
|
109
|
85
|
myTimer->stop();
|
110
|
86
|
delete myTimer;
|
|
@@ -112,20 +88,19 @@ void frog::paintEvent(QPaintEvent *){
|
112
|
88
|
QThread::msleep(5);
|
113
|
89
|
connect(myTimer, SIGNAL(timeout()), this, SLOT(mySlot()));
|
114
|
90
|
|
115
|
|
- // Draw background
|
|
91
|
+
|
|
92
|
+
|
116
|
93
|
p.drawPixmap(temp2,-5,600,400,QPixmap(back));
|
117
|
94
|
p.drawPixmap(temp,-5,600,400,QPixmap(back));
|
118
|
95
|
|
119
|
|
- // Draw leaves
|
120
|
|
- p.drawPixmap(xnenu,230,125,60,QPixmap(leaf));
|
121
|
|
- p.drawPixmap(xnenu2,230,125,60,QPixmap(leaf));
|
122
|
|
- p.drawPixmap(xnenu3,230,125,60,QPixmap(leaf));
|
|
96
|
+ p.drawPixmap(xnenu,250,125,60,QPixmap(leaf));
|
|
97
|
+ p.drawPixmap(xnenu2,250,125,60,QPixmap(leaf));
|
|
98
|
+ p.drawText(xnenu2+45,290,"x1 = " + QString::number(xnenu2));
|
|
99
|
+ p.drawPixmap(xnenu3,250,125,60,QPixmap(leaf));
|
|
100
|
+ p.drawText(xnenu3+45,290,"x2 = " + QString::number(xnenu3));
|
|
101
|
+
|
123
|
102
|
|
124
|
|
- // Draw text labels
|
125
|
|
- p.drawText(xnenu2+45,310,"x1 = " + QString::number(xnenu2));
|
126
|
|
- p.drawText(xnenu3+45,310,"x2 = " + QString::number(xnenu3));
|
127
|
103
|
|
128
|
|
- // Moves everything on the screen back on the x-axis
|
129
|
104
|
Xsapo=Xsapo-1;
|
130
|
105
|
xnenu=xnenu-1;
|
131
|
106
|
xnenu2=xnenu2-1;
|
|
@@ -133,9 +108,11 @@ void frog::paintEvent(QPaintEvent *){
|
133
|
108
|
temp= temp - 1;
|
134
|
109
|
temp2 = temp2 -1;
|
135
|
110
|
|
|
111
|
+
|
136
|
112
|
repaint();
|
137
|
113
|
|
138
|
|
- // When the frog reaches the end of the screen reset everything to a start position
|
|
114
|
+
|
|
115
|
+
|
139
|
116
|
if(temp == 0 || xnenu3 == -10 || Xsapo == 0){
|
140
|
117
|
backFlag = false;
|
141
|
118
|
temp = 580;
|
|
@@ -145,77 +122,63 @@ void frog::paintEvent(QPaintEvent *){
|
145
|
122
|
updatenenu();
|
146
|
123
|
}
|
147
|
124
|
|
148
|
|
- }else{
|
|
125
|
+ }
|
|
126
|
+ else{
|
149
|
127
|
QFont font = p.font();
|
150
|
128
|
font.setBold(true);
|
151
|
129
|
p.setFont(font);
|
152
|
130
|
|
153
|
|
- // Draw background
|
154
|
131
|
p.drawPixmap(temp2,-5,600,400,QPixmap(back));
|
155
|
132
|
p.drawPixmap(temp,-5,600,400,QPixmap(back));
|
|
133
|
+ p.drawPixmap(xnenu,250,125,60,QPixmap(leaf));
|
|
134
|
+ p.drawPixmap(xnenu2,250,125,60,QPixmap(leaf));
|
|
135
|
+ p.drawPixmap(xnenu3,250,125,60,QPixmap(leaf));
|
156
|
136
|
|
157
|
|
- // Draw leaves
|
158
|
|
- p.drawPixmap(xnenu,230,125,60,QPixmap(leaf));
|
159
|
|
- p.drawPixmap(xnenu2,230,125,60,QPixmap(leaf));
|
160
|
|
- p.drawPixmap(xnenu3,230,125,60,QPixmap(leaf));
|
|
137
|
+// Cambiada la condicion para que sea exacta la caida en el nenufar
|
|
138
|
+// if(Xsapo < (xnenu2 + 55) && Ysapo == 190 && Xsapo > (xnenu2-55)){
|
|
139
|
+// textBool = true;
|
|
140
|
+// }
|
161
|
141
|
|
162
|
|
- //Cambiada la condicion para que sea exacta la caida en el nenufar // Funciona con esta condición
|
163
|
|
- if(Xsapo < (xnenu2 + 55) && Ysapo == 190 && Xsapo > (xnenu2-55)){
|
164
|
|
- textBool = true;
|
165
|
|
- }
|
166
|
|
-
|
167
|
|
- // When the frog lands on the second leaf, change labels to next leaf
|
168
|
142
|
if(Ysapo == 190 && Xsapo == xnenu2){
|
169
|
143
|
textBool = true;
|
170
|
144
|
}
|
171
|
145
|
|
172
|
146
|
if(textBool){
|
173
|
|
- // Redraw the text labels
|
174
|
|
- p.drawText(xnenu2+35,310,"x1 = " + QString::number(xnenu2)); // de 290 a 310
|
175
|
|
- p.drawText(xnenu3+35,310,"x2 = " + QString::number(xnenu3));
|
176
|
|
- p.drawPixmap(xnenu,230,125,60,QPixmap(leaf)); // 250 a 230
|
177
|
|
- }else{
|
178
|
|
- p.drawText(xnenu2+35,310,"x2 = " + QString::number(xnenu2)); // de 290 a 310
|
|
147
|
+ p.drawText(xnenu2+35,290,"x1 = " + QString::number(xnenu2));
|
|
148
|
+ p.drawText(xnenu3+35,290,"x2 = " + QString::number(xnenu3));
|
|
149
|
+ p.drawPixmap(xnenu,250,125,60,QPixmap(leaf));
|
|
150
|
+ }
|
|
151
|
+ else{
|
|
152
|
+ p.drawText(xnenu2+35,290,"x2 = " + QString::number(xnenu2));
|
179
|
153
|
}
|
|
154
|
+
|
180
|
155
|
}
|
181
|
156
|
|
182
|
|
- //Cambiada la condicion para que sea exacta la caida en el nenufar
|
183
|
|
- if((Xsapo > (xnenu + 55) && Ysapo == 190 && Xsapo < (xnenu2-55))
|
|
157
|
+// Cambiada la condicion para que sea exacta la caida en el nenufar
|
|
158
|
+ if(Xsapo > (xnenu + 55) && Ysapo == 190 && Xsapo < (xnenu2-55)
|
184
|
159
|
|| (Xsapo > (xnenu2 + 55) && Ysapo == 190 && Xsapo < (xnenu3-55))
|
185
|
160
|
|| (Xsapo > (xnenu3 + 55) && Ysapo == 190)){
|
186
|
161
|
|
|
162
|
+// if(Ysapo == 190 && (Xsapo != xnenu && Xsapo != xnenu2 && Xsapo != xnenu3)){
|
187
|
163
|
p.drawPixmap(Xsapo, Ysapo + 30, 100, 80, QPixmap(frogger3));
|
188
|
|
-
|
189
|
|
- }else if(Ysapo < 190){
|
190
|
|
- p.drawPixmap(Xsapo,Ysapo,100,100,QPixmap(frogger2));
|
191
|
|
-
|
|
164
|
+ }
|
|
165
|
+ else if(Ysapo < 190){
|
|
166
|
+ p.drawPixmap(Xsapo,Ysapo,100,100,QPixmap(frogger2));
|
192
|
167
|
}else if(Ysapo == 190){
|
193
|
168
|
qDebug() << "xsapo: " << Xsapo << "xnenu2: " << xnenu2;
|
194
|
|
- p.drawPixmap(Xsapo + 15,Ysapo - 20 ,100,100,QPixmap(frogger)); //+15 a la Xsapo, -20 a Ysapo
|
|
169
|
+ p.drawPixmap(Xsapo,Ysapo,100,100,QPixmap(frogger));
|
195
|
170
|
if(!textBool){
|
196
|
|
- p.drawText(xnenu+45,310,"x1 = " + QString::number(xnenu+10));
|
|
171
|
+ p.drawText(xnenu+45,290,"x1 = " + QString::number(xnenu+10));
|
197
|
172
|
}
|
198
|
173
|
}
|
|
174
|
+
|
199
|
175
|
}
|
200
|
176
|
|
201
|
|
-/// \fun frog::~frog()
|
202
|
|
-/// \~English
|
203
|
|
-/// \brief Default destructor.
|
204
|
|
-/// \~Spanish
|
205
|
|
-/// \brief Destructor por defecto.
|
206
|
|
-///
|
207
|
177
|
frog::~frog(){
|
208
|
178
|
delete myTimer;
|
209
|
179
|
}
|
210
|
180
|
|
211
|
|
-/// \fun void frog::mySlot()
|
212
|
|
-/// \~English
|
213
|
|
-/// \brief Function connected to a timer, used to simulate the
|
214
|
|
-/// frog's jump.
|
215
|
|
-/// \~Spanish
|
216
|
|
-/// \brief Funcion conectada a un reloj, utilizada para simular
|
217
|
|
-/// el brinco del sapo
|
218
|
|
-///
|
|
181
|
+
|
219
|
182
|
void frog::mySlot(){
|
220
|
183
|
float interX1 = 0;
|
221
|
184
|
float interX2 = 0;
|
|
@@ -224,6 +187,8 @@ void frog::mySlot(){
|
224
|
187
|
float xtemp = 0;
|
225
|
188
|
float xEnd = 0;
|
226
|
189
|
|
|
190
|
+
|
|
191
|
+
|
227
|
192
|
interX1 = QuadraticMinus(A,B,C);
|
228
|
193
|
interX2 = QuadraticPlus(A,B,C);
|
229
|
194
|
|
|
@@ -234,6 +199,7 @@ void frog::mySlot(){
|
234
|
199
|
}
|
235
|
200
|
if(moved){
|
236
|
201
|
moved = false;
|
|
202
|
+ buttonCounter = 1;
|
237
|
203
|
initialX = Xsapo;
|
238
|
204
|
}
|
239
|
205
|
|
|
@@ -269,27 +235,12 @@ void frog::mySlot(){
|
269
|
235
|
|
270
|
236
|
}
|
271
|
237
|
|
272
|
|
-/// \fn void frog::run(int aa, int bb, int cc)
|
273
|
|
-/// \~English
|
274
|
|
-/// \brief Function that is invoked when the jump button is
|
275
|
|
-/// pressed, makes the frog jump to the coordinates calculated
|
276
|
|
-/// with the a, b, c values provided by the user.
|
277
|
|
-/// \param aa value provided by user to complete the quadratic equation ax^2 + bx + c
|
278
|
|
-/// \param bb value provided by user to complete the quadratic equation ax^2 + bx + c
|
279
|
|
-/// \param cc value provided by user to complete the quadratic equation ax^2 + bx + c
|
280
|
|
-/// \~Spanish
|
281
|
|
-/// \brief Funcion que es invocada cuando el boton de brincar es
|
282
|
|
-/// presionado, hace que el sapo salte a las coordenadas calculadas
|
283
|
|
-/// con los valores de a, b, c proporcionados por el usuario.
|
284
|
|
-/// \param aa valor proporcionado por el usuario utilizado para completar la ecuacion cuadratica ax^2 + bx + c
|
285
|
|
-/// \param bb valor proporcionado por el usuario utilizado para completar la ecuacion cuadratica ax^2 + bx + c
|
286
|
|
-/// \param cc valor proporcionado por el usuario utilizado para completar la ecuacion cuadratica ax^2 + bx + c
|
287
|
|
-///
|
288
|
238
|
void frog::run(int aa, int bb, int cc){
|
289
|
239
|
|
290
|
240
|
A = aa;
|
291
|
241
|
B = bb;
|
292
|
242
|
C = cc;
|
|
243
|
+ buttonCounter++;
|
293
|
244
|
|
294
|
245
|
connect(myTimer, SIGNAL(timeout()), this, SLOT(mySlot()));
|
295
|
246
|
myTimer->start(25);
|