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 ROCKETINVADERSINVADER_H
29 #define ROCKETINVADERSINVADER_H
30 
31 #include <Rocket/Core/Types.h>
32 
33 class Game;
34 
35 /**
36 	An alien invader.
37 
38 	@author Lloyd Weehuizen
39  */
40 
41 class Invader
42 {
43 public:
44 	enum InvaderType { UNKNOWN, RANK1, RANK2, RANK3, MOTHERSHIP };
45 	enum BombType { NONE, RAY, MISSILE };
46 
47 	/// Construct the invader
48 	Invader(Game* game, InvaderType type, int index);
49 	~Invader();
50 
51 	/// Set the invaders screen position
52 	/// @param position Position in screen space
53 	void SetPosition(const Rocket::Core::Vector2f& position);
54 	/// Get the current invader position
55 	/// @returns The invaders position in screen space
56 	const Rocket::Core::Vector2f& GetPosition() const;
57 
58 	/// Update the invader
59 	virtual void Update();
60 
61 	/// Render the invader
62 	void Render();
63 
64 	/// Update the invaders animation
65 	void UpdateAnimation();
66 
67 	/// The current invaders state
68 	enum InvaderState { ALIVE, EXPLODING, DEAD };
69 	/// Get the current invader state
70 	/// @returns Invader state
71 	InvaderState GetState();
72 
73 	/// Returns true if the position hits the invader
74 	/// If a hit is detected, will explode and start the death timer
75 	/// @param position Position to do the hit check at
76 	/// @returns If the invader was hit
77 	bool CheckHit(const Rocket::Core::Vector2f& position);
78 
79 protected:
80 	// Game this invader is in
81 	Game* game;
82 	// The index/id of this invader
83 	int invader_index;
84 
85 	// The invader type we represent
86 	InvaderType type;
87 	// The current position in screen space of the invader
88 	Rocket::Core::Vector2f position;
89 	// Our current animation frame
90 	int animation_frame;
91 
92 	// Our current state
93 	InvaderState state;
94 
95 	// Our current in-flight bomb, or none. (may be not none if we're dead.)
96 	BombType bomb;
97 	// The current position of the bomb in screen space
98 	Rocket::Core::Vector2f bomb_position;
99 	// The animation frame the bomb is on
100 	int bomb_animation_frame;
101 	// When the last bomb update occured
102 	float bomb_frame_start;
103 	// Probability of us dropping a bomb - this is calculated
104 	// at construction time and based on our rank and the game
105 	// difficulty level
106 	float bomb_probability;
107 
108 	// Time when we should die - 0, until we're hit
109 	float death_time;
110 
111 	int GetSpriteIndex() const;
112 };
113 
114 #endif
115