-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.cpp
More file actions
28 lines (25 loc) · 690 Bytes
/
enemy.cpp
File metadata and controls
28 lines (25 loc) · 690 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 "enemy.h"
Enemy::Enemy(int hp, QPoint pos, QPoint size, int speed, int attackPeriod):Object (hp, pos, size)
{
this->speed = speed;
this->attackPeriod = rand()%(attackPeriod+25)+15;
}
void Enemy::update()
{
pos.setY(pos.y()+speed);
randomizedAttack();
}
void Enemy::attack()
{
QPoint bulletPos(this->getPos().x()+this->getSize().x()/2-5,this->getPos().y()+this->getSize().y());
QPoint bulletSize(10,50);
Object* bullet = new EnemyBullet(20, bulletPos, bulletSize);
this->newObjects.append(bullet);
}
void Enemy::randomizedAttack(){
if(attackIterator > attackPeriod){
attack();
attackIterator = 0;
}
++attackIterator;
}