-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradPong.pde
112 lines (90 loc) · 1.85 KB
/
radPong.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
/*
Radial Pong Prototype
Pete Hawkes
2012
*/
boolean drawing;
Circle circle;
Blocker blocker;
void setup() {
size(540, 960);
smooth();
noStroke();
circle = new Circle();
blocker = new Blocker();
}
void draw() {
background(0);
circle.update();
blocker.update();
hitCheck();
pushMatrix();
translate(width/2, height/2);
drawUnderBoard();
circle.display();
blocker.display();
drawOverBoard();
popMatrix();
}
void drawOverBoard() {
// cover
noStroke();
fill(0, 100);
rect(-width/2, 0, width, height/2);
// line
stroke(100);
line(-width/2, 0, width/2, 0);
}
void drawUnderBoard() {
// home
noStroke();
fill(255, 0, 0);
ellipse(0, 0, 10, 10);
}
void hitCheck() {
//
//println(circle.rad +":"+(blocker.rad + circle.speed));
float bonusPadding = blocker.speed*2;
float maxRange = blocker.rad + circle.speed*2;
if (blocker.rad + 5 > maxRange) maxRange = blocker.rad + 5;
if (circle.rad > blocker.rad && circle.rad < maxRange) {
// in range, check for angle
if (circle.angle > blocker.angle - blocker.bonusPadding && circle.angle < blocker.angle + blocker.angleWidth + blocker.bonusPadding) {
if (circle.speed > 0 ) {
//println("hit: "+ circle.rad);
circle.speed *= -1;
circle.rad = blocker.rad;
blocker.reduceBlocker();
}
}
}
}
void reset() {
println("RESET");
circle.reset();
blocker.reset();
}
void mousePressed() {
drawing = false;
}
void mouseReleased() {
drawing = true;
}
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
//blocker.speed = -(.03 + abs(circle.speed)/200);
blocker.speed = -.05;
}
if (keyCode == RIGHT) {
blocker.speed = (.03 + abs(circle.speed)/200);
blocker.speed = .05;
}
}
if (key == ENTER) {
reset();
}
}
void keyReleased() {
blocker.speed = 0;
}