DAY 11 Action Reload, and give me Life!
Alright! Day 11 has felt very productive. I feel confident enough to say, without a doubt I’ll be on phase 2 before the week is over. I ran through the ammo countdown logic. After some thought, I asked myself “Where do we fire lasers?”.
In the Player Class under the FireLaser method is where my head went to. So I looked at the code. I wrote down what I wanted to do. Then took to typing out the syntax to make that happen.
My FireLaser method won’t work unless you have more than 0 in the ammo variable. Your player starts with 15. Tested it and wallah!
After I got things going. I needed to create a UI element that warns the player that you are out of ammo.
I took to the web for a little while and deciding what was the easiest thing to do. Since I am not a Graphic Artist and really enjoy the programming aspect. I decided to simply have a huge text in the bottom left hand corner of the screen stating “Ammo: “ + the ammo left.
Now that I got this thing going on to the next challenge. Creating new PowerUps!
This challenge proved to be a bit difficult for me. Not the logic or how to be able to do it in code, but creating new sprites for my game.
After going through the available markets to me. I did not want to pay anything to create this image.
Next stop Google!
I thought of what I should search for. It then hit me after a brief flash back into my childhood. Classic 2D image a Heart!
Since I just wanted the function to work way more than the image of the game. I decided to just use different colored hearts for life and ammo. I figured, the Player itself holds these values and uses them to gain points and pass the level. So ya know, I can argue the logic of my artistic decision….
Anyway, just took a heart shaped shaped image from the web and bam!….
Unity does not like it.
It turns out .jpeg images are not good to use for sprites and also just create a big block of white background for your image. Not really useable in game.
So I thought well which image type of files work?
I looked through my files to check the file type.
Of course it is. I felt a little silly about not realizing this but hey, it’s ok. Nobody is perfect.
So found a heart in .PNG format. Converted it in Unity to get rid of the background, Slapped on some Text and poof. A heart shaped Image to use!
After I created two game object to represent my new PowerUPS. I realized quickly that I just had to clone the components from one of my other PowerUPS since they interact with environment the same.
I also just had to add 2 more methods that told the Player, hey, if this method is called from you, this is what you do.
I also had to add the new guys to my PowerUPS drop array so they can spawn randomly
Now to see it they work.
After some debugging I got the Ammo Heart to work perfectly.
The Life Heart still does not like it when you are full on life and try to grab it. So tomorrow I’m gonna have to solve this issue. However it does its primary function correctly which is tell the Player “Hey! you have 1 more life!” And tells the UI “Hey! I added a life! Put on life back up on screen” so I end my day feeling excited about tomorrow and quoting Bart Scott “Can’t Wait!”