In this lecture we are going to learn how to add the scoring to the Flappy Bird game. It means the score has to be even higher when our bird could fly through the gap of the pipes.
In the next part we are going to add the collision detection. The collision detection is a very important part of the Flappy Bird app. If we can drive the bird between the pipes, then we are going to get 1 point, but if we can’t, then we will lose the game. It means, thet our bird collided with the pipes. At the of this lecture we will have this collision detection 🙂
Every Kotlin program has at least one function main(). However, you can define any number of functions in your program until memory is not full. It’s always a good practice to divide the whole program into smaller functions that are logically similar. It makes program more readable, understandable and debuggable.
A function declaration is done using the fun keyword.
The basic syntax of a function in Kotlin looks like this:
Syntax of for loop
An Array is a collection of a values of the same type. When you need to store a list of values, such as numbers, you can store them in an array, insted of declaring separate variables for each number.
Constructor of Array in Kotlin
Syntax of Array in Kotlin
As you can see, constructor of array takes a fix size and an init function to return elements of array. There are multiple ways to create a kotlin array
- Using Library function
- Using Array Constructor
- Using Factory function
The for loop iterates through a collection, more specifically through anything that provides an iterator.
Syntax to use for loop in Kotlin.
With the Maps SDK for Android, we can add maps based on Google Maps data to our application.