Memory Lane – My first computer

I recently turned 50 and realized that I have been programming for over 35 years. There’s some interesting, funny, and stupid stories that pop into my head, so why not place some here. If there is some interest, I can post a few stories from time to time.

My First Computer

I was 15 years old in 1980. I visited a friend and he showed me a TRS-80 Model 1 that he had. We typed in a simple BASIC program from a book of games… it was something like “guess a number from 1 to 10”. We ran it, played a bit, and right then and there, I decided that I wanted to write software for a living.

It’s hard to describe how cool it actually was to “program” (ie: type code from a book) that computer for the first time. Of course, I had to get a computer for myself. I visited the local Radio Shack many times over the next few weeks, and decided I wanted the Model 3.

One weekend, my parents and I go over to the local Radio Shack and tell them we want to buy the Model 3 (looking back, that sucker was expensive.  It was $1599, that’s over $4500 today. Not sure how my parents were going to afford that, but they were very supportive and I guess they would “just find a way”). One of the store’s salespersons tells us that the computer salesman is not in today, but he will call us back on Monday. Bummer… guess I’ll wait until he calls.

He never does. I guess he never got my info, or didn’t really expect we would buy a computer, but in the meantime, I discovered the Atari 400, and we went out the next weekend and bought it. Thus begins my computer career. In hindsight, the Atari was a great choice over the Model 3. And a bit cheaper too, which I am sure my parents appreciated.

Easter Eggs

Easter just passed and that got me thinking about Easter Eggs of another type… those in software.

Back in the day, before the Internet ruled supreme, I did some development for the Worldgroup BBS platform. The Worldgroup client consisted of a Windows 3.11 front end that called different modules (email, chat, games), which connected to a server to allow communications with others.

I wrote a few clients and placed some small, and somewhat lame, Easter Eggs in them. To this day, over 20 years later, I believe none of these were found. I never heard anyone discuss them, no one contacted me about them, and the Internet took over and Worldgroup was put out to pasture.

Just prior to working on Worldgroup clients, I released a Windows version of my shareware music collection application “Songanizer”, which also contained a somewhat lame, but undiscovered, Easter Egg.

I like the idea of Easter Eggs and love discovering them, even though I rarely find them on my own. I have all the code for the Worldgroup and Songanizer applications on 3.5″ floppies. If there is any interest, maybe I will post some screen shots with details on how to see these Eggs.

I haven’t placed any Eggs in any of my mobile apps, but I am thinking of adding a few. Any good eggs in your games?

Object Pooling in Unity

In my previous post, I covered object pooling in CoronaSDK. This article will cover object pooling in Unity, using C#. While the concept of Object Pooling is the same no matter what language, there are obvious syntax and set-up differences, and we’ll cover those Unity specific things here.

I am going to demonstrate a very simple object pooling class to get you started. There are more robust solutions on the Internet and in the Unity Asset Store, and each solution is a bit different, but this is what I have been using and it demonstrates the concept as well.

Step 1 – Initial Set Up

To use this solution, you need a couple of things:

  1. A prefab object that you will use as the object to pool. For this example, we’ll just create a cube, and we’ll call it “EnemyPrefab”.
  2. An empty Game Object. For this example, let’s rename it to “EnemyPool”.

Once you have a prefab and an empty game object, create a new C# script called Pooler. Here is the code for this script:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Pooler : MonoBehaviour {
	
	public GameObject pooledObject;		// object to pool, drag into Inspector
	public int pooledAmount;			// number of objects, drag into Inspector
	public string objectName;			// name of object, enter into Inspector
	
	private List<GameObject> pooledObjects;
	
	/// <summary>
	/// Inits the object pool.  Renames the pool objects to the objectName
	/// </summary>
	void Awake () {
		pooledObjects = new List<GameObject>();
		for (int i = 0; i < pooledAmount; i++) {
			GameObject obj = (GameObject)Instantiate(pooledObject, Vector3.zero, Quaternion.identity);
			if (objectName != "") obj.name = objectName;
			obj.SetActive(false);
			pooledObjects.Add(obj);
		}
	}

	/// <summary>
	/// Gets the pooled object.
	/// </summary>
	/// <returns>The pooled object or null if all objects are used.</returns>
	public GameObject GetPooledObject() {
		for (int i = 0; i < pooledObjects.Count; i++) {
			if (!pooledObjects[i].activeInHierarchy) {
				return pooledObjects[i];
			}
		}
		
		return null;
	}
}
 Step 2: Pool your Prefab

Pooler PropertiesAttach the Pooler script to the empty game object, and look at the Inspector. You will notice 3 public properties:

  • Pooled Object – drag your prefab here. This is the object you want to pool.
  • Pooled Amount – enter the number of pooled prefabs you want.
  • Object Name – the name of the object. More on that later

