Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Scenes/PingPongScene/PingPongScene.cpp

Diff revisions: vs.
  @@ -36,7 +36,7 @@
36 36 _touchedOwnTableHalf = false;
37 37 _lost = false;
38 38 _sideDrift = 0;
39 - removeTasks();
39 + clearTasks();
40 40 _ballSGN->getTransform()->setPosition(vec3<F32>(0, 2 ,2));
41 41 }
42 42
  @@ -44,7 +44,7 @@
44 44 GUI::getInstance().modifyText("insults","");
45 45 resetGame();
46 46
47 - if(getTasks().empty()){///A maximum of 1 Tasks allowed
47 + if(getTasks().empty()){//A maximum of 1 Tasks allowed
48 48 Kernel* kernel = Application::getInstance().getKernel();
49 49 Task_ptr newGame(New Task(kernel->getThreadPool(),30,true,false,DELEGATE_BIND(&PingPongScene::test,this,rand() % 5,TYPE_INTEGER)));
50 50 addTask(newGame);
  @@ -66,19 +66,19 @@
66 66 vec3<F32> opponentPosition = opponent->getTransform()->getPosition();
67 67 vec3<F32> tablePosition = table->getTransform()->getPosition();
68 68
69 - ///Is the ball coming towards us or towards the opponent?
69 + //Is the ball coming towards us or towards the opponent?
70 70 _directionTowardsAdversary ? ballPosition.z -= 0.11f : ballPosition.z += 0.11f;
71 - ///Up or down?
71 + //Up or down?
72 72 _upwardsDirection ? ballPosition.y += 0.084f : ballPosition.y -= 0.084f;
73 73
74 - ///Is the ball moving to the right or to the left?
74 + //Is the ball moving to the right or to the left?
75 75 ballPosition.x += _sideDrift*0.15f;
76 76 if(opponentPosition.x != ballPosition.x)
77 77 opponent->getTransform()->translateX(ballPosition.x - opponentPosition.x);
78 78
79 79 ballTransform->translate(ballPosition - ballTransform->getPosition());
80 80
81 - ///Did we hit the table? Bounce then ...
81 + //Did we hit the table? Bounce then ...
82 82 if(table->getBoundingBox().Collision(_ballSGN->getBoundingBox())){
83 83 if(ballPosition.z > tablePosition.z){
84 84 _touchedOwnTableHalf = true;
  @@ -89,21 +89,21 @@
89 89 }
90 90 _upwardsDirection = true;
91 91 }
92 - ///Kinetic energy depletion
92 + //Kinetic energy depletion
93 93 if(ballPosition.y > 2.1f) _upwardsDirection = false;
94 94
95 - ///Did we hit the paddle?
95 + //Did we hit the paddle?
96 96 if(_ballSGN->getBoundingBox().Collision(paddle->getBoundingBox())){
97 97 _sideDrift = ballPosition.x - paddlePosition.x;
98 - ///If we hit the ball with the upper margin of the paddle, add a slight impuls to the ball
98 + //If we hit the ball with the upper margin of the paddle, add a slight impuls to the ball
99 99 if(ballPosition.y >= paddlePosition.y) ballPosition.z -= 0.12f;
100 100
101 101 _directionTowardsAdversary = true;
102 102 }
103 103
104 104 if(ballPosition.y + 0.75f < table->getBoundingBox().getMax().y){
105 - ///If we hit the ball and it landed on the opponent's table half
106 - ///Or if the opponent hit the ball and it landed on our table half
105 + //If we hit the ball and it landed on the opponent's table half
106 + //Or if the opponent hit the ball and it landed on our table half
107 107 if((_touchedAdversaryTableHalf && _directionTowardsAdversary) ||
108 108 (!_directionTowardsAdversary && !_touchedOwnTableHalf))
109 109 _lost = false;
  @@ -112,7 +112,7 @@
112 112
113 113 updated = true;
114 114 }
115 - ///Did we win or lose?
115 + //Did we win or lose?
116 116 if(ballPosition.z >= paddlePosition.z){
117 117 _lost = true;
118 118 updated = true;
  @@ -124,23 +124,23 @@
124 124
125 125 if(_ballSGN->getBoundingBox().Collision(net->getBoundingBox())){
126 126 if(_directionTowardsAdversary){
127 - ///Did we hit the net?
127 + //Did we hit the net?
128 128 _lost = true;
129 129 }else{
130 - ///Did the opponent hit the net?
130 + //Did the opponent hit the net?
131 131 _lost = false;
132 132 }
133 133 updated = true;
134 134 }
135 135
136 - ///Did we hit the opponent? Then change ball direction ... BUT ...
137 - ///Add a small chance that we win
136 + //Did we hit the opponent? Then change ball direction ... BUT ...
137 + //Add a small chance that we win
138 138 if(random(30) != 2)
139 139 if(_ballSGN->getBoundingBox().Collision(opponent->getBoundingBox())){
140 140 _sideDrift = ballPosition.x - opponent->getTransform()->getPosition().x;
141 141 _directionTowardsAdversary = false;
142 142 }
143 - ///Add a spin effect to the ball
143 + //Add a spin effect to the ball
144 144 ballTransform->rotateEuler(vec3<F32>(ballPosition.z,1,1));
145 145
146 146 if(updated){
  @@ -164,45 +164,45 @@
164 164 }
165 165
166 166 void PingPongScene::processInput(){
167 - ///Move FB = Forward/Back = up/down
168 - ///Move LR = Left/Right
169 -
170 - ///Camera controls
171 - if(state()->_angleLR) renderState()->getCamera()->RotateX(state()->_angleLR);
172 - if(state()->_angleUD) renderState()->getCamera()->RotateY(state()->_angleUD);
167 + //Move FB = Forward/Back = up/down
168 + //Move LR = Left/Right
169 + static F32 paddleMovementDivisor = 10;
170 + //Camera controls
171 + if(state()._angleLR) renderState().getCamera().rotateYaw(state()._angleLR);
172 + if(state()._angleUD) renderState().getCamera().rotatePitch(state()._angleUD);
173 173
174 174 SceneGraphNode* paddle = _sceneGraph->findNode("paddle");
175 175
176 176 vec3<F32> pos = paddle->getTransform()->getPosition();
177 177
178 - ///Paddle movement is limited to the [-3,3] range except for Y-descent
179 - if(state()->_moveFB){
180 - if((state()->_moveFB > 0 && pos.y >= 3) || (state()->_moveFB < 0 && pos.y <= 0.5f)) return;
181 - paddle->getTransform()->translateY(state()->_moveFB / 6);
178 + //Paddle movement is limited to the [-3,3] range except for Y-descent
179 + if(state()._moveFB){
180 + if((state()._moveFB > 0 && pos.y >= 3) || (state()._moveFB < 0 && pos.y <= 0.5f)) return;
181 + paddle->getTransform()->translateY(state()._moveFB / paddleMovementDivisor);
182 182 }
183 183
184 - if(state()->_moveLR){
185 - ///Left/right movement is flipped for proper control
186 - if((state()->_moveLR < 0 && pos.x >= 3) || (state()->_moveLR > 0 && pos.x <= -3)) return;
187 - paddle->getTransform()->translateX(-state()->_moveLR / 6);
184 + if(state()._moveLR){
185 + //Left/right movement is flipped for proper control
186 + if((state()._moveLR < 0 && pos.x >= 3) || (state()._moveLR > 0 && pos.x <= -3)) return;
187 + paddle->getTransform()->translateX(state()._moveLR / paddleMovementDivisor);
188 188 }
189 189 }
190 190
191 - bool PingPongScene::load(const std::string& name){
192 - ///Load scene resources
193 - SCENE_LOAD(name,true,true);
194 - ///Add a light
191 + bool PingPongScene::load(const std::string& name, CameraManager* const cameraMgr){
192 + //Load scene resources
193 + bool loadState = SCENE_LOAD(name,cameraMgr,true,true);
194 + //Add a light
195 195 addDefaultLight();
196 196 addDefaultSky();
197 - ///Position the camera
198 - renderState()->getCamera()->setAngleX(RADIANS(-90));
199 - renderState()->getCamera()->setEye(vec3<F32>(0,2.5f,6.5f));
197 + //Position the camera
198 + renderState().getCamera().setPitch(-90);
199 + renderState().getCamera().setEye(vec3<F32>(0,2.5f,6.5f));
200 200
201 201 return loadState;
202 202 }
203 203
204 204 bool PingPongScene::loadResources(bool continueOnErrors){
205 - ///Create a ball
205 + //Create a ball
206 206 ResourceDescriptor minge("Ping Pong Ball");
207 207 _ball = CreateResource<Sphere3D>(minge);
208 208 _ballSGN = addGeometry(_ball,"PingPongBallSGN");
  @@ -223,25 +223,25 @@
223 223 light->setPosition(vec3<F32>(0, 6 ,2));
224 224 _sceneGraph->getRoot()->addNode(light);
225 225 addLight(light);
226 - ///Buttons and text labels
227 - GUI::getInstance().addButton("Serve", "Serve", vec2<I32>(renderState()->cachedResolution().width-120 ,
228 - renderState()->cachedResolution().height/1.1f),
229 - vec2<U32>(100,25),vec3<F32>(0.65f,0.65f,0.65f),
226 + //Buttons and text labels
227 + GUI::getInstance().addButton("Serve", "Serve", vec2<I32>(renderState().cachedResolution().width-120 ,
228 + renderState().cachedResolution().height/1.1f),
229 + vec2<U32>(100,25),vec3<F32>(0.65f),
230 230 DELEGATE_BIND(&PingPongScene::serveBall,this));
231 231
232 - GUI::getInstance().addText("Score",vec2<I32>(renderState()->cachedResolution().width - 120, renderState()->cachedResolution().height/1.3f),
232 + GUI::getInstance().addText("Score",vec2<I32>(renderState().cachedResolution().width - 120, renderState().cachedResolution().height/1.3f),
233 233 Font::DIVIDE_DEFAULT,vec3<F32>(1,0,0), "Score: %d",0);
234 234
235 - GUI::getInstance().addText("Message",vec2<I32>(renderState()->cachedResolution().width - 120, renderState()->cachedResolution().height/1.5f),
235 + GUI::getInstance().addText("Message",vec2<I32>(renderState().cachedResolution().width - 120, renderState().cachedResolution().height/1.5f),
236 236 Font::DIVIDE_DEFAULT,vec3<F32>(1,0,0), "");
237 - GUI::getInstance().addText("insults",vec2<I32>(renderState()->cachedResolution().width/4, renderState()->cachedResolution().height/3),
237 + GUI::getInstance().addText("insults",vec2<I32>(renderState().cachedResolution().width/4, renderState().cachedResolution().height/3),
238 238 Font::DIVIDE_DEFAULT,vec3<F32>(0,1,0), "");
239 239 GUI::getInstance().addText("fpsDisplay", //Unique ID
240 240 vec2<I32>(60,60), //Position
241 241 Font::DIVIDE_DEFAULT, //Font
242 242 vec3<F32>(0.0f,0.2f, 1.0f), //Color
243 243 "FPS: %s",0); //Text and arguments
244 - ///Add some taunts
244 + //Add some taunts
245 245 _quotes.push_back("Ha ha ... even Odin's laughin'!");
246 246 _quotes.push_back("If you're a ping-pong player, I'm Jimmy Page");
247 247 _quotes.push_back("Ooolee, ole ole ole, see the ball? ... It's past your end");
  @@ -256,55 +256,41 @@
256 256 void PingPongScene::onKeyDown(const OIS::KeyEvent& key){
257 257 Scene::onKeyDown(key);
258 258 switch(key.key){
259 - case OIS::KC_W:
260 - state()->_moveFB = 0.25f;
261 - break;
262 - case OIS::KC_A:
263 - state()->_moveLR = 0.25f;
264 - break;
265 - case OIS::KC_S:
266 - state()->_moveFB = -0.25f;
267 - break;
268 - case OIS::KC_D:
269 - state()->_moveLR = -0.25f;
270 - break;
271 - default:
272 - break;
259 + default: break;
260 + case OIS::KC_W: state()._moveFB = 1; break;
261 + case OIS::KC_A: state()._moveLR = -1; break;
262 + case OIS::KC_S: state()._moveFB = -1; break;
263 + case OIS::KC_D: state()._moveLR = 1; break;
273 264 }
274 265 }
275 266
276 267 void PingPongScene::onKeyUp(const OIS::KeyEvent& key){
277 268 Scene::onKeyUp(key);
278 269 switch(key.key) {
270 + default: break;
279 271 case OIS::KC_W:
280 - case OIS::KC_S:
281 - state()->_moveFB = 0;
282 - break;
272 + case OIS::KC_S: state()._moveFB = 0; break;
283 273 case OIS::KC_A:
284 - case OIS::KC_D:
285 - state()->_moveLR = 0;
286 - break;
287 - default:
288 - break;
274 + case OIS::KC_D: state()._moveLR = 0; break;
289 275 }
290 276 }
291 277
292 278 void PingPongScene::onJoystickMovePOV(const OIS::JoyStickEvent& key,I8 pov){
293 279 Scene::onJoystickMovePOV(key,pov);
294 280 if( key.state.mPOV[pov].direction & OIS::Pov::North ) //Going up
295 - state()->_moveFB = 0.25f;
281 + state()._moveFB = 1;
296 282 else if( key.state.mPOV[pov].direction & OIS::Pov::South ) //Going down
297 - state()->_moveFB = -0.25f;
283 + state()._moveFB = -1;
298 284
299 285 if( key.state.mPOV[pov].direction & OIS::Pov::East ) //Going right
300 - state()->_moveLR = -0.25f;
286 + state()._moveLR = 1;
301 287
302 288 else if( key.state.mPOV[pov].direction & OIS::Pov::West ) //Going left
303 - state()->_moveLR = 0.25f;
289 + state()._moveLR = -1;
304 290
305 291 if( key.state.mPOV[pov].direction == OIS::Pov::Centered ){ //stopped/centered out
306 - state()->_moveLR = 0;
307 - state()->_moveFB = 0;
292 + state()._moveLR = 0;
293 + state()._moveFB = 0;
308 294 }
309 295 }
310 296