-
Notifications
You must be signed in to change notification settings - Fork 0
/
Led_pong.pde
76 lines (63 loc) · 1.81 KB
/
Led_pong.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
import oscP5.*;
import netP5.*;
private OPC opc;
private OscP5 oscP5;
private NetAddress sonicPi;
private State state;
private final int _LED_AMT = 179; //60 LED per M strip
//private final int _LED_AMT = 120; //30 LED per M strip
public int _score = 0;
private final int _PLAYER_SIZE = 50;
private long lastKeyPress = 0;
public void setup() {
colorMode(HSB, 100);
size(1253, 100); //60 LED per M strip
//size(1200, 100); //30 LED per M strip
opc = new OPC(this, "127.0.0.1", 7890);
opc.ledGrid(0, _LED_AMT, 1, width/2, height/2, 7, 10, 0.0, false); //60 LED per M strip
//opc.ledGrid(0, _LED_AMT, 1, width/2, height/2, 10, 10, 0.0, false); //30 LED per M strip
oscP5 = new OscP5(this, 8000);
sonicPi = new NetAddress("127.0.0.1", 4559);
State.IDLE.setObject(new IdleState());
State.GAME_START.setObject(new GameStartState());
State.GAME_ON.setObject(new GameOnState());
State.GAME_OVER.setObject(new GameOverState());
state = State.IDLE;
}
public void draw() {
background(0);
state.getObject().draw();
}
public void keyPressed() {
if (key == ' ') {
long now = millis();
if (now - lastKeyPress > 300) {
lastKeyPress = now;
state.getObject().click();
}
}
}
public void changeState(State s) {
state = s;
sendOscMessage("state", state.getIndex());
lastKeyPress = millis();
switch (state) {
case GAME_START:
State.GAME_ON.setObject(new GameOnState());
State.GAME_OVER.setObject(new GameOverState());
_score = 0;
break;
case GAME_OVER:
GameOverState gs = (GameOverState) State.GAME_OVER.getObject();
gs.explode();
break;
case GAME_ON:
sendOscMessage("go", 1);
break;
}
}
public void sendOscMessage(String msg, int val) {
OscMessage toSend = new OscMessage("/" + msg);
toSend.add((int)val);
oscP5.send(toSend, sonicPi);
}