Pooler HierarchyWhen your project is run, you will see a number of pooled objects in your Hierarchy view.

See line 20? I like to rename my objects when they are created, but this is up to you how to rename them, if at all. If you enter text in the Object Name property, the object is renamed.

Step 3: Use Objects in Pool

To get an object in the pool:

GameObject obj = GameObject.Find("EnemyPool").GetComponent<Pooler>().GetPooledObject();

or, to break it down:

GameObject gameObj = GameObject.Find("enemyPool");
Pooler enemyPool = gameObj.GetComponent<Pooler>();
GameObject pooledObject = enemyPool.GetPooledObject();

To return an object to the pool, inactivate it:

gameObj.SetActive(false);
That’s it!

There you have a very simple object pooler class. Of course you can expand on this class to do all sorts of things: update other properties, allow the class to grow if needed, etc.

Object Pooling in CoronaSDK

Creating and removing game objects is a very expensive operation. Couple that with enabling and removing physics properties on these objects during game play, and it is no wonder you will notice your game stuttering and lagging during these operations. As more objects are added to the screen, the situation gets worse.

The concept of Object Pooling is something that every new game developer needs to understand. With Object Pooling, you create a set of game objects and configure them as much as you can before the game starts, usually during scene load. During game play, you use and reuse these previously created objects.

Fortunately for Corona developers, creating an object pool is very easy. In this article, we’ll step through this to create a pool of reusable game objects. As an example, I will use one sprite from my game Space Mission: Survival, and I will show you how I create a pool of enemy ships.

Some things to note… for simplicity, I am going to create a pool of static images. In my games, I create my pools using sprite sheets, so I can animate these game objects, but that is outside the scope of this tutorial.

Step 0… Planning

You should determine how you want to pool your game objects. Personally, I like to pool my objects by type, and not mix them.  For example, Space Mission Survival contains an enemy pool and a bullet pool. By keeping them separate, you can manage them easier.  Further, my game contains a bullet pool for the player and a bullet pool that is shared by all enemies, even though the bullet sprite is identical.

Also note that since you are creating a pool of objects, memory will be allocated so try to determine the amount of objects you really need.  For example, if you know you need 50 enemies, create 50 objects, not one hundred.  The extra ones won’t be used, and they will consume memory. In cases where you are not really sure how many you need, you can create extra objects during times where there is little action going on (level starts, info screens, etc).

Step 1… Creation

So, what’s a pool in Corona?  It’s just a table of sprites. Let’s create a pool of enemies:

local maxEnemies = 50
local Enemies = {}

for i = 1, maxEnemies do
    Enemies[i] = display.newImage("enemy.png", 0, 0)
    Enemies[i].isVisible = false
    Enemies[i].isAlive = false

    -- if you need physics on these game objects
    physics.addBody(Enemies[i], "dynamic", params)
    Enemies[i].isBodyActive = false
end

The for loop creates and adds 50 enemies to a table named Enemies, and sets them invisible. Line 7 is a property I added which will keep track of live enemies (enemies currently on the screen).

If you need physics on these game objects, lines 10 and 11 set that up. Line 11 disables any physics checks on this object since it is not alive.

That’s it! This code takes care of the the processor intensive creation of objects that would otherwise slow your game down during game play.

You now have a table of game objects set up with physics, but they are not in the game.  How do you use them?

Step 2 – Use
-- return an available enemy, or nil if there is no enemies left
local function spawnEnemy()
    for i = 1, #Enemies do
        if not Enemies[i].isAlive then
            return Enemies[i]
        end
    end

    -- if we get here, there are no more available enemies in the pool
    return nil
end

-- upon death of enemy, back to the pool
local function killEnemy(enemy)
   enemy.isBodyActive = false
   enemy.isVisible = false
   enemy.isAlive = false
end

-- get enemy from the pool and activate it
local enemy = spawnEnemy()

if enemy ~= nil then
    enemy.x = 100
    enemy.y = 100
    enemy.isVisible = true
    enemy.isAlive = true
    enemy.isBodyActive = true
end

-- do a bunch of stuff in your game and kill enemy when appropriate
killEnemy(enemy)

In the above code, the spawnEnemy function will return a reference to an available enemy in the enemy pool, or nil if one is not available.  The killEnemy function will return the enemy back to the pool.

Step 3 – Clean Up

When done, don’t forget to clean up! Cycle through the pool to remove all event listeners and physics, and don’t forget to nil out the game objects.

Conclusion

Utilizing object pooling is a great way to keep your game responsive and allows you to mange objects by creating and using only what you need. Object reuse keeps your game from having to allocate and release memory by creating the same objects over and over.

