-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.h
45 lines (38 loc) · 1.29 KB
/
enemy.h
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
#pragma once
#include "rocket.h"
#include "missle.h"
#include "bboxed.h"
class Enemy : public Rocket, public Bboxed {
protected:
Entity *target;
int difficulty = 0;
public:
Enemy(std::string _name, float life, float damage, sf::Vector2f position, sf::FloatRect bbox, std::vector<Entity*> *renderQueue) : Rocket(_name, life, damage, position, renderQueue), Bboxed(bbox) {
target = this;
sprite.setColor(sf::Color::Red);
};
void checkBoundries() {
position = sprite.getPosition();
if(!bbox.contains(sprite.getPosition())) stop();
}
void targetEntity(Entity *_target) {
target = _target;
}
void setDifficulty(int _difficulty) {
difficulty = _difficulty;
}
void animate() {
if(difficulty >= 3) {
cooldownTime = cooldownTimer.getElapsedTime();
if(cooldownTime.asMilliseconds() > rand() % 2000 + 1000.f) {
Missle *missle = new Missle(this, 0, 30, 500, 2000, renderQueue);
if(difficulty == 4) missle->targetEntity(target);
renderQueue->push_back(missle);
cooldownTimer.restart();
}
}
Rocket::animate();
if(target != this) Rocket::lookAt(target->getPosition());
checkBoundries();
}
};