-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawMethods.pde
140 lines (119 loc) · 4.31 KB
/
DrawMethods.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
//#############################################
//------------------DRAW GAME------------------
//#############################################
void drawGame() {
gameSurface.beginDraw();
basic_settings();
drawBoard();
drawSphere();
drawParticleSystem();
gameSurface.endDraw();
}
//#############################################
//--------------DRAW SCORE_BOARD---------------
//#############################################
void drawScoreBoard() {
scoreBoard.beginDraw();
scoreBoard.background(scoreColor);
scoreBoard.text("Total Score : ", 10, 25);
scoreBoard.text(Float.toString(getPoints()), 20, 45);
scoreBoard.text("Velocity : ", 10, 65);
scoreBoard.text(Float.toString(playable_sphere.velocity.mag()), 20, 85);
scoreBoard.text("Last score : ", 10, 105);
scoreBoard.text(Float.toString(getLastPoints()), 20, 125);
scoreBoard.endDraw();
}
//#############################################
//----------------DRAW TOP_VEIW----------------
//#############################################
void drawTopView() {
topView.beginDraw();
topView.background(topViewBoard);
float ellipseX = (playable_sphere.location().x + boxLength/2) * square_for_score/boxLength;
float ellipseY = (playable_sphere.location().z + boxLength/2) * square_for_score/boxLength;
float ellipseWidth = 2*radius_sphere*square_for_score/boxLength;
float ellipseHeight = ellipseWidth;
topView.fill(colorSphereTopView);
topView.ellipse(ellipseX, ellipseY, ellipseWidth, ellipseHeight);
if (particle_system!=null) {
particle_system.particleTopView();
}
topView.endDraw();
}
//#############################################
//---------------DRAW BAR_CHART----------------
//#############################################
void drawBarChart() {
barChart.beginDraw();
barChart.background(colorBarChart);
barChart.rectMode(CORNER);
barChart.fill(255);
score_scale = 0.5 + hs_scroll_bar.getPos();
rectIndex = 0;
if (lastSecond != second() && !gamePaused) {
scores.add(getPoints());
}
// Display the chart
for (Float score_index : scores) {
float scaling = (Math.abs(score_index) > 2) ? 2*(log(Math.abs(score_index))) : score_index;
float dimRect = rectSize*score_scale;
float coordX = rectIndex*rectSize*score_scale;
for (int col = 0; col <= Math.abs(scaling); ++col) {
float coordY = col*rectSize*score_scale;
if(score_index < 0) {
barChart.rect(coordX, coordY + score_graphic/2, dimRect, dimRect);
} else {
barChart.rect(coordX, -coordY + score_graphic/2, dimRect, dimRect);
}
}
rectIndex++;
}
lastSecond = second();
barChart.endDraw();
}
//#############################################
//----------AUX METHODS FOR DRAW_GAME----------
//#############################################
//---------------BASIC SETTINGS----------------
void basic_settings(){
gameSurface.noStroke();
gameSurface.directionalLight(directionalColor.x, directionalColor.y, directionalColor.z, 0, 1, 0);
gameSurface.ambientLight(ambientColor, ambientColor, ambientColor);
gameSurface.background(backgroundColor);
}
//-------------SETUP OF THE BOARD--------------
void drawBoard(){
gameSurface.translate(width/2, height/2, -score_graphic);
gameSurface.rotateX(thetaX);
gameSurface.rotateY(thetaY);
gameSurface.rotateZ(thetaZ);
gameSurface.fill(boardColor);
gameSurface.box(boxLength, boxThickness, boxLength);
}
//------------SETUP OF THE SPHERE--------------
void drawSphere(){
if(!gamePaused) {
playable_sphere.update();
}
playable_sphere.checkEdges();
playable_sphere.display();
}
//--------SETUP OF THE PARTICLE SYSTEM---------
void drawParticleSystem(){
for (int i = particle_system.particles.size(); i > 0; --i) {
PVector position = particle_system.particles.get(i-1);
gameSurface.pushMatrix();
gameSurface.translate(position.x,0 , position.z ); //translate origin back to left upper corner
cylinder.display();
gameSurface.popMatrix();
}
if(particle_system.origin != null) {
gameSurface.pushMatrix();
gameSurface.translate(particle_system.origin.x , -cylinderHeight , particle_system.origin.z ); //translate origin back to left upper corner
gameSurface.shape(robotnik);
gameSurface.popMatrix();
}
if(!particle_system.particles.isEmpty() && !gamePaused) {
particle_system.run();
}
}