This was a basic tutorial on how to get started with object pooling in CoronaSDK. Play around a bit… use sprite sheets to animate pooled objects, or change the sprite of an object. Create a dynamically growing pool in cases where you need more objects than you created. Or, create a generic pooler library to handle creation, deletion, spawning, and removal of all objects in your game.

My Development Shelf

I am sure I am not the only developer with a bunch of ideas, partially developed apps, or proof of concepts “on the shelf”.  For some reason I seem to have quite a few.

  • I recently played around with a few concepts that I could not roll into a game I wanted to develop.  One was a card game, another was some LiquidFun functions.  They are now on the shelf for a later day.
  • I have a game a started 4 or 5 times over the past 3 years.  I think I have the basic idea worked out, but I am still trying to figure out the finer points.  So, it’s been on the shelf for over a year without looking at it.  I really want to finish this one.
  • My recent project, the rewrite of Space Mission Survival, was recently put on the shelf.  I liked where I was in the development process, but decided a rewrite wasn’t going to be enough to get anyone to play the game on the PC or consoles.  It’s been on the shelf for about 2 weeks, but I recently dusted it off and it’s back as my project Du Jour.
Space Mission Survival Off The Shelf

My latest thought is that the rewrite of Space Mission Survival for consoles and PC will be a more high-intense, fast action game with power-ups, multiple enemy types, and multiplayer action.  This is a bit different than my original thought of developing a straight port, but I think its the way to go.  I still love the game play of the current Space Mission Survival, so I think I am going to add this “classic” mode to the new version.  Two… two… two games in one!

Since taking this project off the shelf, I yet again decided to start over (as I always seem to d0), but kept as much code as I could.  Lots of code was reused, but there were instances where new stuff I learned greatly improved ways to do things, thereby reducing code.  InvokeRepeating is awesome, and taking advantage of Mechanim for simple animations is another time saver.  Going to add some particle effects too!

We’ll See

I was planning on using CoronaSDK to develop a bunch of smaller mobile games this year.  I did release one game in January.  The Unity development of Space Mission Survival may impact the development of some Corona projects, but we’ll see.

One of the reasons why some of my apps go back on the shelf is that I am easily discouraged (due to limited feedback) and quick to change gears (finding something new, exciting, and challenging).  Right now I am into developing Space Mission Survival, but we’ll see.

Maybe I’ll pull one of the other things I mentioned off the shelf as well… we’ll see.

Announcing Space Mission: Survival

I have never released an announcement, video, or screen shot of any of my apps prior to release, but I am going to give it a try now.  I’m actually a bit nervous.

So without any further delay, here is a brief video of my upcoming game, Space Mission: Survival.

Space Mission: Survival is a retro space-themed arcade shooter.  In the game, you have 10 seconds of fuel per level to destroy the alien ships and save your astronauts.  The game is over when either all your ships are destroyed or all the astronauts are lost.

Game features:

  • Retro gameplay… you actually try to score points to get a high score!
  • Retro sounds
  • Arcade-like attract modes
  • Support for different languages
  • Achievements and Leaderboard support
  • Facebook and Twitter bragging

This game will be available soon… please check back for status updates.  Like us on Facebook or Twitter for status updates as well.

The History of Spell Them Out

Here’s a little story on how it took me almost 3 years to release my first game.

I wanted to write a game for years… YEARS!  Perhaps since the 1970s.  I tried a few times over the years and finally decided to dedicate myself to write the game I’ve had in my head for a while.  That game, Spell Them Out, was released in 2012 for various tablets and smartphones, but it took a couple of restarts to finally get it out.

Attempt 1 – Diamond Mine XNA

[photo title = ‘Diamond Mine – XNA Version’ align = ‘right’ size = ‘medium’]http://gamesbycandlelight.com/wp-content/uploads/2014/07/sto-xna.png[/photo]

Back in 2010 I decided to develop a game for Windows using Microsoft XNA Game Studio.  Using C# and the XNA library, I wrote Diamond Mine.  It took about a year to learn XNA and develop a working game.

I never released it.

I thought it was a pretty good game, but there wasn’t enough polish to expect someone to pay for it and play it.  I guess I am my own worst critic, so I kept the game unreleased.  At least I had some experience developing a game under my belt, so the year wasn’t a total waste.  I thought about going back and working on it a bit more, but then I shifted gears to mobile app development.

Second Attempt – Diamond Mine Java

[photo title = ‘Diamond Mine – Android’ align = ‘left’ size = ‘small’]http://gamesbycandlelight.com/wp-content/uploads/2014/07/sto-java.png[/photo]

I thought that Diamond Mine would make a pretty good mobile app, so I ditched XNA, installed Eclipse, Java, and the Android APIs and went to work on an Android version in late 2011.  I spent about 6 months working on it and I had something running, but I thought there had to be an easier way.  I wanted this game out on iOS devices as well, so the thought of rewriting/porting this in Objective-C after months of Java development was not something I was looking forward to.

