7std::vector<Explosion *> Level::s_explosions;
27 pPlayerShip->
Hit(std::numeric_limits<float>::max());
28 pEnemyShip->
Hit(std::numeric_limits<float>::max());
40 m_totalSectorCount = m_sectorCount.
X * m_sectorCount.
Y;
42 m_pSectors =
new std::vector<GameObject *>[m_totalSectorCount];
53 for (
int i = 0; i < 100; i++)
56 m_projectiles.push_back(pProjectile);
78 delete m_pCollisionManager;
80 m_gameObjectIt = m_gameObjects.begin();
81 for (; m_gameObjectIt != m_gameObjects.end(); m_gameObjectIt++)
83 delete (*m_gameObjectIt);
94 if (s_explosions.size() == 0) {
99 for (
int i = 0; i < 10; i++)
103 pExplosion->
SetSound(pExplosionSound);
104 s_explosions.push_back(pExplosion);
120 for (
unsigned int i = 0; i < m_totalSectorCount; i++)
122 m_pSectors[i].clear();
125 m_gameObjectIt = m_gameObjects.begin();
126 for (; m_gameObjectIt != m_gameObjects.end(); m_gameObjectIt++)
129 pGameObject->
Update(gameTime);
132 for (
unsigned int i = 0; i < m_totalSectorCount; i++)
134 if (m_pSectors[i].size() > 1)
136 CheckCollisions(m_pSectors[i]);
140 m_explosionIt = s_explosions.begin();
141 for (; m_explosionIt != s_explosions.end(); m_explosionIt++)
143 (*m_explosionIt)->Update(gameTime);
159 int minX = (int)(position.
X - halfDimensions.
X - 0.5f);
160 int maxX = (int)(position.
X + halfDimensions.
X + 0.5f);
161 int minY = (int)(position.
Y - halfDimensions.
Y - 0.5f);
162 int maxY = (int)(position.
Y + halfDimensions.
Y + 0.5f);
176 for (
int x = minX; x <= maxX; x++)
178 for (
int y = minY; y <= maxY; y++)
180 int index = y * (int)m_sectorCount.
X + x;
182 m_pSectors[index].push_back(pGameObject);
192 for (
unsigned int i = 0; i < s_explosions.size(); i++)
194 if (!s_explosions[i]->IsActive())
196 pExplosion = s_explosions[i];
201 if (!pExplosion)
return;
203 const float aproximateTextureRadius = 120;
205 const float scaleToObjectSize = (1 / aproximateTextureRadius) * objectRadius * 2;
206 const float dramaticEffect = 2.2f;
207 const float scale = scaleToObjectSize * dramaticEffect;
218void Level::CheckCollisions(std::vector<GameObject *> &gameObjects)
220 const unsigned int objectCount = (
unsigned int)gameObjects.size();
224 for (
unsigned int i = 0; i < objectCount - 1; i++)
226 pFirst = gameObjects[i];
229 for (
unsigned int j = i + 1; j < objectCount; j++)
233 pSecond = gameObjects[j];
251 m_gameObjectIt = m_gameObjects.begin();
252 for (; m_gameObjectIt != m_gameObjects.end(); m_gameObjectIt++)
255 pGameObject->
Draw(spriteBatch);
261 spriteBatch.
Begin(SpriteSortMode::Deferred, BlendState::Additive);
263 m_explosionIt = s_explosions.begin();
264 for (; m_explosionIt != s_explosions.end(); m_explosionIt++)
266 (*m_explosionIt)->Draw(spriteBatch);
void PlayerShootsEnemy(GameObject *pObject1, GameObject *pObject2)
void PlayerCollidesWithEnemy(GameObject *pObject1, GameObject *pObject2)
Represents a blaster weapon that can be fired by a game object.
Represents a collision manager that can be used to manage collisions between game objects.
virtual void CheckCollision(GameObject *pGameObject1, GameObject *pGameObject2)
Check for collisions between game objects.
virtual void AddNonCollisionType(const CollisionType type1, const CollisionType type2)
Add a non-collision type to the manager.
virtual void AddCollisionType(const CollisionType type1, const CollisionType type2, OnCollision callback)
Add a collision type to the manager.
Represents a type of collision.
static const CollisionType Projectile
static const CollisionType Ship
static const CollisionType Enemy
static const CollisionType Player
Represents an enemy ship.
virtual void Hit(const float damage)
Applies damage to the ship.
Represents an explosion animation in the game.
virtual void SetAnimation(Animation *pAnimation)
Sets the explosion's animation.
virtual void SetSound(AudioSample *pSound)
Set the sound that will be played when the explosion is activated.
virtual void Activate(const Vector2 position, const float scale=1)
Activates the explosion.
Represents a game object in the game. This is the base class for all objects that can be updated,...
static void SetCurrentLevel(Level *pLevel)
Set the current level.
virtual void Activate()
Activate the object.
virtual bool HasMask(CollisionType mask) const
Check if the object has a specific collision bit-mask.
virtual bool IsActive() const
Flag to determine if the object is active.
virtual void Deactivate()
Deactivate the object.
virtual Vector2 GetHalfDimensions() const
Get the half dimensions of the object.
virtual void Draw(SpriteBatch &spriteBatch)=0
Render the object.
virtual float GetCollisionRadius() const
Get the collision radius of the object.
virtual void Update(const GameTime &gameTime)
Update the object.
virtual Vector2 & GetPosition()
Get the position of the object.
Represents timing and framing values for texture animations.
virtual void Stop()
Stops the animation.
Represents a 2D grid of texels.
static const Color White
White.
static int GetScreenHeight()
Gets the screen width in pixels.
static int GetScreenWidth()
Gets the screen width in pixels.
Contains timing values for game updates and rendering.
static T Clamp(const T min, const T max, const T value)
Restricts a value to be within a specified range.
Loads and manages the lifespan of objects from external files.
T * Load(const std::string &path, const bool cache=true, const bool appendContentPath=true)
Load and manage a resource.
float GetAlpha() const
Gets the overall screen transition alpha value (or opacity). This is handy for fading screens in and ...
virtual void Exit()
Tells the screen to transition out. When the screen has completed its transition, UnloadContent() wil...
Enables a group of sprites to be drawn using the same settings.
void Begin(const SpriteSortMode sortMode=SpriteSortMode::Deferred, const BlendState blendState=BlendState::Alpha, ALLEGRO_TRANSFORM *pTransformation=NULL)
Begins a sprite batch operation.
void End()
Flushes the sprite batch and restores the device state to how it was before Begin was called.
void Draw(const Texture *pTexture, const Vector2 position, const Region region, const Color color=Color::White, const Vector2 origin=Vector2::ZERO, const Vector2 scale=Vector2::ONE, const float rotation=0, const float drawDepth=0)
Adds a sprite to a batch of sprites to be rendered.
Defines a vector with 2 components (x and y).
float Y
The y-coordinate of the vector.
static const Vector2 UNIT_Y
A unit vector on the y-axis.
static const Vector2 ZERO
A vector with both of its components set to zero.
float X
The x-coordinate of the vector.
virtual void AddGameObject(GameObject *pGameObject)
Add a game object to the level. This object will be updated, rendered, and checked for collisions.
virtual void SpawnExplosion(GameObject *pExplodingObject)
Spawn an explosion at a specific position.
virtual GameplayScreen * GetGameplayScreen() const
Get a pointer to the gameplay screen.
Level()
Instantiate a level object.
virtual void Draw(SpriteBatch &spriteBatch)
Render the level, and all of the game objects within it.
virtual void LoadContent(ResourceManager &resourceManager)
Load the content for the level, including game objects and resources.
virtual bool IsScreenTransitioning() const
Check if the screen is transitioning.
virtual void Update(const GameTime &gameTime)
Update the level.
virtual float GetAlpha() const
Get the alpha value of the screen.
virtual CollisionManager * GetCollisionManager()
Get a pointer to the collision manager.
virtual void UpdateSectorPosition(GameObject *pGameObject)
Update the position of a game object within the level, based on its collision sector (only objects wi...
virtual void HandleInput(const InputState &input)
Handle input for the level.
Represents the player's ship.
virtual void HandleInput(const InputState &input)
Handles input for the player ship.
virtual void LoadContent(ResourceManager &resourceManager)
Loads the content for the player ship.
Represents a projectile that can be fired by a weapon.
virtual float GetDamage() const
Get the amount of damage the projectile will deal.
virtual void Hit(const float damage)
Applies damage to the ship.
virtual void AttachItem(IAttachment *item, Vector2 position)
Attaches a weapon to the ship.
virtual void SetProjectilePool(std::vector< Projectile * > *pProjectiles)
Set the pool of projectiles that the weapon can fire.