-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mage.cpp
71 lines (65 loc) · 2.91 KB
/
Mage.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
#include "Defines.h"
#include "Mage.h"
Mage::Mage(sf::Texture & healthBarForegroundTexture, sf::Texture & healthBarBackgroundTexture, sf::Texture & mageTexture,
sf::Texture & staffTexture, sf::Texture & fireballTextureA, sf::Texture & fireballTextureB, float fireballSpeed,
float fireballReloadTime, float timeAfterShot, float slowSpeed, int maxHealth, int damageMin, int damageMax,float moveSpeed, bool fromWeapon) :
ProjectileShooter(healthBarForegroundTexture, healthBarBackgroundTexture, mageTexture, staffTexture, fireballTextureA, fireballTextureB,
fireballSpeed, fireballReloadTime, timeAfterShot, fromWeapon, maxHealth, damage, moveSpeed), moveSpeed(moveSpeed), slowSpeed(slowSpeed),
damageMin(damageMin), damageMax(damageMax) {
}
Mage::~Mage() {
while (projectiles.size() > 0) {
delete projectiles[0];
projectiles[0] = NULL;
projectiles.erase(projectiles.begin()); //remove NULL from vector
}
}
void Mage::move(const sf::RenderWindow & window, const sf::Keyboard::Key releasedKey) {
if (isShooting) {
charSpeed = slowSpeed;
}
else {
charSpeed = moveSpeed;
}
Character::move(window, releasedKey);
}
sf::Packet Mage::chainDataToPacket(sf::Packet & packet, std::string value) {
sf::Vector2i mousePos = sf::Vector2i(-1, -1);
if (projectiles.size() > 0) {
mousePos = projectiles[0]->mousePos;
}
return (packet << value << "Mage" << maxHealth << health << damage << playerSprite.getPosition().x << playerSprite.getPosition().y << playerSprite.getRotation() << isShooting << fromWeapon << weaponSprite.getRotation() << mousePos.x << mousePos.y << uniqueProjectilesCounter) ? packet : sf::Packet();
}
sf::Packet Mage::extractPacketToData(sf::Packet & packet) {
sf::Vector2f pos;
float rotation;
float angle;
sf::Vector2i mousePos;
sf::Uint16 projectilesCounter;
packet >> maxHealth >> health >> damage >> pos.x >> pos.y >> rotation >> isShooting >> fromWeapon >> angle >> mousePos.x >> mousePos.y >> projectilesCounter;
playerSprite.setPosition(pos);
playerSprite.setRotation(rotation);
weaponSprite.setRotation(angle);
if (justAdded || projectilesCounter < uniqueProjectilesCounter) {
uniqueProjectilesCounter = projectilesCounter;
justAdded = false;
}
else if (mousePos != sf::Vector2i(-1, -1) && projectilesCounter > uniqueProjectilesCounter) {
uniqueProjectilesCounter++;
Projectile * projectile;
if (!fromWeapon) { //shoot projectile from playerSprite
projectile = new Projectile(mousePos, projectileTextureA, playerSprite);
}
else { //shoot projectile from weaponSprite
projectile = new Projectile(mousePos, projectileTextureA, weaponSprite);
}
projectiles.insert(projectiles.begin(), projectile); //store projectile
clockReload.restart();
clockProjectile.restart();
}
return packet;
}
sf::Int16 Mage::getDamage() {
damage = rand() % (damageMax - damageMin + 1) + damageMin; // rand()%(max-min + 1) + min;
return damage;
}