-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfighter.cpp
More file actions
28 lines (25 loc) · 729 Bytes
/
fighter.cpp
File metadata and controls
28 lines (25 loc) · 729 Bytes
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
#include "fighter.h"
Fighter::Fighter(int hp, QPoint pos, QPoint size, int speed):Ship(hp, pos, size, speed){}
void Fighter::attack(QPoint attackPos)
{
QPoint bulletPos(attackPos);
QPoint bulletSize(10,50);
Object* bullet = new Bullet(20, bulletPos, bulletSize);
this->newObjects.append(bullet);
}
void Fighter::update()
{
updatePos();
updateBullets();
}
void Fighter::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()));
}
++shotIterator;
if(shotIterator ==0 && !keys.contains(Qt::Key_A)){
shotIterator = 0;
}
}