-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlien_Class.pde
More file actions
122 lines (112 loc) · 2.21 KB
/
Copy pathAlien_Class.pde
File metadata and controls
122 lines (112 loc) · 2.21 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
112
113
114
115
116
117
118
119
120
121
122
class Alien {
/* declare variables for alien position, direction of movement and appearance */
PImage myImage; //<>//
PImage explodeImage;
PImage spaceshipImg;
PImage bombImg;
PImage blackImage;
Bomb theBomb;
float x;
float y;
int c;
int d;
boolean exploded;
boolean bomb;
boolean bombOffScreen;
/* Constructor is passed the x and y position where the alien is to
be created, plus the image to be used to draw the alien */
Alien(float xpos, float ypos, PImage alienImage, PImage explodingImage,
PImage spaceship, PImage bombImage, PImage blackImg)
{
c = 0;
d = 0;
x = xpos;
y = ypos;
spaceshipImg = spaceship;
myImage = alienImage;
explodeImage = explodingImage;
blackImage = blackImg;
blackImage.width = myImage.width;
blackImage.height = myImage.height;
bombImg = bombImage;
exploded = false;
theBomb = null;
bomb = false;
bombOffScreen = true;
}
void move()
{
if (x+myImage.width < SCREENX && c < myImage.height)
x++;
if (x+myImage.width >= SCREENX && c < myImage.height )
{
y++;
c++;
}
if (c >= myImage.height && x > 0)
{
x--;
}
if (x <= 0)
{
y++;
d++;
}
if (d >= myImage.height)
{
d = 0;
c = 0;
}
/* Move the alien according to the instructions in the exercise */
}
boolean createBomb()
{
if (bomb)
{
return bomb = false;
}
else if (random(0,100) > 99.5)
{
bomb = true;
}
return bomb;
}
void getBomb()
{
if(!exploded && bomb && bombOffScreen)
{
theBomb = new Bomb(x,y+myImage.height, bombImg, spaceshipImg);
bombOffScreen = false;
}
else if (!bombOffScreen && theBomb.offScreen())
{
bombOffScreen = true;
}
}
void draw()
{
image(myImage, x, y);
if (exploded)
{
myImage = blackImage;
}
}
/* boolean randomExplode()
{
if (exploded == true)
return exploded;
else if (random(0,100) > 99.7)
exploded = true;
return exploded;
} */
void explode()
{
// if (randomExplode())
if (!exploded)
{
myImage = explodeImage;
exploded = true;
image(myImage, x, y);
}
}
}