title: Giving a shot at making a game using Godot Engine 3.0
date: 2018-02-03 12:43:10
In the past week, I’ve been working on a simple 3D game using [Godot Engine 3.0](https://godotengine.org/) (_go-doh_). In this article, I will show off some of the features and discuss how it all works. Here’s a quick demo of the gameplay:
## Block breaking
Blocks can be broken by just clicking on a tile of the chunk. The speed of the breaking and the damage dealt to the tile depend on the current pickaxe. Pickaxes can be upgraded in the Shop GUI. Pickaxes also have a durability value, which will always be kept at maximum when you’re on the surface. The current pickaxe along with it’s durability is displayed in the bottom right corner of the screen. When your pickaxe “breaks”, you will stop mining and you won’t be able to start mining until you repair it or return to the surface.
Blocks can also be broken using bombs. By placing a bomb, it takes approximately 3 seconds to detonate and it **damages** blocks in a 4 tile radius. Tougher blocks located deeper in the mine wont be broken by a bomb, instead made softer and thus they will take less time to mine with a pickaxe. When a bomb blows up tiles, you won’t get them in your inventory.
In the shop GUI, you can sell your mined blocks for money or buy items like torches, bombs and better pickaxes. Money can only be earned by selling the blocks you’ve mined.
This is the list of minerals currently generated in the chunk and their yield when sold:
- Copper - $15
- Iron - $20
- Silver - $50
- Gold - $100
- Amethyst - $250
- Emerald - $300
- Sapphire - $400
- Ruby - $500
- Diamond - $1000
- Flawless Diamond - $2500 (rarest)
Note that all of these are not guaranteed to generate. It depends on the random seed and the y value.
Godot uses Scenes, which can be easily instanced. The following image is the Godot editor, in it I have opened the root scene, which will be the point where the game runs.
- [**Root**](http://docs.godotengine.org/en/3.0/classes/class_spatial.html) - This is the first node in the scene, containing everything.
- [**WorldEnvironment**](http://docs.godotengine.org/en/3.0/classes/class_worldenvironment.html) - Controls the overall look of the scene. I have configured it to give me a completely black scene without a background.
- All of my other custom scenes follow these.
## The Chunk
The Chunk is a [MeshInstance](http://docs.godotengine.org/en/3.0/classes/class_meshinstance.html) which I use to generate a random mine with. I’ve attached a script to this node which generates a mesh and assigns it to the MeshInstance.
Using [SurfaceTool](http://docs.godotengine.org/en/3.0/classes/class_surfacetool.html), you can create geometry by specifying the vertices individually.
# Create a new SurfaceTool instance
var st = SurfaceTool.new()
# Begin specifying your vertices using primitive type of triangles. Every 3 vertices is a triangle.
# Half of a quad
# Output the mesh
var mesh = st.commit()
This is just a basic example of what you can do with SurfaceTool, but as you can see, it’s a great way to create procedural geometry. Alongside this I use some code to decide which material to use for which tile and the ability to regenerate the mesh when a tile is changed.
## The Player
The player is currently just a simple CapsuleMesh with a camera, a light, some raycasts and some sounds attached to it.
The script attached to it deals with [KinematicBody](http://docs.godotengine.org/en/3.0/classes/class_kinematicbody.html) movement and the block break animation. The RayCasts are used to determine whether the player is colliding with the chunk or not. The RayCast pointing up is used to cancel the jump when player hits a tile from below.
## The GUI
GUI in Godot is created using the [Control](http://docs.godotengine.org/en/3.0/classes/class_control.html) class and it’s inherited classes.
In the GUI scene I have a simple [ItemList](http://docs.godotengine.org/en/3.0/classes/class_itemlist.html) inventory and a few other items. The main thing the GUI does is the shop: buy and sell system.
On the righthand side, there are two image buttons that spawn an instance of another scene and translate it to the player’s current position. These two buttons are Bomb and Torch, which “place” their respective item.
# Load the scene
var scene = load("res://scene/props/bomb.tscn")
# Get the root instance of the scene, in this case it's a Spatial
var node = scene.instance()
# Translate the Spatial
node.set_translation(Vector3(x, y, z))
# Add it to the Root scene
This scene generates 4 quads that cover the chunk. These prevent the player from walking off of the chunk or falling out the bottom.
This scene generates a quad that has a variable texture. This scene is used to display the breaking animation of a tile, by translating it to the currently “broken” tile and setting the Texture of the material to one of the 6 crack textures.
![The 6 textures used to represent the tile breaking](https://i.lunasqu.ee/blog/crack.png)
# The Source
The source of this project is available [on my GitHub account](https://github.com/LunaSquee/xyminer). I’ve laid out the scenes, scripts, etc. into a nice folder structure so you can easily see where the things are located. I recommend you do the same when you’re making a game in Godot. If you want to try the game yourself, you can clone or download the repository onto your computer and **Import** it in the project list of the editor. Downloads are not currently available as the game is still in development, but you can easily export them in the editor.
I think that Godot is a really great game engine. It lets you do amazing things quite easily. The community is also very helpful and the [documentation](http://docs.godotengine.org/en/3.0/) is good enough for you to get started. This game still needs work for it to be enjoyable, but it’s been quite fun getting this far and I thought I’d share it with you.
Today I’m going to instruct you through the steps of installing your own Arch Linux system.
## Download the ISO
You can find the [downloads for Arch Linux by clicking here](https://www.archlinux.org/download/).
## 1. Partition the drive
Determine your drive name by running `lsblk`. Run the following command to start the partitioning (with `/dev/sda` replaced by your drive):
# fdisk /dev/sda
1. Enter `n` to create a new partition.
2. Press Enter on the following prompts to accept the defaults.
3. Enter `w` to write your changes to the disk.
## 2. Create the File System and mount it
Next, you need to create a filesystem on the partition that you’ve made. After you’ve created the filesystem, you can mount it.
# mkfs.ext4 /dev/sda1
# mount -t ext4 /dev/sda1 /mnt
## 3. Install Arch Linux system
This is maybe the most important step in the progress. This is the step where you are actually installing the system. For that, you need to run `pacstrap` followed by the packages you want to install. In this case, we’ll install `base` and `grub` for the bootloader.
# pacstrap -i /mnt base grub
## 4. Generate File System Tab
The file `fstab` contains descriptive information about the filesystems the system can mount.
# genfstab -U -p /mnt >> /mnt/etc/fstab
## 5. Enter the system via `chroot`
Now, we’re ready to set up the system by going inside it. For this, we’ll be running `arch-chroot`. **Do NOT reboot at this stage!**
# arch-chroot /mnt /bin/bash
## 6. Setting up locales
Locales are basically the language files your system will be using.
# nano /etc/locale.gen
Uncomment line en_US.UTF-8 UTF-8
Uncomment line en_US ISO-8859-1
(uncomment by removing the `#` in front)
After that, you have to generate the locale files.
And then put them into effect on the system.
# echo LANG=en_US.UTF-8 > /etc/locale.conf
# export LANG=en_US.UTF-8
## 7. Setting the timezone
All timezone files can be found in `/usr/share/zoneinfo/`. You need to create a link to `/etc/localtime` with the timezone you want.
This command sets the hardware clock from system time. `--utc` implies that your hardware clock is in the UTC timezone. More information [here](https://wiki.archlinux.org/index.php/Time#Hardware_clock)
# hwclock --systohc --utc
## 9. Set your system’s hostname
This can be anything you want.
# echo "my-computer" > /etc/hostname
## 10. Set up simple networking
Before you do the following, please run `ip a` to determine your interface. It’s generally called `eth0`, but it may be different on some machines.
Replace the "Interface=eth0" line with the one shown by the "ip a" command.
3. Enable the network
# netctl enable my_network
Setting a password on your root user is highly recommended. You can do that now by running `passwd`
You can find information on how to install GRUB on various systems on the [Arch Linux Wiki](https://wiki.archlinux.org/index.php/GRUB). The following is a simple installation on a system with a **BIOS** (not **UEFI**). You can find more boot loaders [here](https://wiki.archlinux.org/index.php/Category:Boot_loaders).
# grub-install --recheck /dev/sda
# grub-mkconfig -o /boot/grub/grub.cfg
## 13. Reboot the machine
You are now ready to boot into your new system.
# umount /mnt
After shutting down, remove the disk image and boot the system again. **You can now use your newly installed system!**
# More things to do
## Creating an user account
The first user you create should also be added to the `wheel` group. This will be kind of like an administrator.
# useradd -m -G wheel -s /bin/bash usernamehere
# passwd usernamehere
For creating other users, you should omit the `-G wheel` part unless you want them to be able to use `sudo`.
### Enabling `sudo`
1. Install sudo - `# pacman -S sudo`
2. Create a file in `/etc/sudoers.d/99-wheel` with the following lines:
%wheel ALL=(ALL) ALL
If you want the `wheel` group to be able to use sudo without password, you can replace the last `ALL` with `NOPASSWD: ALL`.
For graphics drivers, you can look at the wiki: [Intel](https://wiki.archlinux.org/index.php/Intel_graphics), [ATI](https://wiki.archlinux.org/index.php/ATI), [AMD](https://wiki.archlinux.org/index.php/AMDGPU) and [NVIDIA](https://wiki.archlinux.org/index.php/NVIDIA).
**You can find packages for various desktop environments [here](https://wiki.archlinux.org/index.php/Desktop_environment).**
### Install `lightdm`
Some desktop environments don’t have a system to log you in to a session. This is where `lightdm` comes to play.
# pacman -S lightdm lightdm-gtk-greeter
# systemctl enable lightdm.service
You can find lightdm configuration at `/etc/lightdm/lightdm.conf`.
After you’ve installed what you want, you can reboot the system and it should either load up the desktop environment or the `lightdm-gtk-greeter`, which will allow you to select a desktop environment to log in to.
## Keeping your system up-to-date
You should keep your system up-to-date to get the latest packages and security patches. Arch Linux is a **rolling release** distribution, meaning that you don’t have to reinstall the entire system and package updates are rolled separately instead of in bundles.
# pacman -Syu
This command synchronizes your system with the latest repositories and installs all available updates.
# That’s it!
This should be your basic Arch Linux system ready to go! Always remember that the [Arch Linux Wiki](https://wiki.archlinux.org/) is a great place to find help for all things Linux, not just Arch!
Today I will be describing to you my experiences with self-hosting and how you can get started as well.
I’m not going to go into detail in this article about how to install and configure anything, but the websites for respective pieces of software have great documentation and you can always look for more information online. Followup blog posts may come in the future describing setups that I’ve created.
## 1. Hardware
Believe it or not, you don’t actually need a server computer to host your websites, email or other networked software. You can use pretty much any old computer to do what you want. I know a guy who uses a laptop without a screen as a server, and quite successfully so. Your server could be anything, from an old Android phone to a router to an actual server computer, just as long as you have it connected to a network.
I have personally been using [Raspberry Pi](https://www.raspberrypi.org/) computers for my personal servers. What you might learn the hard way, though, that you really don’t want to do many write operations on a simple SD card, instead, I recommend getting a 2.5” Hard Disk Drive or a even a Solid State Drive with a simple USB to SATA converter, which you can get cheap off [eBay](https://www.ebay.com/sch/i.html?_from=R40&_trksid=m570.l1313&_nkw=usb+to+sata&_sacat=0) or [AliExpress](https://www.aliexpress.com/wholesale?SearchText=usb+to+sata). I’ve had quite a few corrupted SD cards on my Raspberry Pi’s due to high amount of concurrent writes.
### 1.1. Hosting services
For most of the heavy-lifting, though, I recommend using Virtual Private Servers for online services. I use a 10€/month cloud server from [Hetzner](https://www.hetzner.com/cloud) to host most of my websites, databases and email. I can only really recommend Hetzner and [OVH](https://www.ovh.com/) because I’ve had the best experiences with them, but you can search around the web for VPS hosting. Be sure to look at reviews and make sure to read the Terms of Service notices!
If you have more money to spend, you can also look for hosted dedicated servers.
With hosting services, you also avoid the problem of having to expose your IP address or open ports on your local network. If you don’t like your IP address being public or you simply are unable to open ports on your network, I strongly recommend that you get a low cost virtual private server instead of any local computer.
## 2. Operating System
What you’re looking for here is an operating system based on the [Linux kernel](https://en.wikipedia.org/wiki/Linux_kernel). I can recommend [Debian](https://www.debian.org/intro/about), [CentOS](https://www.centos.org/) and [Arch Linux](https://www.archlinux.org/). Linux systems are (mostly, there are paid enterprise solutions) completely free, in every sense of the word, and open source.
If you run into any issues with Linux systems, or just want to know how to configure or use a certain program, an absolutely wonderful online resource is the [Arch Linux Wiki](https://wiki.archlinux.org/), and you don’t even have to use Arch Linux in order for it to be useful to you.
## 3. Software
There’s _a lot_ of things you can run on your own server computer, so in this section, I’m going to tell you about some of the more common and more useful services.
### 3.1. Website hosting
Of course everybody wants to have a website. What would a self-hosted server be without a website?
The first thing you need in order to run a website is a web server. For beginners and simple setups, the most popular choice is the [Apache HTTP Server](https://httpd.apache.org/), however for more versatility and better (in my opinion) configuration and proxying, I recommend [nginx](http://nginx.org/) as well.
For the actual content of the website, you also have _a lot_ of options. A very good and popular free platform you can use is [WordPress](https://wordpress.org/). Of course, there’s the possibility of writing a website yourself, either in PHP and HTML or just HTML and CSS.
### 3.2. Private File Cloud
If you’re like me and don’t like having your files on **someone else’s computer**, hosting a “file cloud” yourself is a good bet. The best software to do this (by far) is [NextCloud](https://nextcloud.com/). It allows you to easily synchronize files between your computers and mobile phones and you always know that your files are safe in your own hands.
Be warned though, this application server takes a good chunk of your computer resources, so you might need something more powerful than a Raspberry Pi for this one.
#### 3.2.1. Online Documents
NextCloud can very easily help you transfer documents between your devices, but there’s also the option to integrate an Office platform, such as [Collabora Online](https://nextcloud.com/collaboraonline/), which allows you to view and edit your Office documents on the go, just like Google Docs or Office 356 Online, but you’re in control!
Be warned again, these applications are also a significant load on your server.
### 3.3. Mail Server
Okay, so you’ve got it in your head that you also want to host a mail server for yourself, but let me stop you right there. Setting up a mail server is **a really tedious and time consuming task** and you’ll probably end up giving up and using Gmail or Outlook in the end anyway. A misconfigured email server could also do a lot of harm, so please be careful with what you configure and always read the documentation if you really do plan on hosting your own mail server.
If that didn’t scare you, you may proceed. Just know that you should **NEVER** host an open email relay unless you really know what you’re doing.
#### 3.3.1. Mail Transfer Agent (MTA)
The MTA is the program used to send emails. It does not necessarily let you read/manage inboxes on its own.
One of the more popular MTAs, and the one I use, is [Postfix](http://www.postfix.org/). Creating the perfect configuration to meet your needs is, again, a tedious task. You can look for example configurations online and try them out yourself.
#### 3.3.2. Mail access (IMAP, POP3)
This is the application that actually allows you to access and store your emails on your server.
The most popular software for this is [Dovecot](https://www.dovecot.org/). Dovecot is really good at doing what it does and it allows you to set up mailboxes and can even do message sorting ([pigeonhole](https://wiki2.dovecot.org/Pigeonhole) sieve).
#### 3.3.3. Mail filtering
Mail filtering is what you would use to combat spam.
A great free software for combating spam is [SpamAssassin](https://spamassassin.apache.org/) and you can use [ClamAV](https://www.clamav.net/) to detect viruses in incoming mail.
### 3.4. Database
If you need a database, your own server is also a good place for that. For SQL databases, I recommend using [MariaDB](https://mariadb.org/). For NoSQL, you could use [MongoDB](https://www.mongodb.com/). You’ll need a MariaDB database if you’re going to host WordPress on your server.
## 4. Communication
Communication is an important part of society. Did you know that there are free and open source solutions that you can put on your own server that allows you to communicate with your friends? Here are some that I have personally come in contact with and can recommend.
**1. An aging, historical solution: IRC**
IRC (Internet Relay Chat) is an old text-based protocol used in ages old chat rooms. Believe it or not, it is still used to this day. IRC is a quick and easy way to communicate in text. A popular IRC server application is [inspIRCd](http://www.inspircd.org/).
I personally still host an IRC server for me and my friends.
**2. Purely for voice chatting: Mumble**
[Mumble](https://wiki.mumble.info/wiki/Main_Page) is a free and open source low latency voice chatting application. In order to host your own server for Mumble, you need [Murmur](https://wiki.mumble.info/wiki/Running_Murmur) (mumble-server).
**3. Up-and-coming communication standard: Matrix**
[Matrix](https://matrix.org/blog/home/) is a free and open source decentralized communication protocol. Anyone can host a server (called a homeserver) and people from different servers are able to communicate with each-other. The current go-to homeserver solution is [Synapse](https://matrix.org/docs/guides/installing-synapse), however more options are coming in the future.
As a disclaimer I’d like to say that Synapse is a large application and it might not be plausible for you to host it on your machine.
**4. Simple and modern: Rocket.Chat**
[Rocket.Chat](https://rocket.chat/) is a free and open source communication platform aimed for teams. Despite being aimed for teams, it’s also a great solution for chatting with your friends. It allows you to create rooms and also provides end-to-end encryption for messages.
I’ve personally hosted a Rocket.Chat instance and can say that it is a good platform, however me and my buddies are old-school and like our IRC server more.
### 4.1. Your own social network!
Have you ever thought about running a Twitter-like platform that you had full control over? Well, now you can! With [Mastodon](https://joinmastodon.org/), you can create your own social networking platform, called an instance. Instances are joined together in a global federated network called the [Fediverse](https://en.wikipedia.org/wiki/Fediverse), which allows you to communicate with anyone on any Mastodon (or other platform on the Fediverse) server without making multiple accounts.
## Conculsion, for now..
There’s a lot of things you can do with your own server. Hopefully this blog post was of any use to you.
So, I’ve decided to start a new blog using [Hexo](https://hexo.io/).
I’ll probably be using this to share my projects and write some tutorials.
## Current projects
I’m currently taking a break from writing code due to personal reasons, but I’m mainly working on my network, [Icy Network](https://icynet.eu). The main project in the works is [Episodes.Community](https://github.com/IcyNet/Episodes.Community), which is basically a site where people can watch and share links to their favorite TV shows and cartoons.