forked from tcl510/shooter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshooter.pde
175 lines (158 loc) · 4.33 KB
/
shooter.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
167
168
169
170
171
172
173
174
175
//<>// //<>// //<>//
void setup() {
//based on og galaga dimensions
size(672, 864);
//bc this frameRate is unachieveable, processing will try its best to render at highest frameRate resulting in as smooth as possible gameplay
frameRate(100000);
//load sound files
loadSound();
//galaga setup
galaga_setup();
}
void draw() {
//play the game galaga;
gameStateHandler();
//start the timer function(helps universially with timing the game)
time();
}
Player player;
int gameState = 1;
final int GAMESTATE_MENU = 0;
final int GAMESTATE_OPENING = 1;
final int GAMESTATE_GAME_KEYBOARD = 2;
final int GAMESTATE_GAME_WEBCAM = 3;
final int GAMESTATE_HOWTO = 4;
final int GAMESTATE_GAMEOVER = 5;
void gameStateHandler() {
switch(gameState) {
case GAMESTATE_MENU:
bg();
menu();
break;
case GAMESTATE_GAME_KEYBOARD:
galagaKeyboard();
break;
case GAMESTATE_OPENING:
bg();
splashScreen();
break;
case GAMESTATE_GAME_WEBCAM:
galagaWebcam();
break;
case GAMESTATE_HOWTO:
bg();
howTo();
break;
case GAMESTATE_GAMEOVER:
background(0);
gameOver();
break;
default:
gameState = GAMESTATE_GAME_KEYBOARD;
break;
}
}
//game setup
void galaga_setup() {
newStars();
player = new Player();
}
//neatly wrapped game to be put in draw
void galagaKeyboard() {
//draw and update objects
bg();//update background
player.draw(); //player
bullets(); //draw, render, and delete, and determain behaviour of bullets
enemies(); //draw, render, and delete enemies
explosions(); //draw, render, and delete explosions
gameGui();//draw ui
}
void galagaWebcam() {
//draw and update objects
updatePosByWebcam(); //updating the position of the block
bg();//update background
gameGui();//draw ui
if (!paused){
player.draw(); //player
bullets(); //draw, render, and delete, and determain behaviour of bullets
enemies(); //draw, render, and delete enemies
explosions(); //draw, render, and delete explosions
} else {
textAlign(CENTER,CENTER);
text("paused", width/2, height/2);
}
}
void mousePressed() {
println(new PVector(mouseX, mouseY));
}
//controller function
void keyPressed() {
//galaga movement
if (gameState == GAMESTATE_OPENING) {
if (key == ' ') gameState = GAMESTATE_MENU;
return;
}
if (gameState == GAMESTATE_MENU) {
if (key == 'a' || keyCode == LEFT || key == 'A') selection--;
if (key == 'd' || keyCode == RIGHT || key == 'D') selection++;
if (key == 'w' || keyCode == UP || key == 'W') selection++;
if (key == 's' || keyCode == DOWN || key == 'S') selection--;
if (selection > 2) {
selection = 0;
}
if (selection < 0) {
selection = 2;
}
if (key == ' ' || keyCode == ENTER) {
gameState = GAMESTATE_GAME_KEYBOARD + selection;
restartGame();
};
return;
}
if (gameState == GAMESTATE_HOWTO) {
if (key == ' ' || keyCode == ENTER) gameState = GAMESTATE_MENU;
return;
}
if (gameState == GAMESTATE_GAME_KEYBOARD) {
if (key == 'a' || keyCode == LEFT || key == 'A') player.left = true;
if (key == 'd' || keyCode == RIGHT || key == 'D') player.right = true;
if (key == 'w' || keyCode == UP || key == 'W') player.up = true;
if (key == 's' || keyCode == DOWN || key == 'S') player.down = true;
if (key == ' ') player.shoot();
}
if (gameState == GAMESTATE_GAME_WEBCAM) {
if (key == ' ') player.shoot();
}
if (gameState == GAMESTATE_GAMEOVER) {
if (key == ' ') {
sad.stop();
gameState = GAMESTATE_OPENING;
};
}
}
void keyReleased() {
//galaga movement
if (gameState == GAMESTATE_GAME_KEYBOARD) {
if (key == 'a' || keyCode == LEFT || key == 'A') player.left = false;
if (key == 'd' || keyCode == RIGHT || key == 'D') player.right = false;
if (key == 'w' || keyCode == UP || key == 'W') player.up = false;
if (key == 's' || keyCode == DOWN || key == 'S') player.down = false;
if (key == ' ') player.isShooting = false;
}
if (gameState == GAMESTATE_GAME_WEBCAM) {
if (key == ' ') player.isShooting = false;
}
}
void restartGame() {
if (gameState == GAMESTATE_GAME_WEBCAM){
loadWebCam();
}
currentWave = newWave(0);
score = 0;
level = 1;
lives = 3;
player = new Player();
bullets = new ArrayList<Bullet>();
enemyBullets = new ArrayList<Bullet>();
explosions = new ArrayList<Explosion>();
}