-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrow.js
91 lines (80 loc) · 2.4 KB
/
crow.js
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
export default class Crow {
constructor(centerx, centery, speed, health) {
this.width = 20;
this.height = 40;
this.x = centerx - (this.width / 2);
this.y = centery - (this.height / 2);
this.side = "right";
this.speed = speed;
this.speedx = 0;
this.speedy = 0;
this.healthMax = health;
this.health = health;
this.killed_enemies = 0;
}
get mid_x() {
return this.x + (this.width / 2)
}
get mid_y() {
return this.y + (this.height / 2)
}
Move(button) {
if (button.d & !(button.w || button.s || button.a)) {
this.speedx = this.speed;
this.speedy = 0;
this.side = "right";
} else if (button.a & !(button.w || button.s || button.d)) {
this.speedx = -this.speed;
this.speedy = 0;
this.side = "left";
} else if (button.w & !(button.a || button.d || button.s)) {
this.side = "up";
this.speedy = -this.speed;
this.speedx = 0;
} else if (button.s & !(button.a || button.d || button.w)) {
this.side = "down";
this.speedy = this.speed;
this.speedx = 0;
} else if (button.d & button.w & !(button.s || button.a)) {
this.speedx = this.speed;
this.speedy = -this.speed;
this.side = "right-up";
} else if (button.d & button.s & !(button.w || button.a)) {
this.speedx = this.speed;
this.speedy = this.speed;
this.side = "right-down";
} else if (button.a & button.w & !(button.s || button.d)) {
this.speedx = -this.speed;
this.speedy = -this.speed;
this.side = "left-up";
} else if (button.a & button.s & !(button.w || button.d)) {
this.speedx = -this.speed;
this.speedy = this.speed;
this.side = "left-down";
} else {
this.speedy = 0;
this.speedx = 0;
}
this.x += this.speedx;
this.y += this.speedy;
return
};
Draw() {
fill('#CCC');
stroke("#CCC");
strokeWeight(5);
triangle(this.x, this.y + this.height, this.x + this.width, this.y + this.height, this.x + (0.5 * this.width), this.y);
}
WallCollision(walls) {
if (this.y + this.speedy <= walls.y1) {
this.y = walls.y1;
} else if (this.y + this.height + this.speedy >= walls.y2) {
this.y = walls.y2 - this.height;
}
if (this.x + this.speedx <= walls.x1) {
this.x = walls.x1;
} else if (this.x + this.width + this.speedx >= walls.x2) {
this.x = walls.x2 - this.width;
}
}
}