Creating A Single Alien

Click here to load the completed tutorial directly into the editor SWARM-11.DBA. If you want to step through and make the modifications, click here to load SWARM-10.DBA.

Before we construct an entire armada of attacking aliens, we must start with the creation of a single unit.

Replace the line REM * HERE B * to read:
rem Make a single alien
make_single_alien( 1 )

You are now introduced to the world of user defined functions. User defined functions can be thought of as self-contained programs that perform a specific task.

You will find one such function at the end of the program called make_single_alien(). Unlike subroutines, functions can be given values to work with, and functions can also return a value. In this case, we are passing a value of 1 into the function.

Replace the line REM * HERE C * to read:
rem Make a decal object (flat object)
make object plain objid,25,20

Inside the user-defined function, we have added a command that will create a flat 3D object 25 units wide and 20 units high.

These types of 3D object are often referred to as decals. The variable OBJID stores the value passed into the function from the main program. You may recall we passed in a value of one, which means we are going to create a decal object using an object number of 1. Pressing F5 will demonstrate what a decal object looks like.

Replace the line REM * HERE A * to read:
rem Load images for alien
load image "bmp\alien1.bmp",7

As we have done previously, we shall load a bitmap file into memory and store as an image for later use. Our bog-eyed monster is stored in the file ALIEN1.BMP located in the BMP folder of our project.

Replace the line REM * HERE E * to read:
rem Texture the decal object with an alien image
texture object objid,7

Returning to our function declaration, adding this command will texture the decal object with the image of an alien. By pressing F5 now, we can see our alien replacing the blank rectangle we saw before.

Replace the line REM * HERE D * to read:
rem Make all black areas of the object see-through
set object objid,1,0,0

To complete the visual appearance of the alien, we can remove the rectangle of black that surrounds our alien by instructing DarkBASIC to make all black areas within the image transparent. Running the program after this modification reveals the removal of the telltale border.

Click Here For The Next Tutorial Creating Multiple Aliens.