Making My Own Pirate Game #1
The time has finally come to show something 😅 This post contains a bit of information about my game and a short video showing the current progress.
My goal is to create a world where the player takes on the role of a sailor who explores the seas, fights enemy pirates (or becomes one), searches for treasure, and builds a fleet. It will be just as easy to get rich there as it will be to lose everything. The hero’s death will be irreversible, but the world you sail through will remain unchanged and available to the next travelers created by the player. So if you bury a treasure on some island, after death you will be able to discover it with another hero. All of it in a humble pixel-art style.
Well, at least that is the idea: to make something in a roguelike vein. For development I use the Defold engine, where scripts are written in LUA. Here is a video showing the current progress:
The list of features right now is, in theory, pretty simple:
- you can sail a ship
- you can freely move the map, zoom in, and zoom out
- random NPCs sail around the map
- you can attack enemies until they are destroyed
- attacks have visible special effects, cannon smoke, and cannonballs splashing into the sea
Implementing all of this came with a few obstacles. The map visible in the video does not look large, but in reality it is made up of many small squares, the so-called “tiles”. Eventually it will be much bigger, so there is no point keeping the whole thing loaded all the time. That solution would eat a lot of memory and the game would end up poorly optimized, which would be shameful on the block.
To prevent that, I divided the map into so-called “chunks”, meaning grouped squares like the ones I mentioned earlier. When the player moves around the map, only the chunks directly around them or the ones that should currently be visible on the computer screen are loaded. To picture it better, imagine a chocolate bar. If you only need to see part of it on the screen, there is no point loading every atom of chocolate into memory. It is better to group them into pieces that are easy to break off and show only the ones the player should currently see.
Shooting cannons was also a challenge. Eventually the game will have several types of ships, which can carry different numbers of cannons, and those cannons will have different parameters. Of course I do not have to account for all of that at the prototype-writing stage, but it made sense to write the skeleton of those features now, so I do not have to dig through scripts later and move everything around.
So right now the code works like this: a ship has several different cannons loaded on it, and they have defined damage, reload time, and accuracy. When attacking another ship, auto-attack starts, and as many cannonballs fly out as there are cannons. Randomness and parameters decide whether a projectile hits and how much damage it deals. On top of that there are visual effects. Those, however, are a topic for a separate post 😄
Now that I have written all this out, I think maybe I did too much for a prototype, but I regret nothing. The next stage is creating the skeleton of the artificial intelligence. Enemy ships should react to the player’s attack, return fire, or flee. It would also be nice to assign them teams, so they can shoot at each other. To achieve that, I will use a so-called behavior tree. I have been wrestling with this topic for a while; I have the theory down, but in practice it is giving me some trouble. I will write more about that in the next post.
If you have any questions, feel free to leave a comment. You can do it anonymously, without registering.
Talk soon!