class base_image
The base_image
class is the core behind all sprite-types introduced in GALVADERS.
Once you grasp how to work with this class, you know the concept of how GALVADERS is built.
How to work with this class:
First construct
a base_image
object with:
RLE_SPRITE **dt This is RLE_SPRITE * vector (see create_game_params()
about how create this vector from Allegro DATAFILE).
This pointer should be valid at all time.
BITMAP *dst This is the dest-BITMAP where you want to write sprite-output.
This should be your back-ground buffer.
pos_x,pos_y The sprite location on dest-BITMAP.
z_order This is the Z-Order value for the sprite. Some games don't use this.
sprite_index This is the index of the sprite-image. Thus, dt[sprite_index] gives the sprite address.
bg_flag When this flag is set, the base_image
object retains sprite's background when removing it from dest-BITMAP. When clear, a black rectangle is drawn.
Once constructed a base_image
object the way of work is simple,
just issue a remove()
, action()
and draw()
for each and every frame.
base_image::remove()
removes RLE_SPRITE from dest-BITMAP.
draw()
write RLE_SPRITE to dest-BITMAP.
The virtual method action()
does nothing
, once you derive your own sprite-class from base_image
add all the game-logic code for your object in the action()
method.
Thus, having all kinds of objects derived from base_image
construct an STL-list or vector of base_image *
, and for each an every frame the remove()
, action()
and
draw()
are committed.
Since action()
is virtual, the right action-method would be called for each object type.
Do a reverse-scan of the list when doing the remove()
section, and forward-scan for
action()
and draw()
This keep your dest-BITMAP clean from trails of moving objects.
Take a look at base_image.h
for available base_Image methods. I think all of them are straight forward.
Read the code in base_image.cpp
for better understanding, it's simple.
To make things easy, this page will be updated later.
There is another base_image class, not used in GALVADERS, that works directly with Allegro DATAFILE array. This one does not require RLE_SPRITE vector-pointer, but a DATAFILE pointer instead. The DATAFILE pointer should be valid all time.