-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathInvader.cpp
More file actions
50 lines (38 loc) · 1.22 KB
/
Invader.cpp
File metadata and controls
50 lines (38 loc) · 1.22 KB
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
#include "Invader.h"
Invader::Invader(sf::Texture* texture, sf::Vector2<unsigned> imageCount, float switchTime, float speed)
: Entity(*texture), animation(texture, imageCount, switchTime) {
entity.setOrigin(texture->getSize().x / 2, texture->getSize().y / 2);
}
void Invader::update() {
//Animation
animation.updateAnimation(false, true);
entity.setTextureRect(animation.uvRect);
//Updating death
if (isOnScreen() == false) { setDead(); }
}
void Invader::move(sf::Vector2<float> distance) {
entity.move(sf::Vector2<float>(distance));
}
void Invader::setType(Invader::InvaderType type) {
this->type = type;
}
int Invader::returnPoints() const {
if (type == Invader::InvaderType::crab) { return Invader::InvaderType::crab; }
if (type == Invader::InvaderType::octopus) { return Invader::InvaderType::octopus; }
if (type == Invader::InvaderType::squid) { return Invader::InvaderType::squid; }
}
void Invader::setDead() {
isDead = true;
}
bool Invader::isInvaderDead() {
if (isDead) {
return true;
}
return false;
}
bool Invader::isOnScreen() {
if (getX() >= 0 && getX() <= SCREEN_WIDTH + 100 && getY() >= 0 && getY() <= SCREEN_HEIGHT) {
return true;
}
return false;
}