-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch_words.pde
185 lines (154 loc) · 4.83 KB
/
sketch_words.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
176
177
178
179
180
181
182
183
184
185
/* Definitions **********************************************************************************************************/
/* define blocks and paramters*/
float liquidHeight = 4;
float liquidDensity = 50;
boolean useThreeLiuquids = false;
FBox l1;
FBox l2;
FBox l3;
/* define start and stop button */
FCircle c1;
FCircle c2;
/* define game ball and paramters */
float objectDensity = 200;
/* define game start */
boolean gameStart = false;
boolean gameEnd = false;
boolean atCenter = false;
boolean runLevel = false;
/* define game parameters */
int maxLevel = 3;
int currentLevel = 1;
int levelProgress = 0;
int levelBase = 0;
float levelAngle = 0;
float levelForce = 0;
/* end definitions *****************************************************************************************************/
/* setup section *******************************************************************************************************/
void setup(){
/* screen size definition */
size(1000, 700);
PhysicsSetup();
}
void PhysicsDefinitions()
{
/* Start Button */
c2 = new FCircle(5.0);
c2.setPosition(worldWidth/2, worldHeight/2);
c2.setFill(255);
c2.setStaticBody(true);
world.add(c2);
c1 = new FCircle(1.0);
c1.setPosition(worldWidth/2, worldHeight/2);
c1.setFill(0, 255, 0);
c1.setStaticBody(true);
world.add(c1);
}
/* end setup section ***************************************************************************************************/
/* calbacks ************************************************************************************************************/
/* end callbacks *******************************************************************************************************/
/* Keyboard inputs *****************************************************************************************************/
void keyPressed()
{
if (key == ' ')
{
if (!gameStart || gameEnd)
return;
if (currentLevel < maxLevel){
currentLevel++;
resetLevel();
}
else {
gameStart = false;
gameEnd = true;
currentLevel = 1;
}
world.remove(s.h_avatar);
world.add(s.h_avatar);
}
else if(key == 'n')
{
gameStart = false;
gameEnd = false;
resetLevel();
}
}
/* end of keyboard inputs **********************************************************************************************/
/* draw section ********************************************************************************************************/
void drawLoop(){
if(gameStart){
if (!runLevel)
text("Move to the center", width/2, 60);
}
else {
fill(128, 128, 128);
textAlign(CENTER);
if ( gameEnd ) {
text("Thank you", width/2, 60);
}
else {
text("Move to the center", width/2, 60);
}
}
}
/* end draw section ****************************************************************************************************/
/* helper functions section, place helper functions here ***************************************************************/
void PhysicsSimulations()
{
if (gameEnd)
return;
if(s.h_avatar.isTouchingBody(c1)) {
if (!gameStart) {
gameStart = true;
s.h_avatar.setSensor(true);
}
if (!runLevel){
atCenter = true;
runLevel = true;
resetLevel();
}
} else if (s.h_avatar.isTouchingBody(c2) && atCenter) {
runLevel = true;
} else {
runLevel = false;
atCenter = false;
}
if (atCenter){
levelAngle = 0; //random(-PI, PI);
switch (currentLevel){
case 1:// calm
levelProgress = millis() - levelBase;
levelForce = 1.5 + levelProgress * 0.0002;
fEE.add(levelForce * cos(levelAngle) , levelForce * sin(levelAngle));
s.h_avatar.setDamping(500);
break;
case 2:// angry
levelProgress = millis() - levelBase;
// delayed force push
if (levelProgress > 2000)
{
levelForce = 3 + levelProgress * 0.0002;
fEE.add(levelForce * cos(levelAngle) , levelForce * sin(levelAngle));
}
break;
case 3:// excited
levelProgress = millis() - levelBase;
levelForce = 1.5 + levelProgress * 0.001;
fEE.add(levelForce * cos(levelAngle) , levelForce * sin(levelAngle));
// adding noice
levelAngle = random(-PI, PI);
fEE.add(1.5 * cos(levelAngle) , 1.5 * sin(levelAngle));
break;
}
fEE.limit(3.5);
}
}
void resetLevel() {
levelProgress = 0;
levelBase = millis();
s.h_avatar.setDamping(000);
}
void exit() {
PhysicsExit();
super.exit();
}