Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Ship.h
Go to the documentation of this file.
1
2#pragma once
3
4#include "GameObject.h"
5#include "Weapon.h"
6
8class Ship : public GameObject, public IAttachable
9{
10
11public:
12
14 Ship();
15 virtual ~Ship() { }
16
19 virtual void Update(const GameTime& gameTime);
20
23 virtual void Draw(SpriteBatch& spriteBatch) = 0;
24
27 virtual void Hit(const float damage);
28
31 virtual bool IsInvulnurable() const { return m_isInvulnurable; }
32
35 virtual void SetInvulnurable(bool isInvulnurable = true) { m_isInvulnurable = isInvulnurable; }
36
39 virtual std::string ToString() const { return "Ship"; }
40
43 virtual CollisionType GetCollisionType() const = 0;
44
49 //virtual void AttachWeapon(Weapon *pWeapon, Vector2 position);
50
51 virtual void AttachItem(IAttachment *item, Vector2 position);
52
55 virtual float GetSpeed() const { return m_speed; }
56
59 virtual void SetSpeed(const float speed) { m_speed = speed; }
60
63 virtual void SetMaxHitPoints(const float hitPoints) { m_maxHitPoints = hitPoints; }
64
65
66 virtual IAttachment* GetAttachment(const std::string& key);
67
68 virtual IAttachment* GetAttachment(const int index);
69
70
71protected:
72
74 virtual void Initialize();
75
78 virtual void FireWeapons(TriggerType type = TriggerType::All);
79
83 virtual Weapon* GetWeapon(const std::string &key) //{ if (index < m_weapons.size()) return m_weapons[index]; return nullptr; }
84 {
85 if (m_attachments.find(key) == m_attachments.end()) return nullptr;
86 return dynamic_cast<Weapon *>(m_attachments[key]);
87 }
88
91 virtual float GetHitPoints() const { return m_hitPoints; }
92
95 virtual float GetMaxHitPoints() const { return m_maxHitPoints; }
96
97
98private:
99
100 float m_speed = 300; // pixels per second
101
102 float m_maxHitPoints = 3;
103 float m_hitPoints = m_maxHitPoints;
104
105 bool m_isInvulnurable = false;
106
107 //std::vector<Weapon *> m_weapons;
108 //std::vector<Weapon *>::iterator m_weaponIt;
109
110 std::map<std::string, IAttachment *> m_attachments;
111 std::map<std::string, IAttachment *>::iterator m_attachmentIt;
112};
113
Represents a type of collision.
Represents a game object in the game. This is the base class for all objects that can be updated,...
Definition GameObject.h:15
Contains timing values for game updates and rendering.
Definition GameTime.h:21
Interface for an object that can have items attached to it.
Definition IAttachable.h:27
Interface for a particle emitter.
Definition IAttachment.h:25
Enables a group of sprites to be drawn using the same settings.
Definition SpriteBatch.h:48
Defines a vector with 2 components (x and y).
Definition Vector2.h:21
Represents a ship in the game.
Definition Ship.h:9
virtual IAttachment * GetAttachment(const std::string &key)
Definition Ship.cpp:37
virtual void Draw(SpriteBatch &spriteBatch)=0
Draws the ship.
virtual void Update(const GameTime &gameTime)
Updates the ship.
Definition Ship.cpp:14
virtual float GetHitPoints() const
Gets the current hit points of the ship.
Definition Ship.h:91
virtual void SetSpeed(const float speed)
Sets the speed of the ship.
Definition Ship.h:59
virtual void Hit(const float damage)
Applies damage to the ship.
Definition Ship.cpp:26
virtual void SetMaxHitPoints(const float hitPoints)
Sets the max hit points of the ship.
Definition Ship.h:63
virtual bool IsInvulnurable() const
To determine if the ship should take damage when hit.
Definition Ship.h:31
virtual float GetMaxHitPoints() const
Gets the max hit points of the ship.
Definition Ship.h:95
virtual void Initialize()
Initializes the ship.
Definition Ship.cpp:56
virtual CollisionType GetCollisionType() const =0
Gets the collision type of the ship.
Ship()
Creates a new instance of Ship.
Definition Ship.cpp:6
virtual void AttachItem(IAttachment *item, Vector2 position)
Attaches a weapon to the ship.
Definition Ship.cpp:83
virtual void SetInvulnurable(bool isInvulnurable=true)
Sets the invulnerability of the ship.
Definition Ship.h:35
virtual std::string ToString() const
Gets the string representation of the ship.
Definition Ship.h:39
virtual void FireWeapons(TriggerType type=TriggerType::All)
Fires the ship's weapons.
Definition Ship.cpp:61
virtual Weapon * GetWeapon(const std::string &key)
Gets a weapon from the ship's weapon list.
Definition Ship.h:83
virtual ~Ship()
Definition Ship.h:15
virtual float GetSpeed() const
Gets the speed of the ship.
Definition Ship.h:55
Represents a type of trigger, which can be used to activate weapons.
Definition TriggerType.h:8
static const TriggerType All
Definition TriggerType.h:20
Base class for all weapons that can be fired by a game object.
Definition Weapon.h:12