Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Weapon Class Referenceabstract

Base class for all weapons that can be fired by a game object. More...

#include <Weapon.h>

Inheritance diagram for Weapon:

Public Member Functions

 Weapon (const std::string &key, bool isAttachedToPlayer=true, bool isActive=true, TriggerType triggerType=TriggerType::Primary)
 Instantiate a weapon object.
 
virtual ~Weapon ()
 
virtual void Update (const GameTime &gameTime)
 Update the weapon.
 
virtual void Draw (SpriteBatch &spriteBatch)
 Render the weapon.
 
virtual void Fire (TriggerType triggerType)=0
 Attempt to fire the weapon.
 
virtual void SetTriggerType (TriggerType triggerType)
 Set the game object that the weapon is attached to.
 
virtual void SetProjectilePool (std::vector< Projectile * > *pProjectiles)
 Set the pool of projectiles that the weapon can fire.
 
virtual void Activate ()
 Activate the weapon.
 
virtual void Dectivate ()
 Deactivate the weapon.
 
virtual bool IsActive () const
 Determine if the weapon is active.
 
virtual void SetFireSound (AudioSample *pSound)
 Set the sound that will be played when the weapon is fired.
 
virtual AudioSampleGetFireSound ()
 Get the sound that will be played when the weapon is fired.
 
virtual bool IsAttachedToPlayer () const
 Determine if the weapon is attached to the player.
 
virtual void AttachTo (IAttachable *pAttachable, Vector2 &position)
 Attach the weapon to a game object.
 
virtual std::string GetKey () const
 
virtual std::string GetAttachmentType () const
 

Protected Member Functions

virtual TriggerType GetTriggerType () const
 Get the game object that the weapon is attached to.
 
virtual Vector2 GetPosition () const
 Get the screen position of the weapon.
 
virtual ProjectileGetProjectile ()
 Get a projectile from the pool.
 

Detailed Description

Base class for all weapons that can be fired by a game object.

Definition at line 11 of file Weapon.h.

Constructor & Destructor Documentation

◆ Weapon()

Weapon::Weapon ( const std::string & key,
bool isAttachedToPlayer = true,
bool isActive = true,
TriggerType triggerType = TriggerType::Primary )
inline

Instantiate a weapon object.

Parameters
isActiveA flag to determine if the weapon is active.

Definition at line 18 of file Weapon.h.

◆ ~Weapon()

virtual Weapon::~Weapon ( )
inlinevirtual

Definition at line 25 of file Weapon.h.

Member Function Documentation

◆ Activate()

virtual void Weapon::Activate ( )
inlinevirtual

Activate the weapon.

Definition at line 61 of file Weapon.h.

◆ AttachTo()

virtual void Weapon::AttachTo ( IAttachable * pAttachable,
Vector2 & position )
inlinevirtual

Attach the weapon to a game object.

Parameters
pAttachableA pointer to the attachable game object.
positionThe offset position of the weapon relative to the game object.

Implements KatanaEngine::IAttachment.

Definition at line 85 of file Weapon.h.

◆ Dectivate()

virtual void Weapon::Dectivate ( )
inlinevirtual

Deactivate the weapon.

Definition at line 64 of file Weapon.h.

◆ Draw()

virtual void Weapon::Draw ( SpriteBatch & spriteBatch)
inlinevirtual

Render the weapon.

Parameters
spriteBatchA reference to the game's sprite batch, used for rendering.
Remarks
Generally, this is not used, but can be overridden by derived classes if you want to render the weapon.

Definition at line 34 of file Weapon.h.

◆ Fire()

virtual void Weapon::Fire ( TriggerType triggerType)
pure virtual

Attempt to fire the weapon.

Parameters
triggerTypeThe type of trigger that fired the weapon.
Remarks
The weapon will only fire if it is active, and may not fire if it is on cooldown.

Implemented in Blaster.

◆ GetAttachmentType()

virtual std::string Weapon::GetAttachmentType ( ) const
inlinevirtual

Implements KatanaEngine::IAttachment.

Definition at line 93 of file Weapon.h.

◆ GetFireSound()

virtual AudioSample * Weapon::GetFireSound ( )
inlinevirtual

Get the sound that will be played when the weapon is fired.

Returns
A pointer to the audio sample.

Definition at line 76 of file Weapon.h.

◆ GetKey()

virtual std::string Weapon::GetKey ( ) const
inlinevirtual

Implements KatanaEngine::IAttachment.

Definition at line 91 of file Weapon.h.

◆ GetPosition()

virtual Vector2 Weapon::GetPosition ( ) const
inlineprotectedvirtual

Get the screen position of the weapon.

Returns
The screen position of the weapon.

Definition at line 104 of file Weapon.h.

◆ GetProjectile()

virtual Projectile * Weapon::GetProjectile ( )
inlineprotectedvirtual

Get a projectile from the pool.

Returns
A pointer to a projectile.
Remarks
This helps us avoid instantiating projectiles while the level is running.

Definition at line 109 of file Weapon.h.

◆ GetTriggerType()

virtual TriggerType Weapon::GetTriggerType ( ) const
inlineprotectedvirtual

Get the game object that the weapon is attached to.

Returns
A pointer to the game object.

Definition at line 100 of file Weapon.h.

◆ IsActive()

virtual bool Weapon::IsActive ( ) const
inlinevirtual

Determine if the weapon is active.

Returns
True if the weapon is active.

Definition at line 68 of file Weapon.h.

◆ IsAttachedToPlayer()

virtual bool Weapon::IsAttachedToPlayer ( ) const
inlinevirtual

Determine if the weapon is attached to the player.

Returns
True if the weapon is attached to the player.

Definition at line 80 of file Weapon.h.

◆ SetFireSound()

virtual void Weapon::SetFireSound ( AudioSample * pSound)
inlinevirtual

Set the sound that will be played when the weapon is fired.

Parameters
pSoundA pointer to the audio sample.

Definition at line 72 of file Weapon.h.

◆ SetProjectilePool()

virtual void Weapon::SetProjectilePool ( std::vector< Projectile * > * pProjectiles)
inlinevirtual

Set the pool of projectiles that the weapon can fire.

Parameters
pProjectilesA pointer to the projectile pool.
See also
GetProjectile

Definition at line 58 of file Weapon.h.

◆ SetTriggerType()

virtual void Weapon::SetTriggerType ( TriggerType triggerType)
inlinevirtual

Set the game object that the weapon is attached to.

Parameters
pGameObjectA pointer to the game object.

Set the offset of the weapon from the game object's position.

Parameters
offsetThe offset of the weapon.

Set the type of trigger that can fire the weapon.

Parameters
triggerTypeThe type of trigger.
Remarks
This is to help decouple the weapon from the input system.

Definition at line 53 of file Weapon.h.

◆ Update()

virtual void Weapon::Update ( const GameTime & gameTime)
inlinevirtual

Update the weapon.

Parameters
pGameTimeTiming values including time since last update.

Implements KatanaEngine::IAttachment.

Reimplemented in Blaster.

Definition at line 29 of file Weapon.h.


The documentation for this class was generated from the following file: