-
Notifications
You must be signed in to change notification settings - Fork 0
/
Duet.pde
67 lines (62 loc) · 1.51 KB
/
Duet.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
import processing.sound.*;
/*
We use these two flags below because we want to avoid the latency caused by the system when waiting for few millis to check
whether it is a single key press or a continious one. We also want the animation to be as smooth and responsive as possible
for the player experience.
*/
private boolean leftPressed, rightPressed;
private String mediaPath;
private String[] mediaFiles;
private StarField starField;
private MediaPlayer mediaPlayer;
private GameEngine game;
void setup() {
size(400, 600);
PImage icon = loadImage(dataPath("") + "/icon.jpg");
surface.setIcon(icon);
background(0);
frameRate(120);
mediaPath = dataPath("") + "/media/";
mediaFiles = new String[11];
for (int i = 0; i < 11; i++) {
mediaFiles[i] = mediaPath + i + ".mp3";
}
mediaPlayer = new MediaPlayer(this, mediaFiles);
starField = new StarField();
game = new GameEngine();
}
int x = 200, y = 100;
void draw() {
background(0);
mediaPlayer.play();
starField.display();
if (leftPressed) game.rotateLeft();
else if (rightPressed) game.rotateRight();
game.display();
game.move();
}
void keyPressed() {
if (keyCode == LEFT) {
leftPressed = true;
}
else if (keyCode == RIGHT) {
rightPressed = true;
}
}
void keyReleased() {
if (keyCode == LEFT) {
leftPressed = false;
}
else if (keyCode == RIGHT) {
rightPressed = false;
}
else if (keyCode == ESC) {
exit();
}
else if (keyCode == ENTER) {
game.startGame();
}
else if (key == ' ') {
game.saveGame();
}
}