Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Ship.cpp
Go to the documentation of this file.
1
2#include "Ship.h"
3#include "Level.h"
4
5
7{
8 SetPosition(0, 0);
10
11 Initialize();
12}
13
14void Ship::Update(const GameTime& gameTime)
15{
16 m_attachmentIt = m_attachments.begin();
17 for (; m_attachmentIt != m_attachments.end(); m_attachmentIt++)
18 {
19 IAttachment* pAttachment = m_attachmentIt->second;
20 pAttachment->Update(gameTime);
21 }
22
23 GameObject::Update(gameTime);
24}
25
26void Ship::Hit(const float damage)
27{
28 if (m_isInvulnurable) return;
29
30 m_hitPoints -= damage;
31 if (m_hitPoints > 0) return;
32
35}
36
37IAttachment* Ship::GetAttachment(const std::string& key)
38{
39 m_attachmentIt = m_attachments.find(key);
40 if (m_attachmentIt == m_attachments.end()) return nullptr;
41 return m_attachmentIt->second;
42}
43
45{
46 if (index < m_attachments.size())
47 {
48 m_attachmentIt = m_attachments.begin();
49 std::advance(m_attachmentIt, index);
50 return m_attachmentIt->second;
51 }
52
53 return nullptr;
54}
55
57{
58 m_hitPoints = m_maxHitPoints;
59}
60
62{
63 //m_weaponIt = m_weapons.begin();
64 //for (; m_weaponIt != m_weapons.end(); m_weaponIt++)
65 //{
66 // (*m_weaponIt)->Fire(type);
67 //}
68
69 m_attachmentIt = m_attachments.begin();
70 for (; m_attachmentIt != m_attachments.end(); m_attachmentIt++)
71 {
72 if (m_attachmentIt->second->GetAttachmentType() != "Weapon") continue;
73 ((Weapon *)(m_attachmentIt->second))->Fire(triggerType);
74 }
75}
76
77//void Ship::AttachWeapon(Weapon* pWeapon, Vector2 position)
78//{
79// AttachItem(pWeapon, position);
80// m_weapons.push_back(pWeapon);
81//}
82
84{
85 item->AttachTo(this, position);
86 m_attachments[item->GetKey()] = item;
87}
virtual void SetPosition(const float x, const float y)
virtual void SetCollisionRadius(const int radius)
Definition GameObject.h:98
virtual void Deactivate()
Deactivate the object.
Definition GameObject.h:48
static Level * GetCurrentLevel()
Get the current level.
Definition GameObject.h:30
virtual void Update(const GameTime &gameTime)
Update the object.
Contains timing values for game updates and rendering.
Definition GameTime.h:21
Interface for a particle emitter.
Definition IAttachment.h:25
virtual std::string GetKey() const =0
virtual void Update(const GameTime &gameTime)=0
virtual void AttachTo(IAttachable *pAttachable, Vector2 &position)=0
Defines a vector with 2 components (x and y).
Definition Vector2.h:21
virtual void SpawnExplosion(GameObject *pExplodingObject)
Spawn an explosion at a specific position.
Definition Level.cpp:188
virtual IAttachment * GetAttachment(const std::string &key)
Definition Ship.cpp:37
virtual void Update(const GameTime &gameTime)
Updates the ship.
Definition Ship.cpp:14
virtual void Hit(const float damage)
Applies damage to the ship.
Definition Ship.cpp:26
virtual void Initialize()
Initializes the ship.
Definition Ship.cpp:56
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 FireWeapons(TriggerType type=TriggerType::All)
Fires the ship's weapons.
Definition Ship.cpp:61
Represents a type of trigger, which can be used to activate weapons.
Definition TriggerType.h:8
Base class for all weapons that can be fired by a game object.
Definition Weapon.h:12