Blitz2D Newbies: A Basic Action Game
by Phil

Introduction:

This describes the concept of an action game. The game world is grouped into:

  • Sprites
  • Sprite classes
  • Ground types
  • Events

Sprites are the living beings that move around on the screen or interact in some way with the player. These could be giant bees attacking.

Ground describes what the sprites walk on. This could be grass.

Events are raised by sprites during the course of the game. For example, if the player shoots, or leaves the screen, or a giant bee has found honey, an event is raised.

Sprites:

All sprites have some things in common. Those are the things you only have to code once. The player has to move around. So do the giant bees. They both have to be drawn on the screen. If the player shoots a bullet, this bullet is just another sprite. Sprites have various values attached which make for a basic sprite type.

Shape

The sprite shape is its width, height and image number.


Position

The position on the screen is defined by the x (left) and y (top) coordinates.


Speed

The speed will change the sprite position over time, so it's added to the x and y position values. If the speedX is positive, the sprite will move to the right.


Target position

The position the sprite tries to move to. Speed will be adjusted accordingly.

Speed step

The amount speed is adjusted at a single unit of game time. The higher this value, the faster sprites can adjust their speed.

Target speed

The target speed is the value the speed will try to adjust to. This makes for softer movement of sprites.

In every game time unit, target speed is adjusted:


Speed limit

The speed should never cross this. You can code a hunter sprite which will increase the speedX value if it's left of the player sprite, but it will stop to increase speed at a certain value.

Speed brake

The amount the speed will be reduced at each game time unit.

Ground

Stores the type of ground the sprite stands on.

Class

The basic type of sprite to be handled in class-specific functions.

Class morph energy

Sprites morph into other classes. For example, an attacked bee might morph into a hunter sprite for some seconds. The morph energy is reduced in every game time unit.

Old Class

This value will remember the old class: when the morph energy is reduced to zero, the old class will take over as the main class again.

There are many other values a sprite has to keep. It also needs to know if it's pushed (by whom and in what direction), at which height it moves (like ground, or near sky), if it needs to pause, if it has energy. There should be a counter to handle timing. An attribute "master" should store the class the sprite was generated by, for example if the player shoots a bullet, the master is the player-class. You also need to control animation by keeping track of the current frame. The attributes container, containable, collideable and contained tell about the sprite interacting capabilities/ interaction status.

Sprite classes:

A sprite class is a specific sprite. You cannot express the behavior of it in very general routines applicable to all sprites, so you will check the sprite-class and branch to specialized subroutines.


Ground types

Some basic ground types are: walkable, dangerous, water, barrier, ice...
These are your basic static tiles you read into your map array, using data describing terrain types and image/ animation details.

Events

An event is something which is not connected to sprites directly interacting. If the player steals an item, the item raises an event before it dies. A guard sprite might come to life--switch to class hunter--if it catches this event.
Or, you can navigate a couple of bees to track down the player after a single bee is attacked.

In Closing:

Phil donated this tutorial from his website, http://www.outer-court.com/basic/blitzbasic.htm. Please be sure to check out Phil's site for other great resources and information!


For a printable copy of this article, please click HERE.


This site is Copyright© 2000-2004, BlitzCoder. All rights reserved.