Third Time’s the Charm

[photo title = ‘Spell Them Out’ align = ‘right’ size = ‘small’]http://gamesbycandlelight.com/wp-content/uploads/2013/12/sto-ipad.png[/photo]

[photo title = ‘Alpha-beta Asteroids’ align = ‘left’ size = ‘small’]http://gamesbycandlelight.com/wp-content/uploads/2013/12/aba-game-screen.png[/photo]

After a bit of web research, I found Corona SDK, which allows cross-mobile development using Lua.  A bit reluctant to learn a new language, I decided to try it, and I am glad I did.  I started fresh, renamed Diamond Mine to Spell Them Out, and published to the app stores in 3 months!

Shortly After Spell Them Out was published, I started working on a few other game concepts, but in the back of my mind, I knew I could improve the app, so I decided to write a sequel.  Alpha-beta Asteroids was released about 6 months later with improved graphics and game play, as well as an improvement in my Lua coding skills.

Back In The Day – Inflation Calculator

Background

Back In The Day is a quick little app I put together to solve a problem I found interesting.  I am currently reading a book that stated $300,000 was used in 1923 to build a large structure on a site.  Sounds like a lot, but I wondered what $300,000 is worth today?  Knowing that, I could understanding the scope of the project.  After a bit of research, I put together an app that will allow you to see what the value of money is between two years that you select.

Since this is a utility and not a game, I also decided to make it a little more fun by adding the old codger on the About screen.  Tap on the old man icon and see some words of wisdom.

An Experiment

When I published this app, I decided to support it in the following manner:

  • The app is free to use.
  • Any bugs I find, I will fix.
  • Enhancements will be added, provided there is support of this app from the user community.  If you like the app and wish to support it, please click on an ad, visit my web site or blog site, check out my Facebook or Twitter page, download one of my games, or rate the app on the app store.  Believe me, this goes a long way!  I appreciate hearing from people using my apps and it motivates me in making them better.

That’s all there is to it.  I will continue to enhance this app as long as there is an interest in using it.  Adding features takes time away from my other projects, and while I do not mind updating this app, there has to be a request to justify additional features.  Send me an email or a Tweet!

 Conclusion

I hope you find this app useful, and I look forward to hearing from you.  Thanks for taking the time to read this post and for checking out Back In The Day!  I also plan on writing a more technical article on the development of Back In The Day for those who are interested.

Oh, and $300,000 in 1923 is over $4,000,000 today!

Old File Formats

Recently, I was looking through some cabinets and drawers which contained a lot of old computer equipment, and I found what is basically my entire 35 years of development work.  With the exception of one program I wrote back in 1981, I have source code of every program I have written.  Text dumps of mainframe code, 5.25 and 3.5 floppy disks for various computer systems popular at the time, CDs, DVDs… all there for me to look at, get nostalgic over, and realize I’ve been around the programming game for awhile.

DiskCollection

Why would I keep all of these source files and print-outs?  I’m not really sure, other than I guess it is my body of work, and I need to save it.

So now I have the task of moving all of these files to a single, modern source, and that format is DVD.  Some are easier to move than others.

Anything current (of course) can easily be moved, since that was already on DVD or CD.  This includes my mobile app development, as well as anything in the past 10 or so years.

I was also lucky enough to copy a bunch of diskettes from my days as a “real job” programmer.  I had source files on 3.5 diskettes and moved them to CD years ago, and now I moved the CD files to DVD.

A few items remain, and I am trying to get these files to my PC so I can burn them on a CD or DVD. In my collection of code that I need to copy:

  • My 3.5 diskettes that I recently found.  My current computer no longer has a floppy drive, so I guess I can buy a USB 3.5 drive for about $20 and copy them over.
  • My 5.25 PC diskettes.  I cannot seem to find a USB 5.25 drive, so I am unsure how to copy these files over.  I guess I would need to find a PC that has a 5.25″ drive, as well as either a CD burner or USB port.  No easy task.
  • 5.25 Atari 8-bit diskettes. I do have an Atari 800 here, and I can read the files on the Atari, but I want them moved to my PC.  I’m not even sure if these things will be readable… they are close to 30 years old.  How do I move these source files?  Modem?  USB?  Print, then OCR?  Either way, I need some more hardware.
  • 3.5 Atari ST diskettes.  Same issue… I have an Atari ST, but need to get them over to my PC.

As I mentioned earlier, the only code I no longer have was an early attempt to write a game for the Atari Program Exchange (APX) back in the early 1980s.  That was stored on cassette tape and I am sure I no longer have it.  Looking back now, it was awful, so it is no surprise it was rejected, but I still wish I had the source, as well as the rejection letter.

I would be interested in any ideas to move the older diskettes to my PC… I would love to see some of the code I wrote way back when.