-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheroplane.cpp
46 lines (41 loc) · 1.25 KB
/
heroplane.cpp
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
/*************************************************************************
> File Name: heroplane.cpp
> Author: Polaris-hzn8
> Mail: [email protected]
> Created Time: 2023-08-18 23:59:20
************************************************************************/
#include <QDebug>
#include "config.h"
#include "heroplane.h"
HeroPlane::HeroPlane() {
//初始化成员变量
_pic.load(HERO_PLANE2_PATH);//加载飞机资源
_x = (GAME_WINDOWS_WIDTH - _pic.width()) / 2;
_y = GAME_WINDOWS_HEIGHT - _pic.height() - 50;
//碰撞检测矩形
_rect.setWidth(_pic.width());
_rect.setHeight(_pic.height());
_rect.moveTo(_x, _y);
}
void HeroPlane::updatePosition(int x, int y) {
_x = x;
_y = y;
_rect.moveTo(_x, _y);
}
void HeroPlane::shoot() {
//累加时间间隔记录
_timestamp++;
if (_timestamp < BULLET_INTERVAL2) return;
else {
_timestamp = 0;
for (int i = 0; i < BULLET_MAXNUM; ++i) {
auto ptr = &_bullets[i];
if (!ptr->_isUsed) {
ptr->_isUsed = true;//修改使用标识
ptr->_x = _x + _rect.width()/2 - 10;//设置子弹发射坐标
ptr->_y = _y - 25;
break;
}
}
}
}