-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.cpp
39 lines (32 loc) · 918 Bytes
/
Enemy.cpp
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
#include "Enemy.hpp"
#include <algorithm>
Enemy::Enemy(sf::RenderWindow& window){
// Initalize shape
shape.setSize(sf::Vector2f(rand()%40+20.f, rand()%40+20.f));
sf::Color color(rand()%255 + 1, rand()%255 + 1, rand()%255 + 1);
shape.setFillColor(color);
shape.setPosition(sf::Vector2f(
static_cast<float>(std::max(0.f,rand()%window.getSize().x-shape.getGlobalBounds().width)),
static_cast<float>(-shape.getGlobalBounds().height)
));
// Initialize varible
type = 0;
hp = hpMax = 10;
damage = rand()%3+1;
points = rand()%10+5;
}
const sf::FloatRect Enemy::getBounds() const{
return shape.getGlobalBounds();
}
const int Enemy::getDamage() const{
return damage;
}
const int Enemy::getPoints() const{
return points;
}
void Enemy::update(){
shape.move(0.f, 2.5f);
}
void Enemy::render(sf::RenderTarget& target){
target.draw(shape);
}