Design Patterns and Video Games

The purpose of this blog is to present solutions based on Design Patterns illustrated by the development of video games.
0 comments
20 entries
Advertisement
phylyp
September 28, 2020
Discover Python and Patterns (11): Class

I propose to introduce Python classes to implement the Game Loop pattern. Using these tools, I show how to refactor the code in the previous post to get a more robust and readable program.

This post is part of the Discover Python and Patterns series

Create a class with Python

In this post, I introduce…

5,261 views
phylyp
July 14, 2020
Discover Python and Patterns (10): Keyboard

Thanks to the Pygame library we installed in the previous post, we can draw 2D graphics. In this post, I propose to introduce controls with the keyboard as well as some improvements like window centering and frame rate handling.

This post is part of the Discover Python and Patterns series

Keyboard ev…
3,183 views
phylyp
May 02, 2020
Discover Python and Patterns (9): Pygame

In the previous posts, I introduced enough of Python and patterns to start creating games with graphics using the Pygame library.

This post is part of the Discover Python and Patterns series

Install Pygame

Pygame is a popular library for creating 2D games. Like the random library we used before, the i…

4,987 views
phylyp
March 11, 2020
Discover Python and Patterns (8): Game Loop pattern

The time has come to see our first design pattern: the Game Loop Pattern! This pattern can give us many good ideas to refactor our game in a very effective way.

This post is part of the Discover Python and Patterns series

The Game Loop pattern

There is several version of the Game Loop pattern. Here I …

6,073 views
phylyp
February 26, 2020
Discover Python and Patterns (7): Functions

It is now time to organize/refactor our code! When you begin, this is a strange process since the final code does the same as before. However, refactoring is the only way to create a code easy to maintain and expand.

This post is part of the Discover Python and Patterns series

Define a function

In the…

3,378 views
phylyp
January 03, 2020
Discover Python and Patterns (6): Random

In the previous post, the magic number is always the same. I propose now to introduce random numbers to change the magic number every time we launch the game. I also present imports and more on integers.

This post is part of the Discover Python and Patterns series

Library import

In the previous progra…

2,762 views
phylyp
December 31, 2019
Discover Python and Patterns (5): Integers

In previous posts, I only used strings and booleans. In this one, I use a new data type called “int” (for integer) that allows the storage and computation of natural numbers (numbers without a decimal part). I use them to create the famous “guess the number” game!

This post is part of the Discover P…

2,181 views
phylyp
December 11, 2019
Discover Python and Patterns (4): Loops

The previous game only allows one try: you have to restart it to propose another word. In this post, I introduce loops, and I use them to repeat the game until the player finds the magic word.

This post is part of the Discover Python and Patterns series

While statement

The while statement allows to re…

2,735 views
phylyp
November 24, 2019
Discover Python and Patterns (3): Branching

Programs in the previous post always lead to the same result. Here, I show you the basics of branching, or how to change the flow of a program depending on cases.

If statement

If we want to display a message when the player types a specific word, we can use the following syntax:

word = input("Enter th…
2,500 views
phylyp
November 14, 2019
Discover Python and Patterns (2): Basic interaction

In the first post, we saw how to install an IDE and how to display a message; it is time to add some interaction with the player.

Wait for a key

Create a new python program and type the following line:

input("Press Enter to continue...")

If you run the program, you get the follo…

3,325 views
phylyp
November 07, 2019
Discover Python and Patterns (1): Start

In this series, I propose an introduction to programming for beginners. To do so, I choose the Python language, which is today one of the best (if not the best) language to discover programming. And, as you may guess, we’ll program games

Before starting anything we need a development environ…

2,450 views
phylyp
November 02, 2019
The paperback version of my book is out!

The paperback version of my book "Learn Design Patterns with Game Programming" is finally out!

The Kindle version is updated with some improvements and is still freely available if you subscribed to Kindle Unlimited.

1,901 views
phylyp
October 30, 2019
AWT GUI Facade (8): Keyboard and key sequences

In this post, I add the keyboard management to the facade, and I propose a way to detect key sequences. These sequences are used, for example, in games like Street Fighter II, where characters move according to specific key combos.

Keyboard facade

I first design the keyboard facade. As I…

3,481 views
phylyp
October 23, 2019
AWT GUI Facade (7): Draw text

Graphic libraries usually provide methods to draw text on the screen. These handy methods are often quite slow to run because they recompute many parameters at each call. To save computational time, the flyweight pattern can be used to provide text parameters with low memory and cpu usage.

F…
3,725 views
phylyp
October 16, 2019
AWT GUI Facade (6): Mouse and Game Loop

After loading a level, I now propose to add interaction with the use of a mouse. This will be an opportunity to see two other patterns: the Observer Pattern to handle mouse events, and the Game Loop Pattern for synchronization between controls, updates, and display.

This post is part of the…

4,236 views
phylyp
October 09, 2019
AWT GUI Facade (5): Load a level

In this article, I propose to use the Visitor Pattern to easily load a level. The GUI facade in the previous post is used to display the level. This pattern allows (among other things) to easily browse a data structure to extract information. In our case, it is an XML file created by “Tiled Map …

3,153 views
phylyp
October 03, 2019
AWT GUI Facade (4): Draw with tiles

I continue the extension of the graphic facade (see previous article), with here the addition of a very classic form of drawing for video games: tiles. These make it possible to compose an image using small images called tiles. There are several types of tiles, I propose in this article the simp…

3,216 views
phylyp
October 02, 2019
AWT GUI Facade (3): Display an image

The facade seen in the previous article has only an interface with its methods. It is also possible to enrich a facade with additional interfaces, connected to each other by various means. To illustrate it, I propose to add image management. This addition also makes it possible to present anothe…

4,192 views
phylyp
September 25, 2019
AWT GUI Facade (2): Draw

In this article, I propose to continue the design of a facade for a 2D tile game (previous post). I add two new features: creation/destruction of the window, and basic drawing. Each feature is managed by a batch of methods in a GUIFacade interface.

This post is part of the AWT GUI Facade ser…

3,437 views
phylyp
September 18, 2019
AWT GUI Facade (1): display a window

In this series, I propose to discover the Facade Pattern. In short, this pattern defines an interface that allows a reduced and simplified use of a set of features. To illustrate, we design a facade of the AWT graphic library for a 2D tile game.

This post is part of the AWT GUI Facade series…

4,473 views
Advertisement

Popular Blogs

shawnhar
Generalist
101 Entries
9 Followers
15 Entries
10 Followers
johnhattan
Programmer
1,277 Entries
47 Followers
ApochPiQ
Generalist
628 Entries
44 Followers
dgreen02
Generalist
338 Entries
56 Followers
Advertisement