Challenges 1 & 2 Complete!
Hello There.
It's been a bit of a busy week and a half or so, but I was able to find time to work on some of the challenges to finish the project.
Challenge #1: Game Over State is Implemented if the character falls off screen.
For this challenge, I thought that it would be relatively straightforward. My plan was to create a public float titled offScreen and set it to the coordinates just offscreen on the y axis. Then I'd use an if statement to check if the bird was offscreen and have it trigger the gameover screen if it was. My code ended up looking like this:
Those of you familiar with Unity/C# will probably know immediately what ended up happening, but needless to say I ran into an error message when I tried to test the new code.
I stared at the code and couldn't for the life of me figure out what the problem was, so I did what any sensible person learning to program would do: I googled the error message. Eventually I ran into a forum post from 2015 that illustrated the issue. Floats can't inherently have decimals, when they do they are called doubles. So I am calling for a public float, but Unity recognizes it as a double. Now, I don't know what a double is, and was afraid it would break my code if I had it call a public double instead. Fortunately someone posted a little trick to allow floats with decimal points, just add an f at the end.
I tested the code again, and everything worked as expected. With an added bonus of learning something new about Unity.
Challenge #2: The score can't go up if the game is over
This one was significantly less straightforward to figure out and I spent about twenty minutes staring at the different scripts before I found something that I think will work.
For both of our game over triggers we also have a public bool that declares birdIsAlive to be false. My thought is that if I reference that public bool in the logic manager script and then nest our Increase Score function in an if statement checking if birdIsAlive than it should theoretically work. Here is the final code I ended up with:
Now the only problem here is... I have no idea how to test to see if this works. I ran the game, so fortunately the code hasn't broken anything, but I can't think of a way to test to see if this is working properly. If anyone has any suggestions, please let me know.
What's Next?
I'm planning on doing a deep dive into sound and music in Unity next week and hopefully will be adding both background music and conquering the challenge of incorporating SFX when the score increases.
Thanks for following me on my Game Dev journey.
Best,
Morri
aka Loremother
Files
Philosophy Bird
This bird has his head in the clouds.
Status | Prototype |
Author | loremother |
Genre | Survival |
Tags | Flappy Bird, gmtk-unity-tutorial, philosophy, practice-project, Short |
Languages | English |
Leave a comment
Log in with itch.io to leave a comment.