gametimer.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
  3. * All rights reserved.
  4. *
  5. * This file is part of Harmattan SmashMiner OpenGL game application.
  6. *
  7. * Harmattan SmashMiner OpenGL Example Application version 1.0.0
  8. *
  9. * Latest update: 15.4.2011
  10. *
  11. * The Harmattan SmashMiner OpenGL example application demonstrates how to use
  12. * the OpenGL ES in Harmattan devices.
  13. *
  14. * This example is provided as a starting point for 3rd party
  15. * developers (you) to ease the implementation of OpenGL based
  16. * games. Ideas, parts of code or methodologies that this
  17. * example application uses can be freely used without restrictions.
  18. *
  19. * See file README.txt how to build and compile this example application
  20. * in the Harmattan SDK environment.
  21. *
  22. * See file INSTALL.txt to find out what is required to run this
  23. * application and how to install the application to the device or
  24. * alternatively in QEMU-emulator.
  25. *
  26. * The LICENSE.txt file explains the license this software is provided
  27. * with. A copy of the same license is included in this source file.
  28. *
  29. */
  30. /*
  31. * Copyright (C) 2011 by Nokia Corporation.
  32. *
  33. * Permission is hereby granted, free of charge, to any person obtaining a copy
  34. * of this software and associated documentation files (the "Software"), to deal
  35. * in the Software without restriction, including without limitation the rights
  36. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  37. * copies of the Software, and to permit persons to whom the Software is
  38. * furnished to do so, subject to the following conditions:
  39. *
  40. * The above copyright notice and this permission notice shall be included in
  41. * all copies or substantial portions of the Software.
  42. *
  43. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  44. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  45. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  46. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  47. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  48. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  49. * THE SOFTWARE.
  50. */
  51. #ifndef GAMETIMER_H
  52. #define GAMETIMER_H
  53. #include "defines.h" // include this before anything else.
  54. #include <QObject>
  55. class GameTimer : public QObject
  56. {
  57. Q_OBJECT
  58. friend class TimerManager;
  59. public:
  60. /*!
  61. * \enum TimerType
  62. * Timer types for identifying GameTimer instances.
  63. */
  64. enum TimerType {
  65. // game-state-related timers.
  66. /// Timer type for identifying a ''Get Ready'' game state timer (game play starting)
  67. stateGetReadyTimer = 0,
  68. /// Timer type for indentifying a game state timer used when changing the game level
  69. stateLevelChangingTimer,
  70. /// Timer type for identifying a timer used when player crashes
  71. statePlayerCrashedTimer,
  72. /// Timer type for indentifying a ''Game Over'' game state timer
  73. stateGameOverTimer,
  74. // spaceship-related timers.
  75. /// When ''Ship safe''-timer is on the miner is in protected mode.
  76. shipSafeTimer,
  77. /// ''Ball-to-cone''-mode timer is used to animate the ship from ball mode to cone mode
  78. shipBall2ConeTimer,
  79. /// ''Cone-to-ball''-mode timer is used to animate the ship from cone mode to ball mode
  80. shipCone2BallTimer,
  81. // effect timers.
  82. /// To identify timer used for hyper jump effects
  83. hyperJumpOutTimer,
  84. /// To identify timer used for hyper jump effects
  85. hyperJumpInTimer,
  86. /// To identify timer used for bomb effect
  87. bombEffectTimer,
  88. // other timers.
  89. /// To identify timer used for populating game objects to game
  90. moreObjectsTimer,
  91. // Keep this count at the end of timer types:
  92. /// To keep the count of timer types
  93. NumTimers
  94. };
  95. public:
  96. explicit GameTimer(TimerType type, int endTime, QObject *parent = 0);
  97. void start(int startTime = 0);
  98. void stop();
  99. bool isActive() const;
  100. bool isFirstQuarterTime();
  101. bool isHalfTime();
  102. bool isLastQuarterTime();
  103. bool isFullTime();
  104. /*! Returns the current time of the timer
  105. * \return Current running time of the timer.
  106. */
  107. inline int time() const { return currentTime; }
  108. /*! Returns the timer length --- the ending time of the timer.
  109. * \return Length of the timer
  110. */
  111. inline int timerLength() const { return fullTime; }
  112. /*! Returns the type of the timer
  113. * \return One of \c GameTimer::TimerType game timer enumeration types
  114. */
  115. inline TimerType type() const { return timerType; }
  116. signals:
  117. public slots:
  118. protected:
  119. void incTime(int timeStep);
  120. private:
  121. TimerType timerType;
  122. int currentTime;
  123. int firstQuarterTime;
  124. int halfTime;
  125. int lastQuarterTime;
  126. int fullTime;
  127. bool firstQuarterTimeReplied;
  128. bool halfTimeReplied;
  129. bool lastQuarterTimeReplied;
  130. bool fullTimeReplied;
  131. };
  132. class LocationTimer : public GameTimer
  133. {
  134. Q_OBJECT
  135. public:
  136. LocationTimer(TimerType, int eTime, QObject *parent = 0);
  137. inline FPtype posX() { return positionX; }
  138. inline FPtype posY() { return positionY; }
  139. inline void setPosX(FPtype posX) { positionX = posX; }
  140. inline void setPosy(FPtype posY) { positionY = posY; }
  141. private:
  142. FPtype positionX;
  143. FPtype positionY;
  144. };
  145. class BombTimer : public LocationTimer
  146. {
  147. Q_OBJECT
  148. public:
  149. BombTimer(TimerType, int eTime, QObject *parent = 0);
  150. inline FPtype shockRadius() { return -20.0 + (FPtype) time() * 350.0 / (FPtype) timerLength(); }
  151. inline FPtype lightRadius() { return -40.0 + (FPtype) time() * 325.0 / (FPtype) timerLength(); }
  152. };
  153. #endif // GAMETIMER_H