-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputerplayer.cpp
More file actions
82 lines (80 loc) · 2.3 KB
/
computerplayer.cpp
File metadata and controls
82 lines (80 loc) · 2.3 KB
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
#include "computerplayer.h"
#include "gameview.h"
#include <QDebug>
#include <random>
/*
Function: Computer player constructor
Params: QPixmap &pixmap, int health, int damage, Bounds b, int gold
Desc: Child of Player class. Passes parameters into parent constructor
Returns: ComputerPlayer
*/
ComputerPlayer::ComputerPlayer(QPixmap &pixmap, int health, int damage, Bounds b, int gold)
: Player(pixmap, health, damage, b, gold, Qt::GlobalColor::green)
{
//connect(timer_, &QTimer::timeout, this, &ComputerPlayer::moveCharacter());
//timer_.start(1000);
}
/*
Function: moveCharacter
Params: None
Desc: Moves character in a random direction by 15 px
Returns: None
*/
void ComputerPlayer::MoveCharacter() {
int STEP_SIZE = 15;
int num = rand() % 8;
//if only 1 key is being pressed, simply move in that direction
switch (num){
case 0:
if (x() + STEP_SIZE > bound_.x2) {
return;
}
setPos(x()+STEP_SIZE,y());
break;
case 1:
if (x() - STEP_SIZE < bound_.x1) {
return;
}
setPos(x()-STEP_SIZE,y());
break;
case 2:
if (y() - STEP_SIZE < bound_.y1) {
return;
}
setPos(x(),y()-STEP_SIZE);
break;
case 3:
if (y() + STEP_SIZE > bound_.y2) {
return;
}
setPos(x(),y()+STEP_SIZE);
break;
case 4:
if (y() - STEP_SIZE < bound_.y1 || x() + STEP_SIZE > bound_.x2){
return;
}
setPos(x()+STEP_SIZE,y()-STEP_SIZE);
break;
case 5:
if (y() - STEP_SIZE < bound_.y1 || x() - STEP_SIZE < bound_.x1){
return;
}
setPos(x()-STEP_SIZE,y()-STEP_SIZE);
break;
case 6:
if (y() + STEP_SIZE > bound_.y2 || x() + STEP_SIZE > bound_.x2){
return;
}
setPos(x()+STEP_SIZE,y()+STEP_SIZE);
break;
case 7:
if (y() + STEP_SIZE > bound_.y2 || x() - STEP_SIZE < bound_.x1){
return;
}
setPos(x()-STEP_SIZE,y()+STEP_SIZE);
break;
default:
return;
}
CheckCollision();
}