-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnimal.h
More file actions
77 lines (63 loc) · 1.4 KB
/
Copy pathAnimal.h
File metadata and controls
77 lines (63 loc) · 1.4 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
//
// Created by 20281 on 2022/9/13.
//
#ifndef C__LEARN_ANIMAL_H
#define C__LEARN_ANIMAL_H
#include "myRandom.h"
#include "object.h"
#include "Vec.h"
#include "ProgressBar.h"
/**
* 动物类
* 一般不会攻击的动物
*/
class Animal {
private:
// int damage = 2;
public:
GameObject showChar;
Vec loc{0, 0};
Vec speed{0, 1};
ProgressBar hp{10, 10};
unordered_map<GameObject, int> deadObjects;
/**
* 设置死亡掉落物
*/
void setDeadObj(GameObject o, int count) {
deadObjects[o] = count;
}
void go() {
this->loc.x += this->speed.x;
this->loc.y += this->speed.y;
}
/**
* 一个时间刻的行为
*/
void tickAction() {
// 上下左右移动,在此函数中只是更改移动的动机
int r = randint(4);
switch (r) {
case 0:
this->speed = Vec{0, 1};
break;
case 1:
this->speed = Vec{0, -1};
break;
case 2:
this->speed = Vec{1, 0};
break;
case 3:
this->speed = Vec{-1, 0};
break;
default:
this->speed = Vec{0, 1};
}
// this->loc.x += this->speed.x;
// this->loc.y += this->speed.y;
}
Animal(GameObject o, Vec loc) {
this->showChar = o;
this->loc = loc;
}
};
#endif //C__LEARN_ANIMAL_H