5 #include "controlewii.h"
6 #include "shotmanager.h"
7 #include "weaponitem.h"
10 void Game::loadMap(std::string mapname
) {
13 mapa
= new Mapa(mapname
,this);
16 void Game::addPlatform(Platform
* plat
) {
17 gravityManager
->addPlatform(plat
);
20 void Game::removePlatforms() {
21 gravityManager
->removePlatforms();
26 glClearColor( 1, 1, 1, 0 );
28 //Initialize modelview matrix
29 glMatrixMode( GL_MODELVIEW
);
33 glEnable(GL_DEPTH_TEST
);
34 glDepthFunc(GL_LEQUAL
);
38 glEnable(GL_LINE_SMOOTH
);
40 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
41 glHint(GL_LINE_SMOOTH_HINT
, GL_NICEST
);
43 //If there was any errors
44 if( glGetError() != GL_NO_ERROR
)
49 //If everything initialized
53 Game::Game(ConfigManager
*cfg
) {
54 gravityManager
= new GravityManager
;
59 if( SDL_Init( SDL_INIT_EVERYTHING
) < 0 )
65 if( SDL_SetVideoMode( config
->screen
["width"], config
->screen
["height"], config
->screen
["bpp"], SDL_OPENGL
| SDL_RESIZABLE
) == NULL
)
77 SDL_WM_SetCaption( "Big Stick", NULL
);
80 void Game::desenhaMira(Ponto aim
) {
82 glTranslatef(aim
.x
,aim
.y
,0);
88 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
90 int width
= config
->screen
["width"];
91 int height
= config
->screen
["height"];
93 if (player
->getX() <= width
/2)
95 else if (player
->getX() >= mapa
->xmax() - width
/2)
96 x
= mapa
->xmax() - width
;
98 x
= player
->getX() - width
/2;
100 if (player
->getY() <= 2*height
/3)
102 else if (player
->getY() >= mapa
->ymax() - height
/3)
103 y
= mapa
->ymax() - height
;
105 y
= player
->getY() - 2*height
/3;
110 shotManager
->desenha();
111 enemyManager
->desenha();
113 glMatrixMode( GL_PROJECTION
);
115 glOrtho( camera
.x
, camera
.x
+width
, camera
.y
+height
, camera
.y
, -2, 2 );
116 SDL_GL_SwapBuffers();
119 void Game::reloadLua() {
121 resize(config
->screen
["width"], config
->screen
["height"]);
122 loadMap(config
->maps
.front());
123 weaponManager
->loadWeapons();
124 shotManager
->clearShots();
125 player
->equip(weaponManager
->getWeapon("Shotgun"));
128 void Game::setSpawn(Ponto spawn
) {
132 void Game::resize(GLsizei x
, GLsizei y
) {
133 config
->screen
["width"] = x
;
134 config
->screen
["height"] = y
;
135 SDL_SetVideoMode(x
, y
, config
->screen
["bpp"], SDL_OPENGL
| SDL_RESIZABLE
);
136 glViewport(0, 0, x
, y
);
139 WeaponItem
* Game::dropWeapon(std::string name
) {
140 return weaponManager
->getItem(name
);
143 void Game::spawnEnemy(std::string name
, Ponto position
) {
144 Enemy
* enemy
= enemyManager
->createEnemy(name
);
145 enemy
->setPosition(position
.x
,position
.y
);
148 void Game::mainLoop() {
150 shotManager
= new ShotManager
;
151 weaponManager
= new WeaponManager(this);
152 collisionManager
= new CollisionManager
;
153 weaponManager
->loadWeapons();
154 enemyManager
= new EnemyManager(this);
155 enemyManager
->loadEnemies();
156 loadMap(config
->maps
.front());
158 player
= new Player(this, spawn
, config
->player
["speed"]);
160 c
= new ControleWii(*player
);
161 player
->equip(weaponManager
->getWeapon("Shotgun"));
163 collisionManager
->subscribe(player
);
164 std::list
<WeaponItem
*>::iterator itW
;
165 for (itW
= mapa
->items
.begin(); itW
!= mapa
->items
.end(); itW
++) {
166 collisionManager
->subscribe(*itW
);
167 gravityManager
->subscribe(*itW
);
173 int ifps
= config
->screen
["fps"];
177 enemyManager
->think();
180 collisionManager
->update();
181 gravityManager
->update();
184 enemyManager
->animate();
189 enemyManager
->move();
193 rate
= ((double)fps
.get_ticks())/ifps
;
196 if (fps
.get_ticks() < 1000 / ifps
) {
197 SDL_Delay( ( 1000 / ifps
) - fps
.get_ticks() );