-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayScreen.cpp
More file actions
138 lines (118 loc) · 3.65 KB
/
Copy pathPlayScreen.cpp
File metadata and controls
138 lines (118 loc) · 3.65 KB
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
/**
* Copyright (C) Kevin J. Estevez (kenystev) and Luis C. Isaula (lisaula)
*
* GNU GENERAL PUBLIC LICENSE Version 2
* The licenses for most software are designed to take away your
* freedom to share and change it. By contrast, the GNU General Public
* License is intended to guarantee your freedom to share and change free
* software--to make sure the software is free for all its users. This
* General Public License applies to most of the Free Software
* Foundation's software and to any other program whose authors commit to
* using it.
*/
#include "PlayScreen.h"
#include "RaceGear.h"
PlayScreen::PlayScreen(Game *game)
{
this->game = game;
loadCars("cars.xml");
}
PlayScreen::~PlayScreen()
{
delete track;
delete back_button;
delete background;
delete bu;
delete bd;
delete track;
delete player_car;
}
void PlayScreen::show ()
{
time=0;
scr=new Scores();
finish=false;
player_car = cars[((RaceGear*)game)->selected_car];
player_car->initCar();
track = new Pista(player_car, game->rosalila_graphics, game->receiver,((RaceGear*)game)->selected_track);
bu = game->rosalila_graphics->getTexture(assets_directory+"BACK_UP.png");
bd = game->rosalila_graphics->getTexture(assets_directory+"BACK_DWN.png");
back_button = new BackButton(20,18,bu,bd,game->rosalila_graphics,game);
track->init();
n =((RaceGear*)game)->name_player;
if(scr->seekUser(n)<0){
scr->createNewUserBinary(n);
}
num_rt = ((RaceGear*)game)->id_pista;
display_laps = new Font("airstrikeacad.ttf");
display_laps->setSize(30);
display_laps->setColor(0,0,0);
}
void PlayScreen::render (RosalilaGraphics*p)
{
track->draw();
if(!track->getLose()){
track->logica();
}
if(track->laps==0)
{
finish=true;
((RaceGear*)game)->seg=track->seg;
if(game->rosalila_graphics->frame%100==0)
game->setScreen(((RaceGear*)game)->STATISTICS);
}
back_button->update(game->receiver->getMouse_X(),game->receiver->getMouse_Y(),game->receiver->isLeftClickDown());
// if(back_button->clicked(game->receiver->getMouse_X(),game->receiver->getMouse_Y(),game->receiver->isLeftClickDown()))
// game->setScreen(((RaceGear*)game)->MENU);
back_button->draw(game->receiver->getMouse_X(),game->receiver->getMouse_Y(),game->receiver->isLeftClickDown());
display_laps->drawText("Laps: "+toString(track->laps),117,87);
}
// void resize (int width, int height);
void PlayScreen::pause ()
{
}
void PlayScreen::resume ()
{
}
void PlayScreen::hide ()
{
time = ((RaceGear*)game)->seg;
if(finish){
scr->setPuntosToPista(n,time,num_rt);
}
// //scr->setPuntosToPista(n,time,num_rt);
// track->clear();
// delete background;
// delete scr;
// delete track;
// delete player_car;
// delete cars[0];
// delete cars[1];
// delete cars[2];
// delete cars[3];
// delete &cars;
}
void PlayScreen::dispose ()
{
delete player_car;
delete track;
delete bu;
delete bd;
delete back_button;
}
void PlayScreen::loadCars(string path)
{
TiXmlDocument doc((assets_directory+path).c_str());
doc.LoadFile();
TiXmlNode *Cars = doc.FirstChild("Cars");
int i=0;
for(TiXmlNode *car = Cars->FirstChild("car");
car!=NULL;
car = car->NextSibling("car"),i++)
{
cars[i] = new Car(game->rosalila_graphics,car->ToElement()->Attribute("image"));
cars[i]->maximum = atof(car->ToElement()->Attribute("velocity"));
cars[i]->a = atof(car->ToElement()->Attribute("aceleration"));
cars[i]->CHANGE_TURN = atof(car->ToElement()->Attribute("turn"));
}
}