As mentioned in game's description, the development tool for Smackings is Java. Kind of. It was the closest one to match what is happening here.
It indeed is Java's JVM running Java bytecode (or Dalvik on Android) but the code we write is not Java. The language used to make Smacklings is called Kotlin. Kotlin is a programming language created by JetBrains. You might know the company better from tools like IntelliJ IDEA or a variant of it, Android Studio. Essentially Kotlin is an independent laguage that compiles into Java bytecode an therefore is runnable wherever Java programs are.
"Why?" you might ask. Well, for two seasons. First, Google announced last year that Kotlin is the preferred language for Android development. It is pretty good reason itself but wouldn't write this post just to tell that.
Second reason is that I found Kotlin to be awesome. There are ton on cool features but I won't go through them all here. You can always go and check the official documentation
No forced semicolons! It is a small and simple thing but it makes us happy. You can still use semicolons if you really want and in cases where you really need to. Think about it, how often do you write multiple expressions on same line and need to split them up with semicolon?
Another nifty feature is string interpolation.
Instead of writing "time remaining: " + minutes + ":" + seconds
you can write "time remaining: ${minutes}:${seconds}"
neat, huh?
Here is another example what Kotlin can do. Code here is from character controller class:
private fun act(dir:Int) {
if (!alive) {
return
}
when (state) {
CharacterState.IDLING -> jump(dir)
CharacterState.JUMPING -> attack(dir)
}
}
CharacterState is an enum and state-variable is field of the class. This is kind of Kotlin version of switch-case flow but way cleaner and cooler. That when-expression could easily return a value too but that was not need for this functionality.
We might post more neat stuff from the game's sources so stay tuned for the next one!
1 comment