forked from Sicatriz/CppGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeteor3.cpp
37 lines (31 loc) · 795 Bytes
/
meteor3.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
#include "meteor3.h"
using namespace insemi;
// meteor random spawnposition and sprite
Meteor3::Meteor3(QGraphicsItem *){
int random_number = rand() % 1600;
setPos(random_number, 0);
//gfx enemy type 1
setPixmap(QPixmap(":/gfx/gfx/Stones2Filled_25.png"));
}
// meteor movement and deletion
void Meteor3::move()
{
if (i == 0){
int select = rand()%2;
int ran = rand()%7;
ranused = ran;
selectused = select;
i++;
}
// move meteor down
if(selectused == 1){
setPos(x()-(ranused/10),y()+0.4);
}else{
setPos(x()+(ranused/10),y()+0.2);
}
// when enemy is out of screen, free memory
if(pos().y() > 1100 || pos().x() > 1800 || pos().x() < 0){
scene()->removeItem(this);
this->deleteLater();
}
}