Stack, with the stacker!
One of the most complex Projects I did this year which is a little different to what I’m used to, but with some familiar code datatypes.
Introducing the Stack, a game where you must stack as many tiles as you can, which tiles hanging out, are chopped off while the rest of its tile stays on the stack. If you accidentally stack the tile completely off the stack, you will lose the game.
WHAT I LEARNED
• Using Color32 datatype which represents the RGB format of 32-bit format to switch colors using a lerp with 4 main color arrays.
• Got the script to count all the starting 12 stiles (not stacked by the player) and store them in a private array without assigning them myself before starting the game.
• Made the blocks move either on the z or x-axis by using a bool and a vector2 axis. • Adding those colors by Vector vertices to change the entire tile’s color within its array length using color32.
• Using Mathf. Sin to randomly change the color of each block by multiplying it with the score count.
• Lerp 4(which is used to lerp through 4 colors) needs to return a value otherwise it will cause an error.
• Randomize the 4 colors to be slightly different from their public color value by using a lerp with division than returning the value.
• Using the Array code to set each tile to move along the x or z-axis when starting at its last tile stacked position. When it appears, it sets bounds so the stack does not move out of bounds by code with a new Vector3 Mathf.Sin.
• Getting a reference to each tile in the stack by using transform and array reference.
• Chopping off part of the tile that’s hanging outside the stack with a float and transform, then resizing the next one minus using the same float with Math.Abs.
• Determining if the full tile is inside the bounds of the stack using transform. X before chopping a bit off otherwise game is over if not inside bounds.
• Resizing the tile from the middle based on how much it is placed on the stack by a float and local scale Vector 3.
• Using Vector3 minus vector3 to chop off tiles that are hanging out of the stack while using a float.
• Used very similar code for each x and z movement of the respectful tile.
• Using the score to also spawn new tiles on top by adding 1 for each tile placed and in vector3.y.
WHAT WENT WRONG? COULD I HAVE DONE BETTER?
• I have never used Color32 before, so I may want to experiment with it more so I can understand how I can use it better.
• I couldn’t get one of the tiles to switch from blue to the next color as soon as the tile was placed not at the beginning of the game, but rather sometime after multiple tiles had been placed. I tried using the color array to switch to a different color afterward, but the project crashed instead which I believe it was causing it to go in a endless loop. So I need to understand better controlling loops and try again next time.
• If I play the game too fast, such as stacking the tiles so quickly, it will create a bug where the next tile will be out of the expected bounds making gameplay difficult or impossible. Due to the complicated programming I did, I haven’t figured out how I’m going to fix that bug, the only way I’m going to fix this bug, is to learn to do similar programming on its mechanics so I get ideas on how I can fix it.
OVERALL
It was a different type of exercise, it may not be as perfect as I expected, but it still turned out well, as long as the game did not crash or the mechanics break.
I haven’t quite wrapped my head around the new mechanics with the nuts and bolts I put in yet, but at least I have a rough understanding of what the code is doing.
I decided not to overcomplete the mechanics because I haven’t got a full idea about the nuts and bolts yet, but if a time calls when I’m making similar mechanics for a client or for my next game then I would be happy to come back, and make the game again to revise the mechanic and its components.
留言