-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathenemy.hpp
74 lines (70 loc) · 1.95 KB
/
enemy.hpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef ENEMY_HPP_INCLUDED
#define ENEMY_HPP_INCLUDED
#include<bits/stdc++.h>
#include<SFML/Graphics.hpp>
using namespace std;
using namespace sf;
class Enemy{
private:
Texture enemmyTexture;
Sprite enemySprite;
SoundBuffer enemySoundBuffer;
Sound enemySound;
float moveSpeed=3;
bool alive = true;
bool started = true;
public:
string morarSoundLoc = "Resource/Levels/co/die.ogg";
string enemyLoc = "Resource/Levels/co/enemyGreen.png";
bool directionOfEnemy;
float startPoint=-100.0f, endPoint=-100.0f, height=-100.0f;
void initEnemy(float startP, float endP, float heightP){
enemmyTexture.loadFromFile(enemyLoc);
enemySprite.setTexture(enemmyTexture);
enemySoundBuffer.loadFromFile(morarSoundLoc);
enemySound.setBuffer(enemySoundBuffer);
startPoint=startP;
endPoint=endP;
height=heightP;
enemySprite.setPosition(startPoint, height);
}
void updateEnemy(){
if(alive){
float enemyX = enemySprite.getPosition().x;
if(directionOfEnemy) {
enemySprite.move(moveSpeed,0);
if(enemyX>=endPoint){
directionOfEnemy = false;
}
}
else {
enemySprite.move(moveSpeed*(-1),0);
if(enemyX<=startPoint){
directionOfEnemy=true;
}
}
}
else enemySprite.setPosition(-200,-200);
}
void drawEnemy(RenderWindow& window){
if(alive) window.draw(enemySprite);
}
FloatRect getRect(){
return enemySprite.getGlobalBounds();
}
void boroshoro(){
enemySprite.scale(10, 10);
}
void dead() {
enemySound.play();
alive = false;
}
void jinda() {
if(this->started){
enemySprite.scale(.1,.1);
this->started=false;
}
alive = true;
}
};
#endif // ENEMY_HPP_INCLUDED