quinta-feira, 16 de fevereiro de 2023

Memory 5 of 10: Game programming

In early 1993, I was 14 when I started working part-time at my father's law office. I took my brother's place, as he moved to another city to prepare for the ITA and IME admission exams at the end of the year.

I was in charge of the office computer. My tasks consisted of typing texts, creating spreadsheets and managing the list of lawsuits. Sometimes I did some tasks outside the office, like sending letters at the post office or paying bills at the bank.

The office computer was a PC AT 286 with a monochrome monitor, DOS operating system and a 20 Megabytes HDD. It looked like the computer in this photo:


The SimCity game that belonged to my brother was installed on the computer. This is the SimCity game box:

After I completed all my office tasks, I used my free time to play SimCity. SimCity was a very interesting game due to the many actions available when managing a city. Sometimes I would print my city map to plan how I would expand it.

SimCity has a color version, but since my monitor was monochrome, my game version was like this:


Borland's Turbo C compiler was also installed on the computer. The C programming language is a general purpose language, but it was created with a focus on developing system programs, which are programs that interact with hardware. It provides several features for direct manipulation of computer memory, which is why it has become very popular in the software industry, mainly for game programming.

My brother had a Turbo C book that showed the fundamentals of programming using the C language. I started studying this book and the only thing I could think of was how to turn all those concepts into a game.


However, the book did not contain any material aimed at game programming and at this time there was no internet to search. It took a lot of experimentation to get to my goal. But I did, and so my first game called Raven was born:

The player controls a spaceship called Raven and needs to destroy the blocks that fall on the screen. The spaceship is represented on the screen by the letter "W". I chose this letter because it reminded me of a Star Wars ship.

The game with source code is available in this fileRaven.zip

Completing this game was very important to me. I already had the essential elements of code for a game that I could expand into other projects. A brave new world opened before me. I got excited and already had countless ideas for other games. I stopped playing SimCity and any spare time I had at the office I devoted to my game projects.

One of my next projects was to program a game that could be played by two people simultaneously. This project turned into the game "Mina". Each player controls a character and must pick up the item of their color that appears in random positions on the screen. There are 5 mines that are hidden in the game area and that change position periodically. 

Picking up an item earns 10 points and colliding with a mine explodes and loses 5 points. Whoever scores 100 points first wins the game. Player 1 uses the WASD keys to move and player 2 uses the arrow keys. In this game I even programmed the pause feature that is triggered by pressing the "P" key.


Mina game with source code is available in this archive: Mina.zip.

I'm going to comment on two curiosities about the Mina game. The first is that I managed to program a song for it. The PC had a simple speaker. There was a function on the Turbo C called "sound" which turns the speaker on at a certain frequency. I found a table with the frequencies corresponding to the musical notes. I converted all the musical notes of a song to the equivalent frequencies and controlled the time used by each note using an internal game counter that I created to synchronize events.

The other curiosity is in relation to the colors. In the game's C language code I defined the colors that the game objects would use. Each player was represented by a color. This color was used to draw each player's character, item, name and score. Player 1 was represented by the color green and player 2 by the color yellow. The rest of the game's elements used the color red. There was only one problem, my monitor was monochrome, it displayed colors as different shades of green. But I knew that one day the Mina game would run on a color monitor.

Another project I dedicated myself to was programming a RPG game. My RPG game is based on a story called "The Wishing Well":  


A description of the current room is displayed on the game screen and below it are displayed the various options for actions available for that room. The player can choose an option by pressing the equivalent key (1 to 5). A turn-based combat system has also been implemented that is used when an enemy is encountered.

The RPG with source code is available in this file: P_Desejo.zip.

In addition to these games, I programmed several other smaller projects, experimenting with ideas that popped into my head.

In early 1995, the office computer stopped working and was replaced by a PC 486 with a color monitor. With this more powerful PC, I directed my studies towards 3D game programming.

I found this book on virtual reality programming in the bookstore:

The book used REND386, which is a library of C language functions for 3D rendering. REND386 generated and manipulated a virtual world using three types of files: PLG, FIG and WLD.

  • PLG: It is a polygon file that contains the definitions of a 3D object. It is composed of three parts: object title, vertices and polygon descriptors.
  • FIG: It is a figure file that is used to group several PLG objects allowing the representation of a 3D entity with hierarchy among 3D objects, such as a person for example.
  • WLD: It is a world file that allows the definition of a 3D virtual environment. It has several commands for defining simple shapes in the world, specifying plane colors and allowing the inclusion of PLG and FIG files within the virtual environment.

This is an example of a 3D environment programmed with REND386:


Since the end of 1994 I wasn't playing any games. I missed out on PlayStation 1 and Nintendo 64 releases.

In early 1995 I started practicing martial arts on weekends with some friends: