Did you know ?
I am not a programer.
I do not know how to solve a rubik's cube.
"Then, Why did you make one?" I hear you ask, well, i saw this video on youtube.
I already knew about cos and sin doing circles and stuff.
and I thought I could push the concept further with fake perspective.
So what simple puzzle game can I make with just a cube?
A Rubik's Cube, that's the game plan.
Making a "3D" cube
Doing the base cube wasn't that difficult,
it follows what there is in the video, but scale down the X and Y axis with of the circle with another cos controlling all of that.
Then I just keep the top and bottom part far away from one another when the cube is on front of us.
And bring the top and bottom part close to the middle of the screen for the top and bottom view.
BUT THEN !!!
Doing the nine squares on each face was more difficult
a naïve way to think of it would be to take the distance between each corner and divided by 3, repeat and multiply by 2 and you would have the coordinate, but this does not account for perspective.
The result of this was an "indent effect", it felt like the further away the squares where, the bigger they get.
We want the opposite of that.
The solution was to take shift we calculated by doing the naïve method, and adding it again to the result, and multiply this shift by a cos or a sin of the rotation of the cube.
This makes the position of the pieces in between the corner shifts away from the "camera."
and with that, we have x and y coordinate for every square on the cube that fake perspective
Is it accurate? No.
Is it good enough? ? I believe so.
Selecting and Rotating faces
Gettings the face was simple and straight to the point.
Get the inclination of the cube.
Is the camera high?Select the top face.
Is the camera low?Select the bottom face.
Else just get the rotation of the cube, and you select one of the vertical face.
But again, moving them was way more difficult,
I don't have a clear way to do it and would love to have your feedback on it.
I separated the problems on two categories, the top and bottom face, and the vertical face.
The top and bottom face wasn't so difficult, first copy all the flat faces on a table, then copy them back to the cube with the appropriated transformation, the side face of the flat face was juster a shift in their position, it works the same for the top and bottom faces.
The vertical faces were a nightmare.
Just rotating the face in front of the camera was fine and works pretty much the same as above.
But the side face was horrible.
Let me tell you first how the faces are made.
I have a table witch store each face from 1 to 6, 1 is the top, 6 the bottom and 2 to 5 the side face.
Then for each face a have 3 tables other table, for the faces X data,
And in those tables have the 3 y coordinate making a table like this:
CUBE[FACE][POSITION X][POSITION Y]
this gave me quitea headache because
you would think that for getting the side ofan another vertical face you would just move the CUBE[face] by +1 or -1,
but if you are face 2 or 5, you would get the face top and bottom, but we want to stay on the vertical face...
And when we want to get the side of the top and bottom from a verticale face, well, each verticale face are neightbore with different position X and y from the top and bottom face.
it created too many edge case.
I ended up doing a long table (or a truth table?, i don't know of those things are called) that would give the order of every x and y coordinate to take for every vertical face, and after all of that it finally work.
The Token probleme
I ran out of token.
I needed to make the menu, a scramble system for the cube, have quality of life option, and a congratulation message for when the player solve the cube, and I have 70 tokens left.
i did a Majeur rewrite off many thing to save a few token, in the finish game, i have 2 token left.
i am not a programer, i pretty much learn by doing and falling, and so i don't know any optimisation technique.
in the end, i was able to save enouph token to finish the game,
There are a few micro details in the menu I wish I could have fixed, and I wish I would have been able to do a better congratulation message... But in the end, I made it!
Congrats! you made it!
That was a fun project to make, a quick one week, one shot.
I wanted to go back to another project I was making, way bigger, a game I already put 6 months in, that I am doing on love2d.
But this is a nice break, and I wanted to have to criticism on my way of programing.
So that's it, I hope you enjoy the game!
~Savary Benjamin