forked from kevin890703/assign6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fighter.pde
76 lines (69 loc) · 1.25 KB
/
Fighter.pde
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
class Fighter{
PImage fighterImg;
int x = 0;
int y = 0;
int type;
int speed = 5;
int hp;
Fighter(int hp) {
this.fighterImg = loadImage("img/fighter.png");
this.x = width - this.fighterImg.width;
this.y = (height-this.fighterImg.height)/2;
this.type = FlightType.FIGHTER;
this.hp = hp;
}
void draw() {
image(fighterImg, this.x, this.y);
if (isMovingUp) {
this.move(Direction.UP);
}
if (isMovingDown) {
this.move(Direction.DOWN);
}
if (isMovingLeft) {
this.move(Direction.LEFT);
}
if (isMovingRight) {
this.move(Direction.RIGHT);
}
}
void shoot() {
}
void move(int direct) {
switch (direct) {
case Direction.UP:
if (this.y - speed > 0) {
this.y-= speed;
}
break;
case Direction.DOWN:
if (this.y + speed < height - this.fighterImg.height) {
this.y+= speed;
}
break;
case Direction.LEFT:
if (this.x - speed > 0) {
this.x-= speed;
}
break;
case Direction.RIGHT:
if (this.x + speed < width - this.fighterImg.width) {
this.x+= speed;
}
break;
}
}
void hpValueChange(int value)
{
this.hp += value;
if (this.hp <=0) {
state = GameState.END;
return;
}
else if (this.hp >= 100) {
this.hp = 100;
return;
}
return;
}
}