-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProjectileShooter.h
82 lines (77 loc) · 4.21 KB
/
ProjectileShooter.h
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
#ifndef ProjectileShooter_H
#define ProjectileShooter_H
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include "Character.h"
class ProjectileShooter : public Character {
public:
struct Projectile {
//default projectile constructor
Projectile();
//constructor for player projectiles
Projectile(sf::RenderWindow & window, sf::Texture & projectileTexture, sf::Sprite startSprite);
//constructor for internet player projectiles
Projectile(sf::Vector2i mousePos, sf::Texture & projectileTexture, sf::Sprite startSprite);
//sprite of projectile, created using "projectileTexture"
sf::Sprite projectileSprite;
//start position based on player position
sf::Vector2f startPos;
//mouse position when projectile was created
sf::Vector2i mousePos;
bool trigger; //used for animation of projectile (switch between frames)
sf::Clock clockAnim; //used for animation of projectile
sf::CircleShape projectileCircle; // collision circle for projectile
bool hitWall = false;
};
//constructor that creates the projectileShooter
//@param projectileShooterTexture: texture for projectileShooter
//@param weaponTexture: texture for weapon
//@param projectileTextureA: texture for first animation frame of projectile
//@param projectileTextureB: texture for second animation frame of projectile (same texture as A if no animation for projectile)
//@param projectileSpeed: speed of projectiles shot
//@param projectileReloadTime: time before you can shoot another projectile
//@param timeAfterShot: amount of time you want slow to last
//@param fromWeapon: whether projectile should come from weapon (otherwise comes from player)
ProjectileShooter(sf::Texture & healthBarForegroundTexture, sf::Texture & healthBarBackgroundTexture, sf::Texture & projectileShooterTexture,
sf::Texture & weaponTexture, sf::Texture & projectileTextureA, sf::Texture & projectileTextureB, float projectileSpeed = 0.25f,
float projectileReloadTime = 0.3f, float timeAfterShot = 1.0f, bool fromWeapon = false, int maxHealth = 100, int damage = 10, float charSpeed = 1.5f);
//draws projectileShooter
void draw(sf::RenderWindow & window);
//shoots projectile on left click, and updates "isShooting" based on "timeAfterShot"
void shoot(sf::RenderWindow & window);
//collision between projectile and player
//@param player: circle to test if intersecting with projectile
//@return: true if sword and player are intersecting, false otherwise
bool collisionPP(sf::CircleShape & player);
//draws and moves all projectiles
void drawProjectiles(sf::RenderWindow & window);
//sets weapon of projectileShooter based on "fromWeapon"
void setWeapon(sf::RenderWindow & window);
//gets projectile collision circles for use in map collisions
std::vector<sf::CircleShape*> getProjectileCircles();
//make hitWall for projectiles[i] true so that the projectile is deleted
void setHitWall(int i);
protected:
bool isShooting = false; //true if shot and time within "timeAfterShot" seconds
float timeAfterShot; //amount of time you want slow to last
sf::Sprite weaponSprite; //sprite for weapon
sf::CircleShape weaponCircle; //circle that weapon rotates around
bool fromWeapon; //whether projectile shoots from weapon (or from player)
sf::Texture projectileTextureA; //texture for first animation frame of projectile
sf::Texture projectileTextureB; //texture for second animation frame of projectile
std::vector<Projectile*> projectiles; //stores all projectiles
sf::Clock clockProjectile; //used for checking time since projectile was fired
sf::Clock clockReload; //used for projectile shooting
sf::Uint16 uniqueProjectilesCounter = 0; // number of projectiles shot so far by player
private:
float projectileSpeed; //speed of projectiles shot
float projectileReloadTime; //time before you can shoot another projectile
//--PROJECTILE--
//checks if projectile is on screen (called by "drawProjectiles")
//@param projectile: projectile to check
//@return bool: true if projectile is on screen, false if projectile is not on screen
bool projectileOnScreen(Projectile * projectile);
//called by "drawProjectiles" to move all projectiles forward
void moveProjectile(Projectile * projectile);
};
#endif