doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GameBearShootWindow.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 #include "../idlib/precompiled.h"
29 #pragma hdrstop
30 
31 #include "../framework/Session_local.h"
32 
33 #include "DeviceContext.h"
34 #include "Window.h"
35 #include "UserInterfaceLocal.h"
36 #include "GameBearShootWindow.h"
37 
38 
39 #define BEAR_GRAVITY 240
40 #define BEAR_SIZE 24.f
41 #define BEAR_SHRINK_TIME 2000.f
42 
43 #define MAX_WINDFORCE 100.f
44 
45 idCVar bearTurretAngle( "bearTurretAngle", "0", CVAR_FLOAT, "" );
46 idCVar bearTurretForce( "bearTurretForce", "200", CVAR_FLOAT, "" );
47 
48 /*
49 *****************************************************************************
50 * BSEntity
51 ****************************************************************************
52 */
54  game = _game;
55  visible = true;
56 
58  materialName = "";
59  material = NULL;
60  width = height = 8;
61  rotation = 0.f;
62  rotationSpeed = 0.f;
63  fadeIn = false;
64  fadeOut = false;
65 
66  position.Zero();
67  velocity.Zero();
68 }
69 
71 }
72 
73 /*
74 ======================
75 BSEntity::WriteToSaveGame
76 ======================
77 */
78 void BSEntity::WriteToSaveGame( idFile *savefile ) {
79 
81 
82  savefile->Write( &width, sizeof(width) );
83  savefile->Write( &height, sizeof(height) );
84  savefile->Write( &visible, sizeof(visible) );
85 
86  savefile->Write( &entColor, sizeof(entColor) );
87  savefile->Write( &position, sizeof(position) );
88  savefile->Write( &rotation, sizeof(rotation) );
89  savefile->Write( &rotationSpeed, sizeof(rotationSpeed) );
90  savefile->Write( &velocity, sizeof(velocity) );
91 
92  savefile->Write( &fadeIn, sizeof(fadeIn) );
93  savefile->Write( &fadeOut, sizeof(fadeOut) );
94 }
95 
96 /*
97 ======================
98 BSEntity::ReadFromSaveGame
99 ======================
100 */
102  game = _game;
103 
104  game->ReadSaveGameString( materialName, savefile );
106 
107  savefile->Read( &width, sizeof(width) );
108  savefile->Read( &height, sizeof(height) );
109  savefile->Read( &visible, sizeof(visible) );
110 
111  savefile->Read( &entColor, sizeof(entColor) );
112  savefile->Read( &position, sizeof(position) );
113  savefile->Read( &rotation, sizeof(rotation) );
114  savefile->Read( &rotationSpeed, sizeof(rotationSpeed) );
115  savefile->Read( &velocity, sizeof(velocity) );
116 
117  savefile->Read( &fadeIn, sizeof(fadeIn) );
118  savefile->Read( &fadeOut, sizeof(fadeOut) );
119 }
120 
121 /*
122 ======================
123 BSEntity::SetMaterial
124 ======================
125 */
126 void BSEntity::SetMaterial(const char* name) {
127  materialName = name;
128  material = declManager->FindMaterial( name );
129  material->SetSort( SS_GUI );
130 }
131 
132 /*
133 ======================
134 BSEntity::SetSize
135 ======================
136 */
137 void BSEntity::SetSize( float _width, float _height ) {
138  width = _width;
139  height = _height;
140 }
141 
142 /*
143 ======================
144 BSEntity::SetVisible
145 ======================
146 */
147 void BSEntity::SetVisible( bool isVisible ) {
148  visible = isVisible;
149 }
150 
151 /*
152 ======================
153 BSEntity::Update
154 ======================
155 */
156 void BSEntity::Update( float timeslice ) {
157 
158  if ( !visible ) {
159  return;
160  }
161 
162  // Fades
163  if ( fadeIn && entColor.w < 1.f ) {
164  entColor.w += 1 * timeslice;
165  if ( entColor.w >= 1.f ) {
166  entColor.w = 1.f;
167  fadeIn = false;
168  }
169  }
170  if ( fadeOut && entColor.w > 0.f ) {
171  entColor.w -= 1 * timeslice;
172  if ( entColor.w <= 0.f ) {
173  entColor.w = 0.f;
174  fadeOut = false;
175  }
176  }
177 
178  // Move the entity
179  position += velocity * timeslice;
180 
181  // Rotate Entity
182  rotation += rotationSpeed * timeslice;
183 }
184 
185 /*
186 ======================
187 BSEntity::Draw
188 ======================
189 */
191  if ( visible ) {
193  }
194 }
195 
196 /*
197 *****************************************************************************
198 * idGameBearShootWindow
199 ****************************************************************************
200 */
202  dc = d;
203  gui = g;
204  CommonInit();
205 }
206 
208  gui = g;
209  CommonInit();
210 }
211 
213  entities.DeleteContents(true);
214 }
215 
216 /*
217 =============================
218 idGameBearShootWindow::WriteToSaveGame
219 =============================
220 */
222  idWindow::WriteToSaveGame( savefile );
223 
224  gamerunning.WriteToSaveGame( savefile );
225  onFire.WriteToSaveGame( savefile );
226  onContinue.WriteToSaveGame( savefile );
227  onNewGame.WriteToSaveGame( savefile );
228 
229  savefile->Write( &timeSlice, sizeof(timeSlice) );
230  savefile->Write( &timeRemaining, sizeof(timeRemaining) );
231  savefile->Write( &gameOver, sizeof(gameOver) );
232 
233  savefile->Write( &currentLevel, sizeof(currentLevel) );
234  savefile->Write( &goalsHit, sizeof(goalsHit) );
235  savefile->Write( &updateScore, sizeof(updateScore) );
236  savefile->Write( &bearHitTarget, sizeof(bearHitTarget) );
237 
238  savefile->Write( &bearScale, sizeof(bearScale) );
239  savefile->Write( &bearIsShrinking, sizeof(bearIsShrinking) );
240  savefile->Write( &bearShrinkStartTime, sizeof(bearShrinkStartTime) );
241 
242  savefile->Write( &turretAngle, sizeof(turretAngle) );
243  savefile->Write( &turretForce, sizeof(turretForce) );
244 
245  savefile->Write( &windForce, sizeof(windForce) );
246  savefile->Write( &windUpdateTime, sizeof(windUpdateTime) );
247 
248  int numberOfEnts = entities.Num();
249  savefile->Write( &numberOfEnts, sizeof(numberOfEnts) );
250 
251  for ( int i=0; i<numberOfEnts; i++ ) {
252  entities[i]->WriteToSaveGame( savefile );
253  }
254 
255  int index;
256  index = entities.FindIndex( turret );
257  savefile->Write( &index, sizeof(index) );
258  index = entities.FindIndex( bear );
259  savefile->Write( &index, sizeof(index) );
260  index = entities.FindIndex( helicopter );
261  savefile->Write( &index, sizeof(index) );
262  index = entities.FindIndex( goal );
263  savefile->Write( &index, sizeof(index) );
264  index = entities.FindIndex( wind );
265  savefile->Write( &index, sizeof(index) );
266  index = entities.FindIndex( gunblast );
267  savefile->Write( &index, sizeof(index) );
268 }
269 
270 /*
271 =============================
272 idGameBearShootWindow::ReadFromSaveGame
273 =============================
274 */
276  idWindow::ReadFromSaveGame( savefile );
277 
278  // Remove all existing entities
279  entities.DeleteContents(true);
280 
281  gamerunning.ReadFromSaveGame( savefile );
282  onFire.ReadFromSaveGame( savefile );
283  onContinue.ReadFromSaveGame( savefile );
284  onNewGame.ReadFromSaveGame( savefile );
285 
286  savefile->Read( &timeSlice, sizeof(timeSlice) );
287  savefile->Read( &timeRemaining, sizeof(timeRemaining) );
288  savefile->Read( &gameOver, sizeof(gameOver) );
289 
290  savefile->Read( &currentLevel, sizeof(currentLevel) );
291  savefile->Read( &goalsHit, sizeof(goalsHit) );
292  savefile->Read( &updateScore, sizeof(updateScore) );
293  savefile->Read( &bearHitTarget, sizeof(bearHitTarget) );
294 
295  savefile->Read( &bearScale, sizeof(bearScale) );
296  savefile->Read( &bearIsShrinking, sizeof(bearIsShrinking) );
297  savefile->Read( &bearShrinkStartTime, sizeof(bearShrinkStartTime) );
298 
299  savefile->Read( &turretAngle, sizeof(turretAngle) );
300  savefile->Read( &turretForce, sizeof(turretForce) );
301 
302  savefile->Read( &windForce, sizeof(windForce) );
303  savefile->Read( &windUpdateTime, sizeof(windUpdateTime) );
304 
305  int numberOfEnts;
306  savefile->Read( &numberOfEnts, sizeof(numberOfEnts) );
307 
308  for ( int i=0; i<numberOfEnts; i++ ) {
309  BSEntity *ent;
310 
311  ent = new BSEntity( this );
312  ent->ReadFromSaveGame( savefile, this );
313  entities.Append( ent );
314  }
315 
316  int index;
317  savefile->Read( &index, sizeof(index) );
318  turret = entities[index];
319  savefile->Read( &index, sizeof(index) );
320  bear = entities[index];
321  savefile->Read( &index, sizeof(index) );
323  savefile->Read( &index, sizeof(index) );
324  goal = entities[index];
325  savefile->Read( &index, sizeof(index) );
326  wind = entities[index];
327  savefile->Read( &index, sizeof(index) );
329 }
330 
331 /*
332 =============================
333 idGameBearShootWindow::ResetGameState
334 =============================
335 */
337  gamerunning = false;
338  gameOver = false;
339  onFire = false;
340  onContinue = false;
341  onNewGame = false;
342 
343  // Game moves forward 16 milliseconds every frame
344  timeSlice = 0.016f;
345  timeRemaining = 60.f;
346  goalsHit = 0;
347  updateScore = false;
348  bearHitTarget = false;
349  currentLevel = 1;
350  turretAngle = 0.f;
351  turretForce = 200.f;
352  windForce = 0.f;
353  windUpdateTime = 0;
354 
355  bearIsShrinking = false;
357  bearScale = 1.f;
358 }
359 
360 /*
361 =============================
362 idGameBearShootWindow::CommonInit
363 =============================
364 */
366  BSEntity * ent;
367 
368  // Precache sounds
369  declManager->FindSound( "arcade_beargroan" );
370  declManager->FindSound( "arcade_sargeshoot" );
371  declManager->FindSound( "arcade_balloonpop" );
372  declManager->FindSound( "arcade_levelcomplete1" );
373 
374  // Precache dynamically used materials
375  declManager->FindMaterial( "game/bearshoot/helicopter_broken" );
376  declManager->FindMaterial( "game/bearshoot/goal_dead" );
377  declManager->FindMaterial( "game/bearshoot/gun_blast" );
378 
379  ResetGameState();
380 
381  ent = new BSEntity( this );
382  turret = ent;
383  ent->SetMaterial( "game/bearshoot/turret" );
384  ent->SetSize( 272, 144 );
385  ent->position.x = -44;
386  ent->position.y = 260;
387  entities.Append( ent );
388 
389  ent = new BSEntity( this );
390  ent->SetMaterial( "game/bearshoot/turret_base" );
391  ent->SetSize( 144, 160 );
392  ent->position.x = 16;
393  ent->position.y = 280;
394  entities.Append( ent );
395 
396  ent = new BSEntity( this );
397  bear = ent;
398  ent->SetMaterial( "game/bearshoot/bear" );
399  ent->SetSize( BEAR_SIZE, BEAR_SIZE );
400  ent->SetVisible( false );
401  ent->position.x = 0;
402  ent->position.y = 0;
403  entities.Append( ent );
404 
405  ent = new BSEntity( this );
406  helicopter = ent;
407  ent->SetMaterial( "game/bearshoot/helicopter" );
408  ent->SetSize( 64, 64 );
409  ent->position.x = 550;
410  ent->position.y = 100;
411  entities.Append( ent );
412 
413  ent = new BSEntity( this );
414  goal = ent;
415  ent->SetMaterial( "game/bearshoot/goal" );
416  ent->SetSize( 64, 64 );
417  ent->position.x = 550;
418  ent->position.y = 164;
419  entities.Append( ent );
420 
421  ent = new BSEntity( this );
422  wind = ent;
423  ent->SetMaterial( "game/bearshoot/wind" );
424  ent->SetSize( 100, 40 );
425  ent->position.x = 500;
426  ent->position.y = 430;
427  entities.Append( ent );
428 
429  ent = new BSEntity( this );
430  gunblast = ent;
431  ent->SetMaterial( "game/bearshoot/gun_blast" );
432  ent->SetSize( 64, 64 );
433  ent->SetVisible( false );
434  entities.Append( ent );
435 }
436 
437 /*
438 =============================
439 idGameBearShootWindow::HandleEvent
440 =============================
441 */
442 const char *idGameBearShootWindow::HandleEvent(const sysEvent_t *event, bool *updateVisuals) {
443  int key = event->evValue;
444 
445  // need to call this to allow proper focus and capturing on embedded children
446  const char *ret = idWindow::HandleEvent(event, updateVisuals);
447 
448  if ( event->evType == SE_KEY ) {
449 
450  if ( !event->evValue2 ) {
451  return ret;
452  }
453  if ( key == K_MOUSE1) {
454  // Mouse was clicked
455  } else {
456  return ret;
457  }
458  }
459 
460  return ret;
461 }
462 
463 /*
464 =============================
465 idGameBearShootWindow::ParseInternalVar
466 =============================
467 */
469  if ( idStr::Icmp(_name, "gamerunning") == 0 ) {
470  gamerunning = src->ParseBool();
471  return true;
472  }
473  if ( idStr::Icmp(_name, "onFire") == 0 ) {
474  onFire = src->ParseBool();
475  return true;
476  }
477  if ( idStr::Icmp(_name, "onContinue") == 0 ) {
478  onContinue = src->ParseBool();
479  return true;
480  }
481  if ( idStr::Icmp(_name, "onNewGame") == 0 ) {
482  onNewGame = src->ParseBool();
483  return true;
484  }
485 
486  return idWindow::ParseInternalVar(_name, src);
487 }
488 
489 /*
490 =============================
491 idGameBearShootWindow::GetWinVarByName
492 =============================
493 */
494 idWinVar *idGameBearShootWindow::GetWinVarByName(const char *_name, bool winLookup, drawWin_t** owner) {
495  idWinVar *retVar = NULL;
496 
497  if ( idStr::Icmp(_name, "gamerunning") == 0 ) {
498  retVar = &gamerunning;
499  } else if ( idStr::Icmp(_name, "onFire") == 0 ) {
500  retVar = &onFire;
501  } else if ( idStr::Icmp(_name, "onContinue") == 0 ) {
502  retVar = &onContinue;
503  } else if ( idStr::Icmp(_name, "onNewGame") == 0 ) {
504  retVar = &onNewGame;
505  }
506 
507  if(retVar) {
508  return retVar;
509  }
510 
511  return idWindow::GetWinVarByName(_name, winLookup, owner);
512 }
513 
514 /*
515 =============================
516 idGameBearShootWindow::PostParse
517 =============================
518 */
521 }
522 
523 /*
524 =============================
525 idGameBearShootWindow::Draw
526 =============================
527 */
528 void idGameBearShootWindow::Draw(int time, float x, float y) {
529  int i;
530 
531  //Update the game every frame before drawing
532  UpdateGame();
533 
534  for( i = entities.Num()-1; i >= 0; i-- ) {
535  entities[i]->Draw(dc);
536  }
537 }
538 
539 /*
540 =============================
541 idGameBearShootWindow::Activate
542 =============================
543 */
544 const char *idGameBearShootWindow::Activate(bool activate) {
545  return "";
546 }
547 
548 /*
549 =============================
550 idGameBearShootWindow::UpdateTurret
551 =============================
552 */
554  idVec2 pt;
555  idVec2 turretOrig;
556  idVec2 right;
557  float dot, angle;
558 
559  pt.x = gui->CursorX();
560  pt.y = gui->CursorY();
561  turretOrig.Set( 80.f, 348.f );
562 
563  pt = pt - turretOrig;
564  pt.NormalizeFast();
565 
566  right.x = 1.f;
567  right.y = 0.f;
568 
569  dot = pt * right;
570 
571  angle = RAD2DEG( acosf( dot ) );
572 
573  turretAngle = idMath::ClampFloat( 0.f, 90.f, angle );
574 }
575 
576 /*
577 =============================
578 idGameBearShootWindow::UpdateBear
579 =============================
580 */
582  int time = gui->GetTime();
583  bool startShrink = false;
584 
585  // Apply gravity
587 
588  // Apply wind
590 
591  // Check for collisions
592  if ( !bearHitTarget && !gameOver ) {
593  idVec2 bearCenter;
594  bool collision = false;
595 
596  bearCenter.x = bear->position.x + bear->width/2;
597  bearCenter.y = bear->position.y + bear->height/2;
598 
599  if ( bearCenter.x > (helicopter->position.x + 16) && bearCenter.x < (helicopter->position.x + helicopter->width - 29) ) {
600  if ( bearCenter.y > (helicopter->position.y + 12) && bearCenter.y < (helicopter->position.y + helicopter->height - 7) ) {
601  collision = true;
602  }
603  }
604 
605  if ( collision ) {
606  // balloons pop and bear tumbles to ground
607  helicopter->SetMaterial( "game/bearshoot/helicopter_broken" );
608  helicopter->velocity.y = 230.f;
609  goal->velocity.y = 230.f;
610  session->sw->PlayShaderDirectly( "arcade_balloonpop" );
611 
612  bear->SetVisible( false );
613  if ( bear->velocity.x > 0 ) {
614  bear->velocity.x *= -1.f;
615  }
616  bear->velocity *= 0.666f;
617  bearHitTarget = true;
618  updateScore = true;
619  startShrink = true;
620  }
621  }
622 
623  // Check for ground collision
624  if ( bear->position.y > 380 ) {
625  bear->position.y = 380;
626 
627  if ( bear->velocity.Length() < 25 ) {
628  bear->velocity.Zero();
629  } else {
630  startShrink = true;
631 
632  bear->velocity.y *= -1.f;
633  bear->velocity *= 0.5f;
634 
635  if ( bearScale ) {
636  session->sw->PlayShaderDirectly( "arcade_balloonpop" );
637  }
638  }
639  }
640 
641  // Bear rotation is based on velocity
642  float angle;
643  idVec2 dir;
644 
645  dir = bear->velocity;
646  dir.NormalizeFast();
647 
648  angle = RAD2DEG( atan2( dir.x, dir.y ) );
649  bear->rotation = angle - 90;
650 
651  // Update Bear scale
652  if ( bear->position.x > 650 ) {
653  startShrink = true;
654  }
655 
656  if ( !bearIsShrinking && bearScale && startShrink ) {
657  bearShrinkStartTime = time;
658  bearIsShrinking = true;
659  }
660 
661  if ( bearIsShrinking ) {
662  if ( bearHitTarget ) {
663  bearScale = 1 - ( (float)(time - bearShrinkStartTime) / BEAR_SHRINK_TIME );
664  } else {
665  bearScale = 1 - ( (float)(time - bearShrinkStartTime) / 750 );
666  }
667  bearScale *= BEAR_SIZE;
669 
670  if ( bearScale < 0 ) {
671  gui->HandleNamedEvent( "EnableFireButton" );
672  bearIsShrinking = false;
673  bearScale = 0.f;
674 
675  if ( bearHitTarget ) {
676  goal->SetMaterial( "game/bearshoot/goal" );
677  goal->position.x = 550;
678  goal->position.y = 164;
679  goal->velocity.Zero();
680  goal->velocity.y = (currentLevel-1) * 30;
681  goal->entColor.w = 0.f;
682  goal->fadeIn = true;
683  goal->fadeOut = false;
684 
685  helicopter->SetVisible( true );
686  helicopter->SetMaterial( "game/bearshoot/helicopter" );
687  helicopter->position.x = 550;
688  helicopter->position.y = 100;
691  helicopter->entColor.w = 0.f;
692  helicopter->fadeIn = true;
693  helicopter->fadeOut = false;
694  }
695  }
696  }
697 }
698 
699 /*
700 =============================
701 idGameBearShootWindow::UpdateHelicopter
702 =============================
703 */
705 
706  if ( bearHitTarget && bearIsShrinking ) {
707  if ( helicopter->velocity.y != 0 && helicopter->position.y > 264 ) {
708  helicopter->velocity.y = 0;
709  goal->velocity.y = 0;
710 
711  helicopter->SetVisible( false );
712  goal->SetMaterial( "game/bearshoot/goal_dead" );
713  session->sw->PlayShaderDirectly( "arcade_beargroan", 1 );
714 
715  helicopter->fadeOut = true;
716  goal->fadeOut = true;
717  }
718  } else if ( currentLevel > 1 ) {
719  int height = helicopter->position.y;
720  float speed = (currentLevel-1) * 30;
721 
722  if ( height > 240 ) {
723  helicopter->velocity.y = -speed;
724  goal->velocity.y = -speed;
725  } else if ( height < 30 ) {
726  helicopter->velocity.y = speed;
727  goal->velocity.y = speed;
728  }
729  }
730 }
731 
732 /*
733 =============================
734 idGameBearShootWindow::UpdateButtons
735 =============================
736 */
738 
739  if ( onFire ) {
740  idVec2 vec;
741 
742  gui->HandleNamedEvent( "DisableFireButton" );
743  session->sw->PlayShaderDirectly( "arcade_sargeshoot" );
744 
745  bear->SetVisible( true );
746  bearScale = 1.f;
748 
749  vec.x = idMath::Cos( DEG2RAD(turretAngle) );
750  vec.x += ( 1 - vec.x ) * 0.18f;
751  vec.y = -idMath::Sin( DEG2RAD(turretAngle) );
752 
754 
755  bear->position.x = 80 + ( 96 * vec.x );
756  bear->position.y = 334 + ( 96 * vec.y );
757  bear->velocity.x = vec.x * turretForce;
758  bear->velocity.y = vec.y * turretForce;
759 
760  gunblast->position.x = 55 + ( 96 * vec.x );
761  gunblast->position.y = 310 + ( 100 * vec.y );
762  gunblast->SetVisible( true );
763  gunblast->entColor.w = 1.f;
765  gunblast->fadeOut = true;
766 
767  bearHitTarget = false;
768 
769  onFire = false;
770  }
771 }
772 
773 /*
774 =============================
775 idGameBearShootWindow::UpdateScore
776 =============================
777 */
779 
780  if ( gameOver ) {
781  gui->HandleNamedEvent( "GameOver" );
782  return;
783  }
784 
785  goalsHit++;
786  gui->SetStateString( "player_score", va("%i", goalsHit ) );
787 
788  // Check for level progression
789  if ( !(goalsHit % 5) ) {
790  currentLevel++;
791  gui->SetStateString( "current_level", va("%i", currentLevel ) );
792  session->sw->PlayShaderDirectly( "arcade_levelcomplete1", 3 );
793 
794  timeRemaining += 30;
795  }
796 }
797 
798 /*
799 =============================
800 idGameBearShootWindow::UpdateGame
801 =============================
802 */
804  int i;
805 
806  if ( onNewGame ) {
807  ResetGameState();
808 
809  goal->position.x = 550;
810  goal->position.y = 164;
811  goal->velocity.Zero();
812  helicopter->position.x = 550;
813  helicopter->position.y = 100;
815  bear->SetVisible( false );
816 
818  bearTurretForce.SetFloat( 200.f );
819 
820  gamerunning = true;
821  }
822  if ( onContinue ) {
823  gameOver = false;
824  timeRemaining = 60.f;
825 
826  onContinue = false;
827  }
828 
829  if(gamerunning == true) {
830  int current_time = gui->GetTime();
831  idRandom rnd( current_time );
832 
833  // Check for button presses
834  UpdateButtons();
835 
836  if ( bear ) {
837  UpdateBear();
838  }
839  if ( helicopter && goal ) {
841  }
842 
843  // Update Wind
844  if ( windUpdateTime < current_time ) {
845  float scale;
846  int width;
847 
848  windForce = rnd.CRandomFloat() * ( MAX_WINDFORCE * 0.75f );
849  if (windForce > 0) {
850  windForce += ( MAX_WINDFORCE * 0.25f );
851  wind->rotation = 0;
852  } else {
853  windForce -= ( MAX_WINDFORCE * 0.25f );
854  wind->rotation = 180;
855  }
856 
857  scale = 1.f - (( MAX_WINDFORCE - idMath::Fabs(windForce) ) / MAX_WINDFORCE);
858  width = 100*scale;
859 
860  if ( windForce < 0 ) {
861  wind->position.x = 500 - width + 1;
862  } else {
863  wind->position.x = 500;
864  }
865  wind->SetSize( width, 40 );
866 
867  windUpdateTime = current_time + 7000 + rnd.RandomInt(5000);
868  }
869 
870  // Update turret rotation angle
871  if ( turret ) {
874  }
875 
876  for( i = 0; i < entities.Num(); i++ ) {
877  entities[i]->Update( timeSlice );
878  }
879 
880  // Update countdown timer
883  gui->SetStateString( "time_remaining", va("%2.1f", timeRemaining ) );
884 
885  if ( timeRemaining <= 0.f && !gameOver ) {
886  gameOver = true;
887  updateScore = true;
888  }
889 
890  if ( updateScore ) {
891  UpdateScore();
892  updateScore = false;
893  }
894  }
895 }
GLubyte g
Definition: glext.h:4662
void SetMaterial(const char *name)
virtual void SetStateString(const char *varName, const char *value)
void SetVisible(bool isVisible)
virtual const idSoundShader * FindSound(const char *name, bool makeDefault=true)=0
#define BEAR_GRAVITY
idCVar bearTurretAngle("bearTurretAngle","0", CVAR_FLOAT,"")
idSoundWorld * sw
Definition: Session.h:154
idVec4 colorWhite
Definition: Lib.cpp:116
virtual void Draw(idDeviceContext *dc)
float y
Definition: Vector.h:55
float GetFloat(void) const
Definition: CVarSystem.h:144
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:4804
virtual bool ParseInternalVar(const char *name, idParser *src)
Definition: Window.cpp:1915
virtual void PlayShaderDirectly(const char *name, int channel=-1)=0
GLenum GLint GLint y
Definition: glext.h:2849
static float ClampFloat(float min, float max, float value)
Definition: Math.h:893
float NormalizeFast(void)
Definition: Vector.h:180
case const float
Definition: Callbacks.cpp:62
virtual void WriteToSaveGame(idFile *savefile)
Definition: Window.cpp:3464
idDeviceContext * dc
Definition: Window.h:425
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
GLuint src
Definition: glext.h:5390
GLdouble right
Definition: qgl.h:273
GLenum GLint x
Definition: glext.h:2849
int i
Definition: process.py:33
float Length(void) const
Definition: Vector.h:155
idGameBearShootWindow(idUserInterfaceLocal *gui)
idGameBearShootWindow * game
idCVar bearTurretForce("bearTurretForce","200", CVAR_FLOAT,"")
int Icmp(const char *text) const
Definition: Str.h:667
virtual void WriteToSaveGame(idFile *savefile)
Definition: Winvar.h:137
void Zero(void)
Definition: Vector.h:119
void DrawMaterialRotated(float x, float y, float w, float h, const idMaterial *mat, const idVec4 &color, float scalex=1.0, float scaley=1.0, float angle=0.0f)
Definition: File.h:50
bool ParseBool(void)
Definition: Parser.cpp:2797
int RandomInt(void)
Definition: Random.h:70
virtual void Update(float timeslice)
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup=false, drawWin_t **owner=NULL)
Definition: Vector.h:52
virtual void PostParse()
Definition: Window.cpp:1709
GLuint index
Definition: glext.h:3476
#define BEAR_SIZE
virtual ~BSEntity()
static float Sin(float a)
Definition: Math.h:310
static float Fabs(float f)
Definition: Math.h:779
#define NULL
Definition: Lib.h:88
int evValue2
Definition: sys_public.h:218
virtual float CursorY()
const idMaterial * material
virtual int Read(void *buffer, int len)
Definition: File.cpp:179
float w
Definition: Vector.h:813
float x
Definition: Vector.h:54
void DeleteContents(bool clear)
Definition: List.h:207
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Winvar.h:141
GLenum GLsizei width
Definition: glext.h:2846
BSEntity(idGameBearShootWindow *_game)
#define DEG2RAD(a)
Definition: Math.h:56
void ReadSaveGameString(idStr &string, idFile *savefile)
Definition: Window.cpp:3590
void WriteSaveGameString(const char *string, idFile *savefile)
Definition: Window.cpp:3404
sysEventType_t evType
Definition: sys_public.h:216
GLenum GLsizei GLsizei height
Definition: glext.h:2856
idDeclManager * declManager
void SetSize(float _width, float _height)
virtual const char * Activate(bool activate)
int Append(const type &obj)
Definition: List.h:646
virtual bool ParseInternalVar(const char *name, idParser *src)
idUserInterfaceLocal * gui
Definition: Window.h:427
tuple f
Definition: idal.py:89
virtual void ReadFromSaveGame(idFile *savefile)
virtual void WriteToSaveGame(idFile *savefile)
int Num(void) const
Definition: List.h:265
const GLcharARB * name
Definition: glext.h:3629
#define RAD2DEG(a)
Definition: Math.h:57
idList< BSEntity * > entities
virtual int Write(const void *buffer, int len)
Definition: File.cpp:189
virtual void Draw(int time, float x, float y)
void SetSort(float s) const
Definition: Material.h:513
int FindIndex(const type &obj) const
Definition: List.h:761
virtual const char * HandleEvent(const sysEvent_t *event, bool *updateVisuals)
virtual void WriteToSaveGame(idFile *savefile)
void Set(const float x, const float y)
Definition: Vector.h:114
#define MAX_WINDFORCE
float dot(float a[], float b[])
Definition: Model_lwo.cpp:3883
idSession * session
Definition: Session.cpp:48
char * va(const char *fmt,...)
Definition: Str.cpp:1568
virtual const char * HandleEvent(const sysEvent_t *event, bool *updateVisuals)
Definition: Window.cpp:709
virtual void HandleNamedEvent(const char *namedEvent)
void SetFloat(const float value)
Definition: CVarSystem.h:149
virtual float CursorX()
virtual idWinVar * GetWinVarByName(const char *_name, bool winLookup=false, drawWin_t **owner=NULL)
Definition: Window.cpp:1776
#define BEAR_SHRINK_TIME
float CRandomFloat(void)
Definition: Random.h:86
virtual void ReadFromSaveGame(idFile *savefile)
Definition: Window.cpp:3607
virtual void ReadFromSaveGame(idFile *savefile, idGameBearShootWindow *_game)
static float Cos(float a)
Definition: Math.h:346