-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.cpp
132 lines (118 loc) · 2.85 KB
/
enemy.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "enemy.h"
#include "gameloop.h"
#include "bullet.h"
#include "player.h"
#include "score.h"
#include <iostream>
class GameLoop;
class Enemy;
class Bullet;
class Player;
void Enemy::move()
{
srand(time(0));
this->direct = rand() % 4 + 1;
if (this->direct == 4)
{
this->setPixmap(QPixmap(":/pics/enemy_l.png"));
if (this->map[this->pos_y][this->pos_x - 1] == 0)
{
this->map[this->pos_y][this->pos_x] = 0;
this->pos_x--;
this->setPos(x() - 64, y());
this->map[this->pos_y][this->pos_x] = 9;
}
}
if (this->direct == 3)
{
this->setPixmap(QPixmap(":/pics/enemy_r.png"));
if (this->map[this->pos_y][this->pos_x + 1] == 0)
{
this->map[this->pos_y][this->pos_x] = 0;
this->setPos(x() + 64, y());
this->pos_x++;
this->map[this->pos_y][this->pos_x] = 9;
}
}
if (this->direct == 2)
{
this->setPixmap(QPixmap(":/pics/enemy_d.png"));
if (this->map[this->pos_y + 1][this->pos_x] == 0)
{
this->map[this->pos_y][this->pos_x] = 0;
this->setPos(x(), y() + 64);
this->pos_y++;
this->map[this->pos_y][this->pos_x] = 9;
}
}
if (this->direct == 1)
{
this->setPixmap(QPixmap(":/pics/enemy.png"));
if (this->map[this->pos_y - 1][this->pos_x] == 0)
{
this->map[this->pos_y][this->pos_x] = 0;
this->setPos(x(), y() - 64);
this->pos_y--;
this->map[this->pos_y][this->pos_x] = 9;
}
}
}
Enemy::Enemy (int **map) : QObject(), QGraphicsPixmapItem()
{
this->direct = 2;
this->map = map;
srand(time(0));
ft_spawn();
}
int Enemy::ft_get_x()
{
return (this->pos_x);
}
int Enemy::ft_get_y()
{
return (this->pos_y);
}
void Enemy::ft_spawn()
{
int choice;
choice = rand() % 3 + 1;
if (choice == 3)
{
this->pos_x = 1;
this->pos_y = 11;
}
if (choice == 1)
{
this->pos_x = 11;
this->pos_y = 1;
}
if (choice == 2)
{
this->pos_x = 11;
this->pos_y = 11;
}
}
void Enemy::ft_set_pl(Player *pl)
{
this->pl = pl;
}
Player *Enemy::ft_get_pl()
{
return (this->pl);
}
void Enemy::shoot()
{
Bullet *bull;
bull = new Bullet(this->direct, this->map, this->pl, 0);
if (this->direct == 1 || this->direct == 2)
bull->setPos(x() + 30, y());
if (this->direct == 3)
bull->setPos(x(), y() + 30);
if (this->direct == 4)
bull->setPos(x(), y() + 30);
scene()->addItem(bull);
}
int Enemy::ft_get_direct()
{
return (this->direct);
}