-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcruiser.cpp
More file actions
32 lines (29 loc) · 1 KB
/
Copy pathcruiser.cpp
File metadata and controls
32 lines (29 loc) · 1 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
#include "cruiser.h"
Cruiser::Cruiser(int hp, QPoint pos, QPoint size, int speed):Ship(hp, pos, size, speed){}
void Cruiser::attack(QPoint attackPos)
{
QPoint bulletPos(attackPos);
QPoint bulletSize(10,50);
Object* bullet = new Bullet(40, bulletPos, bulletSize);
this->newObjects.append(bullet);
}
void Cruiser::update()
{
updatePos();
updateBullets();
}
void Cruiser::updateBullets(){
if(shotIterator == shotPeriod)
shotIterator=0;
if(keys.contains(Qt::Key_A) && shotIterator == 0){
attack(QPoint(this->getPos().x()+this->getSize().x()/2-5,this->getPos().y()));
}else if (keys.contains(Qt::Key_A) && shotIterator == shotPeriod/3) {
attack(QPoint(this->getPos().x()+this->getSize().x()-5,this->getPos().y()));
}else if (keys.contains(Qt::Key_A) && shotIterator == shotPeriod*2/3) {
attack(QPoint(this->getPos().x()-5,this->getPos().y()));
}
++shotIterator;
if(shotIterator ==0 && !keys.contains(Qt::Key_A)){
shotIterator = 0;
}
}