-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshootingSprite.cpp
More file actions
90 lines (53 loc) · 1.79 KB
/
shootingSprite.cpp
File metadata and controls
90 lines (53 loc) · 1.79 KB
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
#include "shootingSprite.h"
#include "gamedata.h"
ShootingSprite:: ShootingSprite(const string& n):
MultiSprite(n),
bulletName(Gamedata::getInstance().getXmlStr(n+"/Bullet")),
bullets(new Bullets(bulletName)),
minSpeed(Gamedata::getInstance().getXmlInt(bulletName+"/SpeedY")),
direction("right"),
scale(1)
{}
ShootingSprite:: ShootingSprite(const string& n, const Vector2f& pos, const Vector2f& vel):
MultiSprite(n,pos,vel),
bulletName(Gamedata::getInstance().getXmlStr(n+"/Bullet")),
bullets(new Bullets(bulletName)),
minSpeed(Gamedata::getInstance().getXmlInt(bulletName+"/SpeedY")),
direction("right"),
scale(1)
{}
ShootingSprite:: ShootingSprite(const ShootingSprite& s):
MultiSprite(s),
bulletName(s.bulletName),
bullets(s.bullets),
minSpeed(s.minSpeed),
direction(s.direction),
scale(s.scale)
{}
void ShootingSprite::shoot(){
float x = X()+getFrame()->getWidth()/2-5;
float y = Y()+getFrame()->getHeight();
bullets->shoot(Vector2f(x,y), Vector2f(velocityX(), -(minSpeed+velocityY())));
}
void ShootingSprite::playershoot(){
float x = X()+getFrame()->getWidth()/2;
float y = Y()+getFrame()->getHeight()/2;
if(direction == string("right"))
{bullets->shoot(Vector2f(x,y), Vector2f(-(minSpeed+velocityX()), 0));}
if (direction == string("left"))
{bullets->shoot(Vector2f(x-100,y), Vector2f(minSpeed+velocityX(), 0));}
if (direction == string("up"))
{bullets->shoot(Vector2f(x-20,y-60), Vector2f(0,minSpeed+velocityY()));}
}
bool ShootingSprite::collideWith(const Drawable *obj) const {
//std::cout<<"before bullet"<<std::endl;
return bullets->collideWith(obj);
}
void ShootingSprite::draw() const {
MultiSprite::draw();
bullets->draw(scale);
}
void ShootingSprite::update(Uint32 ticks){
//MultiSprite::update(ticks);
bullets->update(ticks);
}