Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Explosion.cpp
Go to the documentation of this file.
1#include "Explosion.h"
2
3void Explosion::Update(const GameTime& gameTime)
4{
5 m_pAnimation->Update(gameTime);
6}
7
8
9void Explosion::Draw(SpriteBatch& spriteBatch)
10{
11 if (IsActive())
12 {
13 Vector2 center = m_pAnimation->GetFrame(0)->GetCenter();
14 spriteBatch.Draw(m_pAnimation, m_position, Color::White, center, Vector2::ONE * m_scale, m_rotation);
15 }
16}
17
18
19void Explosion::Activate(const Vector2 position, const float scale)
20{
21 SetPosition(position);
22 m_scale = scale;
23 m_rotation = Math::GetRandomFloat() * 2 * Math::PI;
24 m_pAnimation->SetLoopCount(0);
25 m_pAnimation->Play();
26 if (m_pSound) m_pSound->Play();
27}
virtual void SetPosition(const Vector2 position)
Sets the explosion's position.
Definition Explosion.h:49
virtual void Draw(SpriteBatch &spriteBatch)
Render the explosion.
Definition Explosion.cpp:9
virtual bool IsActive() const
Checks if the explosion is active.
Definition Explosion.h:34
virtual void Update(const GameTime &gameTime)
Update the explosion.
Definition Explosion.cpp:3
virtual void Activate(const Vector2 position, const float scale=1)
Activates the explosion.
Definition Explosion.cpp:19
virtual void Update(const GameTime &gameTime)
Updates the animation.
Definition Animation.cpp:40
virtual void SetLoopCount(uint16_t loops=-1)
Sets how many times the animation will run before it stops.
Definition Animation.h:90
virtual void Play()
Starts or resumes the animation.
Definition Animation.h:79
virtual Region * GetFrame(const int index)
Gets a pointer to the indexed frame.
Definition Animation.h:59
static const Color White
White.
Definition Color.h:201
Contains timing values for game updates and rendering.
Definition GameTime.h:21
static float GetRandomFloat()
Get a random number between zero and one.
Definition MathUtil.h:48
static const float PI
Represents the value of pi.
Definition MathUtil.h:25
Vector2 GetCenter()
The center position of the region.
Definition Region.h:110
Enables a group of sprites to be drawn using the same settings.
Definition SpriteBatch.h:48
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).
Definition Vector2.h:21
static const Vector2 ONE
A vector with both of its components set to one.
Definition Vector2.h:32