-
Notifications
You must be signed in to change notification settings - Fork 2
/
Object.cpp
114 lines (95 loc) · 2.88 KB
/
Object.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Created by Sondre on 19.10.2017.
//
#include <iostream>
#include <SFML/Audio/Sound.hpp>
#include "Object.h"
#include "gameConfig.h"
Object::Object(){
};
Object::Object(int x, int y, float health, float maxHealth, sf::Texture* texture, int height, int width){
this->maxHealth = maxHealth;
this->health = health;
this->rect.setPosition(x,y);
this->rect.setTexture(texture);
this->rect.setSize(sf::Vector2f(height, width));
this->tx = texture;
}
sf::RectangleShape Object::getShape(){
return Object::rect;
}
sf::Texture* Object::ObjectTexture(){
return this->tx;
}
void Object::move(){
this->rect.setPosition(rect.getPosition().x + velocity.x, rect.getPosition().y + velocity.y);
if(this->rect.getPosition().x > screenWidth + 200 || this->rect.getPosition().x < -200)
destroy();
else if (this->rect.getPosition().y > screenHeight + 200 || this->rect.getPosition().y < -200)
destroy();
moveOverride();
}
void Object::moveOverride(){
}
void Object::takeDamage(int damage){
if(this->health < damage){
this->health = 0;
}
else
this->health -= damage;
if(this->health == 0){
this->destroy();
}
}
void Object::Heal(int amount){
this->health += amount;
}
void Object::destroy(){
shouldDelete = true;
}
Object::~Object() {
}
bool Object::Explotion_animation(Object *EX,sf::SoundBuffer &buffer,sf::Sound &Explotion_Enemy,int x, int y)
{
EX->rect.setSize(sf::Vector2f(x,y));
if(!ExplotionClock_On)
{
EX->rect.setPosition(rect.getPosition().x,rect.getPosition().y);
Explotion_clock.restart();
ExplotionClock_On=true;
buffer.loadFromFile("Sounds/Explosion_1.wav");
Explotion_Enemy.setBuffer(buffer);
Explotion_Enemy.setVolume(25);
Explotion_Enemy.play();
//
}
if(Explotion_clock.getElapsedTime().asSeconds()>0.1)
{
EX->rect.setFillColor(sf::Color::Red);
EX->rect.setPosition(rect.getPosition().x,rect.getPosition().y);
}
if(Explotion_clock.getElapsedTime().asSeconds()>0.2)
{
EX->rect.setFillColor(sf::Color::Yellow);
EX->rect.setPosition(rect.getPosition().x,rect.getPosition().y);
}
if(Explotion_clock.getElapsedTime().asSeconds()>0.3)
{
EX->rect.setFillColor(sf::Color::Red);
EX->rect.setPosition(rect.getPosition().x,rect.getPosition().y);
}
if(Explotion_clock.getElapsedTime().asSeconds()>0.4)
{
EX->rect.setFillColor(sf::Color::Yellow);
EX->rect.setPosition(rect.getPosition().x,rect.getPosition().y);
}
if(Explotion_clock.getElapsedTime().asSeconds()>0.5) {
EX->rect.setFillColor(sf::Color::Red);
EX->rect.setPosition(rect.getPosition().x , rect.getPosition().y);
}
if(Explotion_clock.getElapsedTime().asSeconds()>0.6)
{
std::cout<<" 4sek"<<std::endl;
return true;
}
}