Welcome to Game Experiments!

Want to learn Go or Odin? Want to write a game or a cross platform app? Over even a headless app? We plan on trying various things here.

Make a Tetris game using Go and Raylib

Tetris using Go and raylib

Difficulty - easy to medium - assumes basic knowledge of Go

We will end up with a game like this with sound effects and music. I chose this to kick off with as we do not use any images but create our images in the code.

I suggest you use VS-Code, but notepad will work just fine too. Git is recommended.

if using VS-Code install this plugin

Start Using Git

Start Using Git

Introduction to Git

As a Go developer, you’ll eventually need to manage your code effectively, and that’s where Git comes in. Git is a powerful version control system that can help you track changes, collaborate with others, and manage code for your Go projects seamlessly. In this post, we’ll cover the essentials of installing and using Git on your own Go projects.

Installing Git

Before you can start using Git with your Go projects, you need to have it installed on your machine. The installation process varies depending on your operating system.

Getting Started: Installing Go and Raylib-Go on Windows

Go

Introduction

Are you ready to dip your toes into the world of game development using Go? If you’re a Windows user looking to get started with Raylib-Go, you’re in the right place! In this guide, we’ll walk you through how to properly install Go and the Raylib-Go library, making your game development journey a smooth one.

Steps 1, 2, and 3 are to be done once.
Step 4 is to be done (almost) every time you start a project.

Step 1: Install Go

The first step is to install Go, the programming language that powers Raylib-Go. Head over to the official Go website at golang.org/dl and download the Windows installer that suits your system architecture (either 64-bit or 32-bit).

Screen wrap & Detect edges

Wrap and follow

We finish up this mini series with this post. The basic game will be functional with these last two changes in the game. I don’t want to get into game design or polishing up this ‘demo’ to turn it into a full fun game. That I will let you try using examples from elsewhere.

Choices

In earlier experimenting I had the tail following the head but when I added the screen-wrap it broke.

Grid Movement

There is a few different ways to do this and each way gives you slightly different results.

I wanted a method that would detect when I crossed the center of a tile or landed on it.

I came up with this for going left - I could have started with right, up, or down I guess.

This is debug code and simply prints out position and if center was crossed. If you tried this you’d likely come up with a different solution.

Worm eats food

Food

The food will be placed in a random position initially. When the worm head passes over it we simulate eating and placing new food by simply placing the food at a new position using random.

It is cheaper on resource space than destroying and re-creating the object as a new object.

import random

Change the way “GameObject” places itself.

def __init__(self, img_name, initial_pos):
    self.img = pygame.image.load(img_name)
    self.img = pygame.transform.scale_by(self.img, 0.5 )
    self.rect = self.img.get_rect()
    self.set_pos(initial_pos)

def set_pos(self, pos):
    self.rect.center = pos

Create a food object that repositions not moves. We set it off-screen to start.

Creating and Moving our player

Artwork

  • first get some images for our worm and food

Head over to Kenney’s shape characters package and get the following images to follow along. The files we want are in the png/default folder. The larger images in that folder are 80x80. If you are adventurous try other images.

I’m going to use individual 2D PNG files for each item to start. Note I change all file names to lowercase as that works with Linux, Mac, and Windows.

Add grid lines and Kinematic objects

CODE can be found at my Git Repository

Add background with lines

We want a grid, but we don’t want to draw the lines every frame. We will create a white background with lines on it using code.

#colors
white = (255,255,255)
black = (0,0,0)

#clear the display
screen.fill(white)

# Create a background
background = pygame.Surface.copy(screen)

#draw lines for the grid on the background
for y in range(0, height, 40):
    pygame.draw.line(background, black, (0,y), (width,y))
for x in range(0, width,  40):
    pygame.draw.line(background, black, (x,0), (x,height))

# blit the background to screen
screen.blit(background,(0,0))

We replace the

Basic Pygame game structure

Prerequisites

Look at the previous posts

We use python and Pygame, and this tutorial focuses mostly on using Pygame.

The game should look like this when done

Encouragement: Don’t let Others discourage you. We all hear it. If you listen you will never achieve your goal.

Repository

Github and BitBucket both provide instructions

Create a empty repository online and then follows the instructions given by GitHub to create locally and set remote to your empty GitHub repository.

Basic Movement

Basic Kinematic Animation - Movement first

2D frame based animation (2D kinematic animation) is easier to explain so we will start there.

2D kinematic animation is controlling the movement of an object without physics involved. We simply move in a direction at set intervals. To keep the speed of the motion same on different size screens we need to take time into account. We will make use of the number Frames per second or more accurately the time difference between each frame (delta time) included in our distance calculation. Don’t worry its quite simple. We ‘animate’ our character by swapping the image with another image every few frames or fraction of a second.

Getting Started with Pygame

This tutorial is for the beginner, the ‘PyGame Worm’ lessons are intermediate at a rough guess. IDK, those terms were never well defined when I started programming.

We dont teach the absolute basics of python here. You need to have a very basic understanding before you start these tutorials else you will be lost.

The style used here is code as we need, not the best method but a good way to try things out if you keep your changes small. We don’t use tests as that will distract from the lesson, but that will be taught soon.

Free Books etc

Intro

Some tools and computer languages included here.

Most programming languages can just be read like you would read English. You will still trip up in places, but most of it should be human-readable.

Computer languages change, but the basics usually stay much the same. You can always use the references, lookup newer features, and view best practices as they change.

free resources

EbookFoundation ~ other spoken language books here