Forest Defender Devlog 1: Development Setup
Tags: gamedev, pygame, python, devjournal
Published: 2022-10-26 21:35:08

# Forest Defender Devlog 1: Development Setup

</br>

<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/19c8bdz3ex1o0ghuut37.jpg" loading="lazy" style="min-width:300px; max-width:600px;" />

<a href="https://www.freepik.com/free-vector/video-game-developer-concept-illustration_13746511.htm#query=game%20development&position=3&from_view=keyword">Image by storyset</a> on Freepik

<i> Written on October 25th, 2022</i>

</br>

## Table of Contents

* <a href="#preface"> Preface </a>
* <a href="#development-machine"> Development Machine </a>
* <a href="#installation-updating"> Development Tool Installation / Updating </a>
* <a href="#virtual-environment"> Virtual Environment </a>
* <a href="#installing-libraries"> Installing Libraries </a>
* <a href="#checking-everything-works"> Checking Everything Works! </a>
* <a href="#further-reading"> Resources / Further Reading </a>

<a id="preface"></a>

</br>

## Preface

The goal of this devlog is to show how I set up my environment for development of this game. Future devlogs will focus on higher level topics, such as game development updates, topics and discussion of the game, etc., instead of lower level topics like this devlog.

That is not to say I won't go into any details / code in future devlogs. If there is an interesting challenge I face or a topic I think is helpful to explain or show, I will certainly add it to the devlog.

<a id="development-machine"></a>

</br>

## What will be used as the development machine?

</br>

The development machine chosen to create a game is important as it sets the main target OS for the game build, creates the subset of tools that can be used, and sets the development environment as a whole.

My development machine is a Windows 10 desktop computer. The specifications are as follows:
* Motherboard: ASUS ROG STRIX Z390-E Gaming
* Processor: Intel Core i9 9900k
* RAM: 32GB of CORSAIR 3.0GHz DDR4
* Storage:
    * Samsung 970 EVO Plus 500GB
    * Samsung 970 EVO Plus 500GB (second one)
    * Western Digital 1TB Hard drive
* Graphics Card: NVIDIA GeForce RTX 2080 SUPER

This machine is certainly overkill for any development we are doing at this scale, especially since we are working on a 2-D game using Python. The machine also serves as a gaming computer for me, which is why these are its specifications.

Since I am using Windows 10 as my development OS, we are locked into tools that are available on Windows 10. While this does cut off a lot of Linux tools, we are still left with plenty. We are also locked into targeting Windows 10 for the main audience for the game. Python and the libraries we are using are able to run on the three major operating systems (Windows, macOS, Linux), but we will be testing and developing on the above system, so any testing on Linux and macOS will come at the end of development.

Ultimately, this is perfectly fine since most games are released on Windows versus the other operating systems and therefore most gamers use Windows to play games. So our audience is still the biggest 'chunk' of people.

<a id="installation-updating"></a>

</br>

## Development Tool Installation / Updating

</br>

We won't be needing too many tools to get started with this project. We will install the following:

* [VS Code](https://code.visualstudio.com/)
* [Aseprite](https://www.aseprite.org/)
* [Tiled](https://www.mapeditor.org/)

VS Code will be used as our text editor of choice. This is for planning of the game, project file management, and writing the actual code.

Aseprite will be used to create all the assets for the game, including the animations.

Tiled is our choice for taking those assets created in Aseprite and using them to create levels.

<a id="virtual-environment"></a>

</br>

## Virtual Environment

</br>

We want to keep our environment (module installations, Python version, etc.) separate from the OS wide installations. In order to do so, we need to create a separate container to store the environment. The way we will achieve this during this development run will be with Python's [Virtual Environment](https://docs.python.org/3/library/venv.html).

It is extremely easy to setup. Ensure you have some version of Python 3+ installed on your machine, and run the following in the terminal / CMD:

```shell
> python -m venv env
```

In this command, we are telling Python to run the venv command, which creates a virtual environment in the current directory, and call it 'env.'

To enter the virtual environment while in the Windows OS, simply traverse to the directory containing it and enter:

```shell
> env/scripts/activate
```

<a id="installing-libraries"></a>

</br>

## Installing Libraries

</br>

To get started with the game, we don't need too many libraries. For now, we will only be using Pygame.

```shell
> pip install pygame
```

<a id="checking-everything-works"></a>

</br>

## Checking Everything Works!

</br>

Now that we have the environment setup, all that is left to do before beginning with development is make sure it all works. We will be checking that the Python environment and Pygame installation were properly done. To accomplish this check, we will run the below Python script which opens a Pygame window:

```python
import pygame

background_color: tuple[int, int, int] = (255, 255, 255)
width: int = 300
height: int = 200
window_title: str = "Window Test"

def main():
    screen = pygame.display.set_mode((width, height))
    pygame.display.set_caption(window_title)
    screen.fill(background_color)
    
    pygame.display.flip()

    keep_running: bool = True
    while keep_running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                keep_running = False


if __name__ == "__main__":
    main()
```

When the above script is run, the following window appears:

<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ii8vlzv2wev6a8cc0bfr.png" alt="Image of Pygame application window" loading="lazy" style="min-width:300px; max-width:600px;" />

<a id="further-reading"></a>

</br>

## Resources / Further Reading

<b> Text Editor </b>
* [VS Code](https://code.visualstudio.com/)
* [Atom](https://atom.io/)
* [PyCharm](https://www.jetbrains.com/pycharm/)
* [Sublime](https://www.sublimetext.com/)
* [VIM](https://www.vim.org/)
* [Visual Studio](https://visualstudio.microsoft.com/)

<b> Other </b>
* [Aseprite](https://www.aseprite.org/)
* [Pygame](https://www.pygame.org/news)
* [Tiled](https://www.mapeditor.org/)