Archive for Game Library

Building a Foundation For Your Games and Handling Screens

This article is part 1 of a series: The Structure of a Game. Read the Introduction here.

Building Foundation

What does a game foundation consist of?

The starting point for any well built structure is a strong foundation. It is important that the foundation of your game is able to handle the basic functionality that will apply across all of your games, and does it simply with little to no extra effort on your part.

Also, what do all games have in common? They consist of various screens (Oh yes they do, or your game would be considered a tech demo my friend). With that in mind, our structure should be able to handle the following:

  • Context Menu Setup
  • Access to the Stage.
  • Tweaking of game speed
  • Frame Rate Tracking
  • Sending updates to your game
  • Custom Game Cursor ( if applicable to your game )
  • Global game pause
  • Ability to step through code 1 update at a time
  • Screen switching

In order to implement all of these in a manner that we can easily and quickly transfer over to each and every project and use without any real need of changing the code at all we will create our structure using the following 3 classes:

  • IScreenItem - Anything that will be considered a screen, such as MenuScreen, GameScreen, etc...
  • AScreen - An Abstract class which handles screen switching.
  • Root - Our meat and potatoes of the foundation. Handles the "Basic" functionality discussed above.

Lets build it!

A few concepts for me to mention now before we start are that almost all of our game objects will use an update and dispose method. Updates will filter down from the Root class so as to keep greater control of the game and eliminate the inconvenience and speed hog of creating multiple frame event listeners to the stage. Also it is good practice to clean up your code on removal such as removing any event listeners and nulling any outside references.

Also we will be using a constant time step to update our code. It is quite simple to interchange actually which I can show you, but in my experience a non-constant time step can cause inconsistencies that are difficult to debug.

When I refer to "Global Game Pause" this means that all updates to the game objects and rendering. You may have seperate pause logic within your game screen that pauses only certain features, still allowing menus or other GUI to run.

The IScreenItem and AScreen Classes

Okay, so let's begin with the IScreenItem class. This will be the interface for any screen used in the game... Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...

The Structure of a Game - Introduction

Inspiration

When I first began programming, it seemed like there were a vast amount of tutorials out there which taught you how to do a specific task such as "make a shooting game" or something of that nature. These were great for me at first, as I didn't know my left toe from my right thumb. Eventually however, I began to get better and I craved more organized and useful information such as how to actually structure games, and how to use proper OOP techniques etc. There simply just isn't enough of it out there. I found a few articles explaining several ideas and concepts, and I read many different books on OOP and design patterns…then after about a year of working together the different I came up with a great mesh of it all to develop my current game structure.

Purpose

My purpose for this article and those that follow in this series is to teach you piece by piece how to build a reusable game structure for your games as well as explain different game coding techniques and concepts along the way. I'll be providing code that I've written, however for maximum benefit I recommend that you modify or rewrite it to your style and needs. For example, each time I start a new project I simply copy all of my game code over from my latest game and then delete classes which I won't need, as well as tweak existing code to fit the current project.

Requirements

It is good practice to write down some goals and requirements for what you would like your game engine to incorporate, so let's consider this now. Our game structure will have consist of the following:

  • The ability to save game state, pause, speed up and slow down
  • We can set a camera position and size to render what is in the game world.
  • The game logic will be separate from the rendering logic.
  • Data driven development. IE: Creatures and levels will be built outside of the core code engine itself, usually from XML or on a higher level in an editor of some sorts.
  • Object creation is centered in one location
  • Control of entities is done through "controller" classes.
  • And of course...it will run incredibly fast.

If any of that sounded complicated, fear not. I will be discussing the reasons for each part as well as explaining how it all works. We will create one piece at a time and build upon the structure as we move along, making improvements along the way.

As I complete each section I will update this article to link to each piece. You may visit the google project page to aquire all of the project files and source code as well.

Additional Articles in this series:

  • Building a Foundation For Your Games and Handling Screens
  • Entity Class - Just what is an entity? ( Coming soon )
  • Seperating Game Logic from Rendering Logic
  • Setting up AI
  • Game Object Management
  • The Game Factory - How You Should REALLY be creating objects
  • Data Driven Development
  • And more...

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...

Actionscript 3 Math Classes for Game Developers

As I have been teaching myself game programming, one of the harder parts has been the math involved. It can be quite complex depending on what you are trying to do. While building various parts for my game engine I've needed several math functions. I've read through a couple of game and math books and have also created quite a few extras just based on what I had learned. I have created a pretty good library of useful functions and so after showing a friend of mine and him remarking that it was quite helpful I decided I would go ahead and release the code for everyone else to use!

I currently don't really have any demos or anything showing how to use the code, however go ahead and take a browse through the functions and there may be some stuff you will use eventually. It's pretty self explanatory anyways and it is all documented. I will definitely be referring to a lot of the code from these classes in some upcoming posts as well so if you are waiting for a more detailed explanation of when and how to use some of it don't worry it's on the way!

You can download everything as a package or just get the classes you need in the repository from my google project page here: http://code.google.com/p/cheezeworld/

As of writing this I currently have:

Vector - Perfect alternative to using the built in "Point" class and has basically ALL of the Vector operations you would need to perform plus a few more.

AABBox - A very lightweight object to simply store "rect" data for whatever purpose.

Matrix2D - Handles any Matrix math needed. Use in conjunction with the Vector class.

Transformations - Some static functions for performing transformations to Vectors easily (such as local to global etc...)

Geometry - A very powerful bunch of static functions for doing a wide range of math such as line intersection tests between rays, segments, polygons, circles, etc etc... This is great for most hit test operations and ray casting + other stuff...just check it out.

Math Utils - This is pretty much just a small number of things that I actually just usually copy directly into the code I am working on or as a private function into a class that needs it but wanted to have a reference to it since they are useful so it's all bundled up in this class.

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5 out of 5)
Loading ... Loading ...

Google Code Sharing Project Created

Now that I will soon be releasing much more code and files I decided to go ahead and set up a google project page. You can set up a "read-only" repository to download all of my code as it is updated and added to or download the code as I post it in the packages with the demos / tutorials.

Check it out here: http://code.google.com/p/cheezeworld/

If you would like to contribute some code or a helpful tutorial etc I'd be happy to add it to the project!

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Animated Bitmap Class. This Will Speed up your games!

It took me a bit longer than I thought, but it is done! I have created a custom "BitmapClip" class for you guys! This class can do it all:

  1. Import MovieClip, Sprite, and even Tile sheets!
  2. Animate each clip at it's own frame rate.
  3. Control it just like you would a MovieClip.
  4. It even creates pre-rotated frames for you! Now you can have super fast animated clips AND support rotation! WOOT.
  5. You can also support scaling by simply adding the clip to a sprite without losing *much* speed.

If you want to see a demo where I am using the BitmapClip with thousands of clips on screen moving / scaling and rotating then go here: Game Framework Test

You can download the package containing all of the code and demos or simply grab the file off of the repository on my Google project page.

The following are instructions on how to use it (which are included in the download as well):
Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 5 out of 5)
Loading ... Loading ...

Simple and Easy to Use Custom Input Manager Class

Sweet! It's ready to go. I have created a custom Input Manager for you to take advantage of. Check out this quick video tutorial that will walk you through how to use it in your projects or feel free to look it over yourself.

You can download the package containing the demos and the files or just grab it directly from the repository on my Google Project Page.

Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5 out of 5)
Loading ... Loading ...