@@ -11,13 +11,43 @@ FloppyCube InitFloppyCube(FloppyCube floppyCube){
1111 return floppyCube ;
1212}
1313
14- void DrawFloppyCube (FloppyCube floppyCube ){
14+ float progress = 0 ;
15+ int fRotating = 0 ;
16+ int rRotating = 0 ;
17+ int lRotating = 0 ;
18+ int bRotating = 0 ;
19+
20+ int animSpeed = 4 ;
21+
22+ FloppyCube DrawFloppyCube (FloppyCube floppyCube ){
23+ if (fRotating || rRotating || lRotating || bRotating ){
24+ progress += animSpeed ;
25+ }
26+ if (progress >= 180 ){
27+ progress = 0 ;
28+ if (fRotating ){
29+ floppyCube = ExecuteTurn (floppyCube , F );
30+ fRotating = 0 ;
31+ }
32+ if (rRotating ){
33+ floppyCube = ExecuteTurn (floppyCube , R );
34+ rRotating = 0 ;
35+ }
36+ if (lRotating ){
37+ floppyCube = ExecuteTurn (floppyCube , L );
38+ lRotating = 0 ;
39+ }
40+ if (bRotating ){
41+ floppyCube = ExecuteTurn (floppyCube , B );
42+ bRotating = 0 ;
43+ }
44+ }
1545 Vector2 planeSize = {1.9 , 1.9 };
1646
1747 float planeOffset = 0.005 ;
1848
1949 // Black centre area
20- DrawCube ((Vector3 ){0.0 ,0.0 ,0.0 }, 6.0 , 2.0 , 6.0 , BLACK );
50+ // DrawCube((Vector3){0.0,0.0,0.0}, 6.0, 2.0, 6.0, BLACK);
2151
2252 // White and yellow stickers
2353 DrawPlane ((Vector3 ){0.0 ,planeOffset + 1.0 ,0.0 }, planeSize , WHITE );
@@ -45,46 +75,122 @@ void DrawFloppyCube(FloppyCube floppyCube){
4575 index -- ;
4676 }
4777
78+ rlPushMatrix ();
79+ if (i > 3 && i != 5 && fRotating ){
80+ rlRotatef (progress , 0 , 0 , 1 );
81+ }
82+ if (rRotating && (index == 2 || index == 4 || index == 7 )){
83+ rlRotatef (progress , 1 , 0 , 0 );
84+ }
85+ if (lRotating && (index == 0 || index == 3 || index == 5 )){
86+ rlRotatef (progress , 1 , 0 , 0 );
87+ }
88+ if (bRotating && index < 3 ){
89+ rlRotatef (progress , 0 , 0 , 1 );
90+ }
4891 DrawPlane ((Vector3 ){pos .x ,planeOffset + 1.0 ,pos .y }, planeSize , GetColorFromIndex (floppyCube .topFace [index ]));
92+ rlPopMatrix ();
4993
5094 rlPushMatrix ();
5195 rlRotatef (180 , 0 , 0 , -1 );
5296 rlRotatef (180 , 0 , 1 , 0 );
97+ if (i < 3 && fRotating ){
98+ rlRotatef (progress , 0 , 0 , -1 );
99+ }
100+ if (bRotating && index > 4 ){
101+ rlRotatef (progress , 0 , 0 , -1 );
102+ }
103+ if (rRotating && (index == 2 || index == 4 || index == 7 )){
104+ rlRotatef (progress , 1 , 0 , 0 );
105+ }
106+ if (lRotating && (index == 0 || index == 3 || index == 5 )){
107+ rlRotatef (progress , 1 , 0 , 0 );
108+ }
53109 DrawPlane ((Vector3 ){pos .x ,planeOffset + 1.0 ,pos .y }, planeSize , GetColorFromIndex (floppyCube .bottomFace [index ]));
54110 rlPopMatrix ();
55111 }
56112
57113 // Green stickers
58114 rlPushMatrix ();
59115 rlRotatef (90 , 1 , 0 , 0 );
116+ if (fRotating ){
117+ rlRotatef (progress , 0 , 1 , 0 );
118+ }
119+ if (lRotating ){
120+ rlRotatef (progress , 1 , 0 , 0 );
121+ }
60122 DrawPlane ((Vector3 ){-2 ,3 + planeOffset ,0 }, planeSize , GetColorFromIndex (floppyCube .frontFace [0 ]));
123+ if (lRotating ){
124+ rlRotatef (progress , -1 , 0 , 0 );
125+ }
61126 DrawPlane ((Vector3 ){0 ,3 + planeOffset ,0 }, planeSize , GetColorFromIndex (floppyCube .frontFace [1 ]));
127+ if (rRotating ){
128+ rlRotatef (progress , 1 , 0 , 0 );
129+ }
62130 DrawPlane ((Vector3 ){2 ,3 + planeOffset ,0 }, planeSize , GetColorFromIndex (floppyCube .frontFace [2 ]));
63131 rlPopMatrix ();
64132
65133 // Red stickers
66134 rlPushMatrix ();
67135 rlRotatef (-90 , 0 , 0 , 1 );
136+ if (rRotating ){
137+ rlRotatef (progress , 0 , 1 , 0 );
138+ }
139+ if (fRotating ){
140+ rlRotatef (progress , 0 , 0 , 1 );
141+ }
68142 DrawPlane ((Vector3 ){0 ,3 + planeOffset ,2 }, planeSize , GetColorFromIndex (floppyCube .rightFace [0 ]));
143+ if (fRotating ){
144+ rlRotatef (progress , 0 , 0 , -1 );
145+ }
69146 DrawPlane ((Vector3 ){0 ,3 + planeOffset ,0 }, planeSize , GetColorFromIndex (floppyCube .rightFace [1 ]));
147+ if (bRotating ){
148+ rlRotatef (progress , 0 , 0 , 1 );
149+ }
70150 DrawPlane ((Vector3 ){0 ,3 + planeOffset ,-2 }, planeSize , GetColorFromIndex (floppyCube .rightFace [2 ]));
71151 rlPopMatrix ();
72152
73153 // Orange stickers
74154 rlPushMatrix ();
75155 rlRotatef (90 , 0 , 0 , 1 );
156+ if (lRotating ){
157+ rlRotatef (progress , 0 , -1 , 0 );
158+ }
159+ if (bRotating ){
160+ rlRotatef (progress , 0 , 0 , 1 );
161+ }
76162 DrawPlane ((Vector3 ){0 ,3 + planeOffset ,-2 }, planeSize , GetColorFromIndex (floppyCube .leftFace [0 ]));
163+ if (bRotating ){
164+ rlRotatef (progress , 0 , 0 , -1 );
165+ }
77166 DrawPlane ((Vector3 ){0 ,3 + planeOffset ,0 }, planeSize , GetColorFromIndex (floppyCube .leftFace [1 ]));
167+ if (fRotating ){
168+ rlRotatef (progress , 0 , 0 , 1 );
169+ }
78170 DrawPlane ((Vector3 ){0 ,3 + planeOffset ,2 }, planeSize , GetColorFromIndex (floppyCube .leftFace [2 ]));
79171 rlPopMatrix ();
80172
81173 // Blue stickers
82174 rlPushMatrix ();
83175 rlRotatef (-90 , 1 , 0 , 0 );
176+ if (bRotating ){
177+ rlRotatef (progress , 0 , -1 , 0 );
178+ }
179+ if (rRotating ){
180+ rlRotatef (progress , 1 , 0 , 0 );
181+ }
84182 DrawPlane ((Vector3 ){2 ,3 + planeOffset ,0 }, planeSize , GetColorFromIndex (floppyCube .backFace [0 ]));
183+ if (rRotating ){
184+ rlRotatef (progress , -1 , 0 , 0 );
185+ }
85186 DrawPlane ((Vector3 ){0 ,3 + planeOffset ,0 }, planeSize , GetColorFromIndex (floppyCube .backFace [1 ]));
187+ if (lRotating ){
188+ rlRotatef (progress , 1 , 0 , 0 );
189+ }
86190 DrawPlane ((Vector3 ){-2 ,3 + planeOffset ,0 }, planeSize , GetColorFromIndex (floppyCube .backFace [2 ]));
87191 rlPopMatrix ();
192+
193+ return floppyCube ;
88194}
89195
90196FloppyCube ExecuteTurn (FloppyCube cube , int turn ){
@@ -120,6 +226,21 @@ FloppyCube ExecuteTurn(FloppyCube cube, int turn){
120226 return cube ;
121227}
122228
229+ void DoTurn (FloppyCube cube , int turn ){
230+ if (turn == F ){
231+ fRotating = 1 ;
232+ }
233+ if (turn == B ){
234+ bRotating = 1 ;
235+ }
236+ if (turn == R ){
237+ rRotating = 1 ;
238+ }
239+ if (turn == L ){
240+ lRotating = 1 ;
241+ }
242+ }
243+
123244FloppyCube RandomScramble (FloppyCube cube ){
124245 int previous ;
125246
0 commit comments