1 /*************************************************************************** 2 * Copyright (C) 2004-2005 by * 3 * Paolo Sacconier <axa1981@tin.it> * 4 * Francesco Tamagni <minchiahead@hacari.org> * 5 * * 6 * This program is free software; you can redistribute it and/or modify * 7 * it under the terms of the GNU General Public License as published by * 8 * the Free Software Foundation; either version 2 of the License, or * 9 * (at your option) any later version. * 10 * * 11 * This program is distributed in the hope that it will be useful, * 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 14 * GNU General Public License for more details. * 15 * * 16 * You should have received a copy of the GNU General Public License * 17 * along with this program; if not, write to the * 18 * Free Software Foundation, Inc., * 19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 20 ***************************************************************************/ 21 22 #ifndef GILLOGAME_H 23 #define GILLOGAME_H 24 25 #include "main.h" 26 27 #include "video.h" 28 #include "sound.h" 29 30 #include "simpleball.h" 31 #include "field.h" 32 #include "goal.h" 33 #include "goalkeeper.h" 34 #include "car.h" 35 #include "omnicar.h" 36 #include "cube.h" 37 #include "pwrup.h" 38 39 #include "cameraball.h" 40 #include "cameratrack.h" 41 42 #include "context.h" 43 #include "event.h" 44 #include "player.h" 45 46 namespace gillo { 47 48 /** 49 A game, that contains objects and players. 50 51 @author $AUTHOR$ 52 */ 53 class Game{ 54 enum Status { 55 PAUSED, 56 SELFPAUSED, 57 RUNNING, 58 TRAINING, 59 FINISHED 60 }; 61 62 static const float possessionBarLength; 63 static const float maxScoreBarLength; 64 static const float maxTimerBarLength; 65 static const float maxMagnetIntensity; 66 static const float splashCoordSet[][4]; 67 static const float scoreEpsilon; 68 static const float possessionEpsilon; 69 70 int contactcount; 71 72 Context context; 73 vector<Entity*> entities; 74 vector<Entity*> tempEntities; 75 vector<Entity*> removedEntities; 76 vector<Entity*> magneticEntities; 77 Goal& goal; 78 SimpleBall& ball; 79 Goalkeeper& goalkeeper; 80 Player p1; 81 Player p2; 82 83 int frameCount; 84 float topScore; 85 float score; 86 float ballScore; 87 float time; 88 float gameDuration; 89 float goalSplashDuration; 90 float randomTimeInterval; 91 bool rotatingGravity; 92 bool goalStatus; 93 bool powerShoot; 94 Img* timerBarPtr; 95 Img* possessionCursorPtr; 96 Img* scoreBarRedPtr; 97 Img* scoreBarBluePtr; 98 Img* mainOverlayPtr; 99 Img* endSplash; 100 Img goalRedSplash; 101 Img goalBlueSplash; 102 Img tieGoalSplash; 103 Img attractionStautsP1; 104 Img attractionStautsP2; 105 Viewport mainView; 106 Viewport playerTwoView; 107 Viewport playerOneView; 108 109 Video& video; 110 Sound& sound; 111 112 queue<Event>& equeue; 113 Status status; 114 Status previousStatus; 115 dContact contacts[ODE_MAX_CONTACTS]; 116 dJointGroupID contactgroup; 117 118 119 Entity& addEntity (Entity* e); 120 Entity& addEntityAtRandomPos (Entity* e, float duration); 121 bool removeEntity (Entity* e); 122 void removeEntitiesOfType(Entity::Type et); 123 bool removeMagneticEntity (Entity* e); 124 dContact* collide(Entity* e1, Entity* e2, dGeomID o1, dGeomID o2, dContact* c); 125 void handleKeyDown( SDL_keysym* keysym ); 126 void handleKeyUp ( SDL_keysym* keysym ); 127 128 void startNew(); 129 inline void updateScore(float dt); 130 inline void updatePossession(float dt); 131 inline void updatePlayers(float dt); 132 void updateTimer(float dt); 133 void updateScoreBarHeight(Rect* r, float h, float dt); 134 void end(); 135 136 friend void collide_callback (void *data, dGeomID o1, dGeomID o2); 137 138 public: 139 Game(Video& v, Sound& s, queue<Event>& eq); 140 ~Game(); 141 142 void update(float dt); 143 void react(SDL_Event *event); 144 void react(const Event::Type et); 145 bool changeStatus(Status s); 146 147 getContext()148 inline Context& getContext() { return context; } 149 150 }; 151 152 }; 153 154 #endif 155