-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.pde
More file actions
111 lines (105 loc) · 2.1 KB
/
enemy.pde
File metadata and controls
111 lines (105 loc) · 2.1 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
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
//enemy class
class Enemy{
//image
PImage img;
//position
int x;
int y;
//velocity
int vx;
int vy;
//speed
int step = 3;
//size
int size = 20;
//type of enemy
int type;
//set up using position, velocity, and type
Enemy(int x_, int y_, int vx_, int vy_, int type_){
//set up position
x = x_;
y = y_;
//set up velocity
vx = vx_;
vy = vy_;
//set up type
type = type_;
//if they are type two
if(type == 2){
//do not move up or down
vy = 0;
}
//if they are type 3
if(type == 3){
//move twice as fast
vx*=2;
vy*=2;
}
//load image
img = loadImage("alien.png");
}
void display(){
//different colour for each type
switch(type){
//enemy 0
case 0:
//no colour
noTint();
break;
//enemy 1
case 1:
//pink
tint(255,20,150);
break;
//enemy 2
case 2:
//blue
tint(0,0,255);
break;
//enemy 3
case 3:
//green
tint(0,255,0);
break;
}
//move in the direction, by the speed
x = x+(vx*step);
y = y+(vy*step);
//if you leave the left of the screen
//and you are able to turn around (not type 1 or 2)
if(x<0 && type!=1 && type != 2){
//move back into the screen
x = 0;
//change direction
vx = vx*-1;
}
//if you leave the right of the screen
//and you are able to turn around (not type 1 or 2)
if(x>width && type!=1 && type != 2){
//move back into the screen
x = width;
//change direction
vx = vx *-1;
}
//if you leave the top of the screen
if(y<0){
//move back into the screen
y = 0;
//change direction
vy = vy*-1;
}
//if you leave the bottom of the screen
if(y>height){
//move back into the screen
y = height;
//change direction
vy = vy *-1;
}
//center the image on the position
imageMode(CENTER);
//draw enemy
image(img,x,y,size*2,size*2);
//remove any colour tint
noTint();
}
}