Design Patterns and Video Games
0 FOLLOWERS
The purpose of this site is to present computer development solutions based on Design Patterns illustrated by the development of video games.
Design Patterns and Video Games
3y ago
In this post, I show a first application of the OpenGL Z-Buffer, which allows a scene rendering without the need to sort tiles.
Objective
To check that the implementation works fine, we want to hide the character behind the top of the trees:
Tiles sorting
The usual approach to get this result is to sort tiles at each time we render a frame. Then, we draw tiles from back to front.
Let’s take an example to illustrate this with three layers:
A background layer (ex: grass) always behind all others;
A middle layer (ex: trees);
A front layer with moving elements (ex: characters).
We render each ti ..read more
Design Patterns and Video Games
3y ago
In this post, I show how to animate water tiles using shaders. The approach I propose also works for all animations that repeat continuously in the same layer!
Objective
All water tiles we create on the map are animated:
Animation with shaders Sub tilesets
We use the type 3 water tiles created by Pipoya: https://pipoya.itch.io/pipoya-rpg-tileset-32×32. It is an 8-step animation, and for each step, we have tiles for every corner:
For instance, the top-left tile (water surrounded by land) has the following animation tiles: (0,0) (8,0) (16,0) (24,0) (32,0) (40,0) (48,0) (56,0). More general ..read more
Design Patterns and Video Games
3y ago
In this post, I show how to update shaders based on the current layer.
Objective
I choose the translation as the property to update for each layer or group of layers. The ground layer has a translation we can control with the arrows. Simultaneously, the translation of the front layers (frame box and text) remains unchanged. The rendering is fast (compared to a pure Python implementation) since the GPU performs most computations:
Design
First of all, we need allow properties per layer in the facade. I propose a solution with groups of layers where each group has specific properties like the tra ..read more
Design Patterns and Video Games
3y ago
Before I continue the facade, I want to create some game data to test it. As you may imagine, I use software design for that!
Objective
The expected result of this post is a simple level editor where we can draw ground tiles. It is enough to check that this first implementation is working fine:
Main approach Game state, game logic and UI
I propose to follow the following approach to design the game engine:
It has some similarities with Model-View-Controler (MVC) approach. As a model, we find the game state, which contains all data required to represent the game at a given time (or epoch ..read more
Design Patterns and Video Games
3y ago
In this post, I show how to display text into frame boxes. I also propose a solution to get more dynamism in the layer. For instance, it allows adding/removing faces in the mesh when the program is running.
Objective
The objective is quite simple: display a text in a frame box, for instance, when characters are speaking:
The main idea is to create a new layer class named UILayer that renders different decorations, starting with frame boxes. It is hard to predict the exact number of required faces/quads in the mesh for this kind of layer. As a result, I propose to update the current f ..read more
Design Patterns and Video Games
3y ago
In the previous program, we had to create one text layer for each text style (bold, shadowed…). In this post, I propose to render text with mixed styles from a single layer.
Objective
Using HTML-like source code, we want to render a text block with many styles. For instance, the following source:
<s size=80>Mixed text styles with <s color=#F08020>OpenGL</s></s>
This <b><s color=#0080F0>text</s></b> contains <u>several</u> <i><b>styles</b></i>
You can <shadow color=#8020F0><u>combine</u></s ..read more
Design Patterns and Video Games
3y ago
Before going to text with mixed styles, we need a better solution to render characters. In this post, I propose an approach based on the Composite pattern that allows an effortless combination of text styles.
Objective
Thanks to this new model, we can easily create new combinations of text styles:
Proposed approach Previous approach
With the previous approach, we handle the combination in a single method using branching:
if shadow:
if underline:
if outline:
else:
...
else:
...
else:
if underline:
if outline:
else:
...
else ..read more