summaryrefslogtreecommitdiffhomepage
path: root/Enemy.cpp
blob: b8329a2ebb696606a5290f95ef79b135b8a01dd8 (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
#include "Enemy.h"

#include <memory>
#include <utility>

#include <raylib.h>

#include "Generator.h"


Enemy::Enemy(std::unique_ptr<Generator> generator) :
    m_hold {0},
    m_position {std::make_shared<Vector2>()},
    m_generator {std::move(generator)}
{
    m_position->x = 400;
    m_position->y = 40;
    m_generator->attach(m_position);
}


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


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


void
Enemy::set_position(const float x, const float y)
{
    m_position->x = x;
    m_position->y = y;
}