-
Notifications
You must be signed in to change notification settings - Fork 0
/
asteroids.pde
166 lines (136 loc) · 2.96 KB
/
asteroids.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//Alan Fung
//Asteroids Project
//October 2021
boolean upkey, downkey, leftkey, rightkey, spacekey, enterkey;
Ship myShip;
ArrayList<GameObject> myObjects;
//colors
color pink = #EAA7FF;
color green = #A7FFB7;
color white = #FFFFFF;
color brown = #896120;
color red = #F70000;
color orange = #FA8303;
color blue = #03ADFA;
color yellow = #E8BB3F;
color black = #030303;
color darkyellow = #FFAC12;
color darkblue = #272D4D;
color purple = #6E06B9;
color darkred = #F25D5D;
color grey = #48423F;
color mango = #FF6A5A;
//mode variables
int mode;
final int INTRO = 0;
final int GAME = 1;
final int PAUSE = 2;
final int GAMEOVER = 3;
//gif
PImage [] gif;
int numberOfFrames;
int f;
//UFO pic
PImage UFO;
//Asteroid pic
PImage asteroid;
//font
PFont font;
//UFO random path
int UFOpath;
//ship lives
int shiplives;
//immunity
int immune;
//counting of asteroids destroyed
int count;
//generate UFO timer
int generate;
//teleport
float teleport;
boolean moves;
int a, b;
void setup() {
size(800, 800);
imageMode(CENTER);
rectMode(CENTER);
myShip = new Ship();
myObjects = new ArrayList<GameObject>();
myObjects.add(myShip);
myObjects.add(new Asteroid());
myObjects.add(new Asteroid());
myObjects.add(new Asteroid());
myObjects.add(new UFO());
//mode
mode = INTRO;
//UFO image
UFO = loadImage("alienship.png");
//asteroid image
asteroid = loadImage("asteroidpic.png");
//gif
numberOfFrames = 40;
gif = new PImage [numberOfFrames];
int i = 0;
while (i < numberOfFrames) {
if (i < 10) {
gif[i] = loadImage("frame_00"+i+"_delay-0.03s.gif");
} else if (i < 40) {
gif[i] = loadImage("frame_0"+i+"_delay-0.03s.gif");
}
i++;
}
//font
font = createFont("NotoSansMono-Light.ttf", 2);
//UFO generator timer
generate = 0;
//teleport timer
teleport = 0;
}
void draw() {
if (mode == GAME) {
background(0);
}
int i = 0;
while (i < myObjects.size() && mode == GAME) {
GameObject myObj = myObjects.get(i);
myObj.show();
myObj.act();
if (myObj.lives == 0) {
myObjects.remove(i);
} else if (shiplives == 0) {
myObjects.remove(i);
} else if (count == 21) {
myObjects.remove(i);
} else {
i++;
}
}
//modes
if (mode == INTRO) {
intro();
} else if (mode == GAME) {
game();
} else if (mode == PAUSE) {
pause();
} else if (mode == GAMEOVER) {
gameover();
} else {
println("Error: mode = " + mode);
}
}
void keyPressed() {
if (keyCode == UP) upkey = true;
if (keyCode == DOWN) downkey = true;
if (keyCode == LEFT) leftkey = true;
if (keyCode == RIGHT) rightkey = true;
if (keyCode == ENTER) enterkey = true;
if (key == ' ') spacekey = true;
}
void keyReleased() {
if (keyCode == UP) upkey = false;
if (keyCode == DOWN) downkey = false;
if (keyCode == LEFT) leftkey = false;
if (keyCode == RIGHT) rightkey = false;
if (keyCode == ENTER) enterkey = false;
if (key == ' ') spacekey = false;
}