Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Blaster.h
Go to the documentation of this file.
1
2#pragma once
3
4#include "Weapon.h"
5
7class Blaster : public Weapon
8{
9
10public:
11
14 Blaster(const std::string &key) : Weapon(key) { }
15 virtual ~Blaster() { }
16
19 virtual void Update(const GameTime& gameTime)
20 {
21 if (m_cooldown > 0) m_cooldown -= gameTime.GetElapsedTime();
22 }
23
26 virtual bool CanFire() const { return m_cooldown <= 0; }
27
29 virtual void ResetCooldown() { m_cooldown = 0; }
30
33 virtual float GetCooldownSeconds() { return m_cooldownSeconds; }
34
37 virtual void SetCooldownSeconds(const float seconds) { m_cooldownSeconds = seconds; }
38
42 virtual void Fire(TriggerType triggerType)
43 {
44 if (!IsActive()) return;
45 if (!CanFire()) return;
46 if (!triggerType.Contains(GetTriggerType())) return;
47
48 Projectile *pProjectile = GetProjectile();
49 if (!pProjectile) return;
50
51 AudioSample* pAudio = GetFireSound();
52 if (pAudio) pAudio->Play();
53
54 pProjectile->Activate(GetPosition(), IsAttachedToPlayer());
55 m_cooldown = m_cooldownSeconds;
56 }
57
58
59private:
60
61 float m_cooldown = 0;
62 float m_cooldownSeconds = 0.35;
63
64
65};
Represents a blaster weapon that can be fired by a game object.
Definition Blaster.h:8
virtual void Update(const GameTime &gameTime)
Update the blaster.
Definition Blaster.h:19
Blaster(const std::string &key)
Instantiate a blaster object.
Definition Blaster.h:14
virtual void SetCooldownSeconds(const float seconds)
Set the number of seconds the blaster must wait between shots.
Definition Blaster.h:37
virtual void ResetCooldown()
Reset the cooldown of the blaster.
Definition Blaster.h:29
virtual ~Blaster()
Definition Blaster.h:15
virtual bool CanFire() const
Check if the blaster is ready to fire.
Definition Blaster.h:26
virtual float GetCooldownSeconds()
Get the number of seconds the blaster must wait between shots.
Definition Blaster.h:33
virtual void Fire(TriggerType triggerType)
Fire the blaster.
Definition Blaster.h:42
Represents a 2D grid of texels.
Definition AudioSample.h:21
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
Represents a projectile that can be fired by a weapon.
Definition Projectile.h:9
virtual void Activate(const Vector2 &position, bool wasShotByPlayer=true)
Activate the projectile.
Represents a type of trigger, which can be used to activate weapons.
Definition TriggerType.h:8
bool Contains(const TriggerType &type) const
Check if the trigger type contains a specific trigger.
Definition TriggerType.h:89
Base class for all weapons that can be fired by a game object.
Definition Weapon.h:12
virtual bool IsAttachedToPlayer() const
Determine if the weapon is attached to the player.
Definition Weapon.h:80
virtual TriggerType GetTriggerType() const
Get the game object that the weapon is attached to.
Definition Weapon.h:100
virtual AudioSample * GetFireSound()
Get the sound that will be played when the weapon is fired.
Definition Weapon.h:76
virtual Vector2 GetPosition() const
Get the screen position of the weapon.
Definition Weapon.h:104
virtual Projectile * GetProjectile()
Get a projectile from the pool.
Definition Weapon.h:109
virtual bool IsActive() const
Determine if the weapon is active.
Definition Weapon.h:68