1 /* 2 * This source file is part of libRocket, the HTML/CSS Interface Middleware 3 * 4 * For the latest information, see http://www.librocket.com 5 * 6 * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 * THE SOFTWARE. 25 * 26 */ 27 28 #ifndef ROCKETINVADERSGAME_H 29 #define ROCKETINVADERSGAME_H 30 31 #include <Rocket/Core/Types.h> 32 #include <Rocket/Core/Texture.h> 33 34 class Shield; 35 class Invader; 36 class Defender; 37 class Mothership; 38 39 /** 40 Runs the game. 41 - Updates the Invader positions, animations and bombs. 42 - Updates the player position and bullets 43 44 @author Lloyd Weehuizen 45 */ 46 47 class Game 48 { 49 public: 50 Game(); 51 ~Game(); 52 53 /// Initialise a new game 54 void Initialise(); 55 56 /// Update the game 57 void Update(); 58 59 /// Render the game 60 void Render(); 61 62 /// Access the defender 63 Defender* GetDefender(); 64 /// Access the invaders 65 Invader* GetInvader(int index); 66 /// Get the total number of invaders 67 int GetNumInvaders(); 68 69 /// Returns true if the given invader can drop bomb 70 bool CanDropBomb(int invader_index); 71 72 /// Access the shields. 73 Shield* GetShield(int index); 74 /// Get the total number of shields 75 int GetNumShields(); 76 77 /// Adds a score onto the player's score. 78 void AddScore(int score); 79 /// Sets the player's score. 80 void SetScore(int score); 81 /// Sets the player's high-score. 82 void SetHighScore(int score); 83 /// Set the number of defender lives. 84 void SetLives(int lives); 85 /// Set the current wave 86 void SetWave(int wave); 87 /// Remove a defender life 88 void RemoveLife(); 89 /// Checks if the game is over 90 bool IsGameOver() const; 91 92 /// Get the dimensions of the game window. 93 const Rocket::Core::Vector2f GetWindowDimensions(); 94 95 private: 96 97 // The current invaders 98 Invader** invaders; 99 // The direction they're moving 100 float current_invader_direction; 101 // Time of the last invader update 102 Rocket::Core::Time invader_frame_start; 103 // How often the invaders move 104 Rocket::Core::Time invader_move_freq; 105 // Is the game over 106 bool game_over; 107 108 // Helper function to move the invaders 109 void MoveInvaders(); 110 111 // Our current defener 112 Defender* defender; 113 114 // Number of lives the defender has left 115 int defender_lives; 116 117 // The current shields 118 Shield** shields; 119 120 // Texture that contains the sprites 121 Rocket::Core::TextureHandle texture; 122 123 void InitialiseShields(); 124 void InitialiseWave(); 125 void OnGameOver(); 126 }; 127 128 #endif 129