In order to get more comfortable with Defold I have recently been thinking about what kind of project I should write
and I thought it would be kinda fun to port over Heartbeasts "Godot Action RPG" series to Defold.
While I do plan to write my code alongside the videos (first video 1, then video 2, etc.) this is not supposed to be a guide per se and I do not plan to go super in depth about everything.
Either way lets go!
Setting up the project
First things first: I created a new empty Defold project and set up the resolution inside the game.project file
I do not know if there is a better way to implement proper zoom in Defold but just taking your target resolution which is 1280x720 for me and then dividing it by your intended zoom level (x2) will achieve the desired effect as the window is small and when you scale it up to the target resolution it will show the desired zoom! Godot used to have a feature where you could pick an actual window resolution but also the desired rendering resolution but they also removed this for reasons.
Also since this is pixel art do not forget to change your settings from LINEAR to NEAREST to ensure the pixels aren't distorted when scaling.
Next we set up some basic WASD controls:
This is probably one of my most disliked parts of Defold, if I want to bind an action to "W" I have to scroll through the input list in the search of "W" instead of having a search or even better a "click desired key now" type of thing.
And finally I setup all animations (and some other stuff) as tile sources. Defold handles spritesheets somewhat weird in a perfect world I would love to just add my spritesheet to a Defold atlas like any other texture but then you can't access the individual parts so you either have to work with a tile source or split the graphic up into individual parts, not sure why they chose this route as this seems kinda inconvenient.
With this the basic setup is done next we can start working on the game!
Video 1 - Moving around the bush
In the first video Heartbeast implements a simple player controller which can move into one of 8 directions and a bush, simple enough.
First we set up a game object for the bush and the player
Then we create a simple player controller script (main/player/player_controller.script) like this:
and with that we have a moving player just like in video 1!
Video 2 - Make it smooth
In video 2 Heartbeast makes the player controller move more smoothly (ramp up, friction, max speed) and not faster in the diagonals by normalizing the movement vector.
I realized I already partially implemented some of the things he does here out of habit whoops!
Well first lets change our implementation to be somewhat closer to his:
To avoid the speed up problem in the diagonals we just simply normalize the velocity vector:
Next I realized that I have drifted away further from Heartbeasts implementation than originally intended so I also refactored this using an input vector plus adding friction, acceleration and setting a limit to the max speed (yeah too lazy to write this part properly...)
as you might have noticed right away Godot has a lot of fancy math functions that Defold lacks so I just opted to reimplement them in Lua:
And with this we have implemented everything from video 2!
This is probably enough for one blog post, see you in part 2!