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.
sprite\image = LoadImage("file/my_sprite.bmp")
sprite\width = 32
sprite\height = 32
Position
The position on the screen is defined by the x (left) and y (top) coordinates.
; position the sprite in the middle of
; of the screen
sprite\x = SCREEN_WIDTH / 2
sprite\y = SCREEN_HEIGHT / 2
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.
sprite\x = sprite\x + sprite\speedX
sprite\y = sprite\y + sprite\speedY
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:
const SPEED_ADJUST# = .01
if sprite\speedX < sprite\targetSpeedX
sprite\speedX = sprite\speedX + SPEED_ADJUST#
endIf
if sprite\speedX > sprite\targetSpeedX
sprite\speedX = sprite\speedX - SPEED_ADJUST#
endIf
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.
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.
select sprite\class
case CLASS_PLAYER
adjustSpeedToKeyboard sprite
case CLASS_HUNTER
followPlayerPosition playerSprite, sprite
case CLASS_SLIDER_ONCE
dieOutsideScreen sprite
case CLASS_SLIDER_BOUNCE
bounceAtScreenBorder sprite
end select
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.