summaryrefslogtreecommitdiffhomepage
path: root/Enemy.cpp
blob: 240639400781fc590eabaf89936c6057c21123b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "Enemy.h"

#include <memory>
#include <utility>

#include <raylib.h>

#include "Behaviour.h"
#include "Generator.h"
#include "NullBehaviour.h"
#include "NullGenerator.h"


Enemy::Enemy() :
    m_hold {0},
    m_position {std::make_shared<Vector2>(Vector2{400.f, 300.f})},
    m_generator {std::make_shared<NullGenerator>()},
    m_behaviour {std::make_shared<NullBehaviour>()}
{
}


Enemy::Enemy(
        std::shared_ptr<Vector2> position,
        std::shared_ptr<Generator> generator,
        std::shared_ptr<Behaviour> behaviour) :
    m_hold {0},
    m_position {position},
    m_generator {generator},
    m_behaviour {behaviour}
{
}


void
Enemy::update(const float dt)
{
    if (m_hold > 0) {
        m_hold -= dt;
        return;
    }
    m_behaviour->update(dt);
    m_generator->update(dt);
}


void
Enemy::draw()
{
    if (m_hold > 0)
        return;
    DrawCircle(m_position->x, m_position->y, 6, DARKGRAY);
}


bool
Enemy::gone() const
{
    return m_position->y > 600;
}