forked from att14/OSGCC---TD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.dart
112 lines (104 loc) · 2.17 KB
/
enemy.dart
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
class Enemy {
int x;
int y;
int sight;
int damage;
int speed;
int castle;
int health;
int size;
bool hit;
HTMLImageElement img;
HTMLCanvasElement canvas;
CanvasRenderingContext2D ctx;
Enemy (this.x, this.y, this.size,int kills){
castle = (750 *.75).floor();
hit = false;
HTMLDocument doc = window.document;
canvas = doc.getElementById('canvas');
ctx = canvas.getContext('2d');
img = doc.createElement('img');
switch(size){
case 0:
img.src = 'images/monsters/blob.png';
sight = 10;
speed = 3;
damage = 10;
health = 201+kills*3;
break;
case 1:
img.src = 'images/monsters/blart.png';
sight = 50;
speed = 2;
damage = 5;
health = 101+kills*3;
break;
case 2:
img.src = 'images/monsters/amoeba.png';
sight = 10;
speed = 1;
damage = 15;
health = 901+kills*3;
break;
case 3:
img.src = 'images/monsters/boom.png';
sight = 10;
speed = 19+kills/100;
damage = 100;
health = 10;
break;
case 4:
img.src = 'images/monsters/skull-fucker.png';
sight = 10;
speed = 19;
damage = 100;
health = 10001+kills*3;
break;
case 5:
img.src = 'images/monsters/mickey.png';
sight = 100;
speed = 2;
damage = 14;
health = 80+kills*3;
break;
}
img.onload = (e) {
if((y-img.height/2)< 0){
y = y + img.height/2;
}
ctx.drawImage(img, x-(img.width/2).floor(), y-(img.height/2).floor());
};
}
bool move() {
if (hit == true) {
return false;
}else {
int distance = castle-x;
if(distance <= sight){
hit = true;
}
else{
x += speed;
}
if (x + size >= castle) {
x = castle - size;
hit = true;
}
return true;
}
}
int get attack() {
if (hit == true) {
return damage;
} else {
return 0;
}
}
int get life() => health;
void set life(int newLife){
health = newLife;
}
void draw() {
ctx.drawImage(img, x-(img.width/2).floor(), y-(img.height/2).floor());
}
}