-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fireball.cpp
92 lines (86 loc) · 2.49 KB
/
Fireball.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
// Created by Cyborg on 4/29/23.
#include "Fireball.h"
#include <utility>
//constuctor
Fireball::Fireball(std::string path, std::string shootSoundPath, std::string fizzleSoundPath) {
this->texture.loadFromFile(path);
this->sprite.setTexture(texture);
this->sprite.setOrigin(sprite.getGlobalBounds().width/2, sprite.getGlobalBounds().height/2);
this->shootSound.setSound(std::move(shootSoundPath));
this->fizzleSound.setSound(std::move(fizzleSoundPath));
this->shootSound.getSound().setVolume(50);
this->fizzleSound.getSound().setVolume(50);
this->isAlive = false;
}
//set fireball sprite
void Fireball::setTexture(std::string path) {
this->texture.loadFromFile(path);
this->sprite.setTexture(texture);
}
//get the fireball sprite for direct sprite function calls
sf::Sprite* Fireball::getSprite() {
return &sprite;
}
//moves the fireball 1 tile
void Fireball::move() {
if (currentDirection == up){
currentTile -= 16;
sprite.move(0, -121.0f);
}
if (currentDirection == down){
currentTile += 16;
sprite.move(0, 121.0f);
}
if (currentDirection == left){
currentTile -= 1;
sprite.move(-121.0f, 0);
}
if (currentDirection == right){
currentTile += 1;
sprite.move(121.0f, 0);
}
}
//play fireball fizzle sound
void Fireball::playFizzleSound(){
fizzleSound.play();
}
//shoot the fireball in a given direction
void Fireball::shoot(int direction, int newCurrentTile, sf::Vector2f cords) {
this->currentDirection = static_cast<Fireball::direction>(direction);
this->currentTile = newCurrentTile;
this->isAlive = true;
sprite.setPosition(cords);
shootSound.play();
switch(direction){
case 1:
sprite.setRotation(270);
break;
case 2:
sprite.setRotation(90);
break;
case 3:
sprite.setRotation(180);
break;
case 4:
sprite.setRotation(0);
break;
default:
std::cout << "ERROR: direction is an invalid value";
}
}
//returns current tile of fireball
int Fireball::getCurrentTile() {
return this->currentTile;
}
//sets current tile of fireball
void Fireball::setCurrentTile(int currentTile) {
this->currentTile = currentTile;
}
//returns if fireball is active or not
bool Fireball::getIsAlive() {
return this->isAlive;
}
//sets if fireball is active or not
void Fireball::setIsAlive(bool isAlive){
this->isAlive = isAlive;
}