As the title indicates, my game is a prototype that lacks beauty, but possesses all the PASSION! I made double progress this week to compensate for the minimal work I did last week on this. I’ve been studying for interviews and took the time to review everything I learned in college. I WENT CRAZY AND ATE SO MUCH ICE CREAM AND OBESITY IS MINE! For some reason, eating food calms me down, but I don’t gain weight that easily, but I have increased SEVEN POUNDS in the last 2 months… Ahh but you don’t care about that! Let’s get to what I did so far. I learn ultra mega amounts of knowledge-ifications.
First I decided to apply my object oriented programming knowledge, since I was reviewing it for interviews and made a lot of functionality to maintain modularity, so in the future if I need to redesign my code, it would not be too difficult to “upgrade”. This is what I have created so far:
- IStats Interface:
- I created all the properties for Name, Class, HP, PP, Strength, Defense and other attributes a character would have. I just did an interface to see the limitations of programming code to be added to unity. It seems scripts are in the same namespace, so any class or code you create can be accessed easily from any script if you create an object for it.
- This is kind of the “Bestiary” code, I created logic that depending on the GameObject being initialized, it would locate the name and apply the correct stats to it. For now I only have 2 entities created, the hero and the Scarlet Wisp. I have the definitions for each of their base attributes here. When an enemy is initialized in battle, its stats are found here and set to the “CurrentStats” script.
- I attached this to each Game Object in the Battle that is to have attributes. The update function here just shows the current HP and PP based on the Stats object that is created in the start function. Using the name of the object as a way to determine what entity it is, it is retrieved from the StatLibrary and applied to the current GameObject’s version of the stats object. This took some experimenting, but I discovered, that even if you attach the same script to multiple GameObjects, they are self contained and are not impacting the same data. The hero and the scarlet wisp both have this script and based on the game objects name, it initializes the stats differently. In the video you can see the different stats they have.
- I am learning this as I go, but I am trying to have everything modular, I wonder when I will run into limitations for taking this approach. It will be a good learning experience REGARDLESS!
- I created this class to create common constants to avoid a variety of variables that apply to the same thing and avoid hard coding. This will allow me to modify in one location if I by chance change the name of a game object and have no idea how many times it appears in the code. I would die, but I won’t now since I am doing this.
- I here I have defined, menu names, actions such as attack, Tags I have created to search for Game Objects among other things.
- I might change the name of this soon, but this class basically has the code to display a GameObject at a specific location relative to another Game Object. For example, the battle menu commands, I wanted the icons to appear centered and above the character executing their turn. I had to do a lot of trial and error and realized this required some equations I have LOOOOOOONG forgotten. I destroyed several sheets of paper making calculations to make it look super even, but I am pretty sure, I can optimize this logic.
- I wrote the code to rely on the amount of objects being displayed, in case I want to add more Icons, so they remain evenly distributed. I divided the amount of objects by 2 and multiplied by a “size” so they would not overlap, then starting from a negative X value of the translation, I added an increments of a positive value so once it finished with the left side of the character (negative), the increments were large enough that the X value of the translation would become positive and end up on the right side.
- I had cases to consider if it was an odd or even number of objects, but removed this for now, since I am trying to get the prototype up. I do have comments there to “optimize” this ghetto approach, say what!?
- I added another function called “moveCursor”, which would take a game object as a parameter, and move the cursor onto the corresponding option in the battle menu. The game object is passed from the “MainBattle” class code.
- This class has the main battle navigation logic, I tried using “axis” for left and right, but it would repeat the actions for that 5 times on a single press of the key. I opted for “Input.GetButtonDown” which only ran the code once.
- I created a stack and arrays for the menu, enemies and players. The stack was for allowing the player to push “cancel” and go back one menu, for example : I WANT TO USE A FIRE SPELL!!! SO I SELECT THE MAGIC BATTLE OPTION! WAIT I CHANGED MY MIND! I WANT TO ATTAAAAAAAACK!”, in this case, upon pushing the cancel button, it pops the stack into an array called “currentOptions”, which you can iterate through pressing left or right. I think this approach allows me create menus that go several levels in, and allow returning to a previous menu.
- Depending on the selection you make in the battle menu, it will address the correct array. I have yet to program the battle over conditions, but I assume, it should be easy as inserting a condition that is “when enemies count ==0″ CONGRATULATIONS YOU WIN A BRAND NEW CAR AND PLEASE TAKE THESE EXPERIENCE POINTS!.
I probably spent the most time on the display logic, since I don’t have that much experience in the visual side of unity and making it do what I want applying MATH!!! My next step is to understand these concepts a bit better so I can be the Ninja of the side quest coalition.
AHHHH!!! I almost forgot, unity got its update and it now has 2D features. I had the previous sprite animations before this update and it was ridiculously not so intuitive. I created materials, then assigned these materials to a plane and then I did the ghetto animation by changing the material tile by using offsets. With the Unity 2D features, I was able to do everything 500 times faster and deleted the inefficient approach I took previously. I will share what I did, because it was not exactly explained anywere, so I had to experiment until I found out how it worked:
- First create your sprite, you can use Gimp, it doesn’t matter how much space is between each “sprite frame”. It can be exactly how my previous post sprite sheet appears.
- Add this to your unity Project
- Click on it and change the “Texture Type” to Sprite
- If you have a sprite that will animate to multiple frames, select Multiple (a sprite editor button appears). Otherwise select Sprite mode as single (I used this for the selection arrow)
- Assuming you selected multiple for the sprite mode, click on Sprite Editor.
- You will see “slice” in the upper left corner of the window that pops up. You can click this and use the default options. Or just manually click on a sprite and adjust the dimensions yourself. When I did the automatic approach, one of my sprites got cut out! And there were some blank ones too, which I suspect is because I drew the sprite by hand and the scan had some extra dots I did not remove in GIMP.
- Now this should cause your sprite to allow expansion. I edited the name of each frame myself to have a 1-6 at the end of each sprite, so I would be able to reference the frame more easily in the future. For example, sprite_ScarletWisp1, sprite_ScarletWisp2…
- To make the sprite animate, drag it to the scene view so it appears in the hierarchy.
- Create an Animator controller and attach it to the game object in the scene.
- Open the animation window and ensure you have the sprite GameObject selected.
- Click Create Clip.
- Click Add Curve and use the sprite renderer option. Now just create a keyframe for each frame of your sprite and change the “sprite”. Play around with the amount of time for each frame to animate and VOILA!
Here is a video of what I managed to make so far, it is slowly taking form! I made the music, but I didn’t really put much effort into it, one thing at a time! I hope you enjoy! Until the next post, cya :).