Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Particle.h
Go to the documentation of this file.
1
2/*
3 ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
4 ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
5 █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
6 ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
7 ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
8 ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
9 /vvvvvvvvvvvvvvvvvvv \=========================================,
10 `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
11 Katana Engine \/ © 2012 - Shuriken Studios LLC
12 http://www.shurikenstudios.com
13*/
14
15#pragma once
16
17#include "KatanaEngine.h"
18
19namespace KatanaEngine
20{
21
23 class Particle : public IParticle
24 {
25
26 public:
27
29 virtual ~Particle() { }
30
33 virtual bool IsActive() const { return m_lifeRemaining > 0; }
34
37 virtual Vector2 GetPosition() const { return m_position; }
38
41 virtual Vector2 GetVelocity() const { return m_velocity; }
42
45 virtual Color GetColor() const { return m_color; }
46
49 virtual float GetScale() const { return m_scale; }
50
53 virtual float GetLifeSpan() const { return m_lifeSpan; }
54
57 virtual float GetLifeRemaining() const { return m_lifeRemaining; }
58
61 virtual void SetPosition(const Vector2 position) { m_position = position; }
62
65 virtual void SetVelocity(const Vector2 velocity) { m_velocity = velocity; }
66
69 virtual void SetColor(const Color color) { m_color = color; }
70
73 virtual void SetScale(const float scale) { m_scale = scale; }
74
77 virtual void SetLifeSpan(const float lifeSpan) {
78 m_lifeSpan = lifeSpan;
79 }
80
81 virtual float GetLifePercentage() const { return m_lifePercentage; }
82
83 virtual void Initialize(Vector2& position) {
84 m_position = position;
85 m_lifeRemaining = m_lifeSpan;
86 }
87
88 virtual void Update(const GameTime& gameTime)
89 {
90 const float elapsed = (float)gameTime.GetElapsedTime();
91 m_lifeRemaining -= elapsed;
92 if (m_lifeRemaining < 0) m_lifeRemaining = 0;
93 m_lifePercentage = m_lifeRemaining / m_lifeSpan;
94 m_position += m_velocity * elapsed;
95 }
96
97
98 private:
99
100 Vector2 m_position;
101 Vector2 m_velocity;
102 Color m_color = Color::White;
103 float m_scale = 1;
104
105 float m_lifeSpan = 0;
106 float m_lifeRemaining = 0;
107 float m_lifePercentage = 0;
108 };
109
110}
Represents a four-component color using red, green, blue, and alpha data.
Definition Color.h:21
static const Color White
White.
Definition Color.h:201
Contains timing values for game updates and rendering.
Definition GameTime.h:21
double GetElapsedTime() const
Gets the time in seconds since last frame.
Definition GameTime.h:30
Interface for a particle.
Definition IParticle.h:24
Instantiate a basic particle.
Definition Particle.h:24
virtual bool IsActive() const
Gets whether the particle is active.
Definition Particle.h:33
virtual float GetScale() const
Gets the scale of the particle.
Definition Particle.h:49
virtual float GetLifePercentage() const
Definition Particle.h:81
virtual Vector2 GetPosition() const
Gets the position of the particle.
Definition Particle.h:37
virtual Vector2 GetVelocity() const
Gets the velocity of the particle.
Definition Particle.h:41
virtual void SetPosition(const Vector2 position)
Sets the position of the particle.
Definition Particle.h:61
virtual void SetVelocity(const Vector2 velocity)
Sets the velocity of the particle.
Definition Particle.h:65
virtual void SetLifeSpan(const float lifeSpan)
Sets the life span of the particle.
Definition Particle.h:77
virtual float GetLifeSpan() const
Gets the life span of the particle.
Definition Particle.h:53
virtual Color GetColor() const
Gets the color of the particle.
Definition Particle.h:45
virtual void Update(const GameTime &gameTime)
Definition Particle.h:88
virtual void Initialize(Vector2 &position)
Definition Particle.h:83
virtual float GetLifeRemaining() const
Gets the life remaining of the particle.
Definition Particle.h:57
virtual void SetScale(const float scale)
Sets the scale of the particle.
Definition Particle.h:73
virtual void SetColor(const Color color)
Sets the color of the particle.
Definition Particle.h:69
Defines a vector with 2 components (x and y).
Definition Vector2.h:21
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition Animation.cpp:18