Graphic+Sound

Chapter 2: GRAPHICS

General:

DiNGS uses 3 screen pages. Let’s take a look at these:

1. Primary Surface
This is what you see on the screen.

2. Back Buffer
This is what all graphic commands in DiNGS write to. It’s invisible. When you call the command SHOWSCREEN the current back buffer becomes the primary surface. Later in detail, but remember: If you don’t see a thing you kight have forgotten SHOWSCREEN.

3. Offscreen Surface
This screen can be accessed with 3 commands only: BMPLOAD, BLACKSCREEN and USEASBMP.
BMPLOAD loads a BMP-file to the offscreen surface.
BLACKSCREEN ‘loads’ a black surface to the offscreen surface.
USEASBMP copies the current back buffer with all sprites drawn to the offscreen surface.

When SHOWSCREEN is called, back buffer and primary surface swap. The now unuseable back buffer will be replaced (cleaned) with the offscreen surface which is black when no bitmap is loaded.

A game mostly is structured like this:

// My game
start:
BMPLOAD "Background.bmp";
// Load further graphics as sprites...
// load level, setup (lives=3, time=100...)
maingame:
//Keyboard input
//Move and draw player
//Move and draw enemies
SHOWSCREEN;
GOTO maingame;

SPRITES:

If you know about computers you might know the truth. The PC doesn’t have real sprites. The good news: DiNGS pretends to have sprites. With all comfort. Next, what is a sprite? No, not a refreshing drink. Sprites are smal graphics that can perform effects that would otherwise have to be programmed with hard work.
For a better understanding we take an example. The game ‘Super Mariou Bros.’ or so... The hero, the enemies as well as bullets and flags are sprites. They have a so called cookie cut. The area next to the object can be seen. Without cookie cut there would be a black solid frame around each object. But how does the program know which parts of the sprite are to be displayed transparent? There would be a lot of ways. DiNGS uses the following: Every pixel of an image loaded for a sprite thet has the color value red:255, green:0 and blue:128 (Hex: FF 00 80) (
Pink) is transparent.

Attention:

All graphic files loaded are in the Windows-Bitmap format, uncompressed. You cannot load 256-color graphics. You have to reload and save them as 24Bit color images.

Your first sprite:

////////////////
// SPRITES
////////////////
// My_Sprite.src
////////////////

// load SPRITE from file “Bubble.bmp” and assign it to ID 0
LOADSPRITE "Bubble.bmp" ,0

// show SPRITE with ID 0 at position x=300, y=150
SPRITE 0, 300, 150, 0
SHOWSCREEN
END

As you can see with 3 commands you made a visible result. The code bejond this is several pages long. And this is your advantage to all the other coders of languages like C++, ASM or Pascal...
The command LOADSPRITE is selfexplaining. It loads a BMP file which can be used with the SPRITE commands and assigns it an ID (here 0).
Take a look at the bmp-file. You’ll see there’s pink color around the image. This will be the transparent pixes. To see this, we’d better load an image for the background by adding

BMPLOAD "back.bmp";

to the beggining of the program.

The command SPRITE need 4 parameters. The frist is the ID of the sprite to be shown. 2 and 3 are the screen position of th sprite to be shown. The last value is an alpha value in %. Right. DiNGS supports alpha blending. Never heared? No problem.

AlphaBlending is, when 2 images (namly the background and the sprite) are melted together. DiNGS knows 2 possibilities for doing this.

1. ADDITIVE ALPHABLENDING

a value from 1(%) and 100(%) mixes the 2 colour values of each pixel by adding the red, green and blue values and watch it not to be more than 255(FF). Sounds complicated, but all work is done by DiNGS. A value more than +1 is for effects like fire, explosions and glass screens.

2. INTERPOLATED ALPHABLENDING

a value from -1(%) to -100(%) melts the 2 objects by adding both values and divide them by 2. You can use this for shaddows and other nice effects. Try it.

A tip: take some time and test some geomertic shapes of different colors on a coloured background with both alpha modes. Even black and white background can get a great look with coloured sprites.

SPRITE SPECIAL FUNCTION

Zooming a sprite to any size can be done with:
ZOOMSPRITE spriteid, xstart, ystart, xend, yend, alpha;
Rotating a sprite around it’s center can be done with the following:
ROTOSPRITE spriteid, x, y, angle, alpha;
X and Y valueas are the positions of the sprite when not rotated. So the following code:
ROTOSPRITE 1,50,70, 0, 0;
is identically to:
SPRITE 1,50,70,0;
Both combined:
ROTOZOOMSPRITE spriteid, x, y, angle, size%, alpha;

size% is a value that specifies the scaling of the sprite. 50 is half the size. 200 double size.

GRAPHIK SPECIAL FUNCTION:

As a special goodie DiNGS offers you a command to fade from the current back buffer into a BMP-file. Fading to a black bitmap the screen will fade-out.

BLENDSCREEN bmpdatei$;

And even better: DiNGS can play videos in all known video codecs. (AVI, MP2...) Very easy with:

PLAYMOVIE filename$;

Only drawback: DiNGS uses an external module for video playback. You have to copy this module when redistributing your game.

TEST:

So. That’s enough for today. Write a program that loads 2 sprites and does the following: Move a sprite fromleft to right, then rotate with ROTOSPRITE once, then use ROTOZOOMSPRITE to rotate the sprite onece and zoom it to screen size meanwhile. Now the program should load an image and do the same again with alpha value of -100 for sprite 1, and 100 for sprite 2.

You’ll find graphics and a smal project for this task in the projects folder.

 

Chapter 3: SOUND

This will be a quite short chapter. You handle sounds as you do with sprites. There are 3 commands for sound playback.


LOADSOUND

This loads a sound to memory, assigning an ID. Just like LOADSPRITE. The only supported format is wav-PCM

PLAYSOUND

This plays a loaded sound. The command requests 2 arguments.
1st is the ID of the sound loaded
2nd is the stereo-fading in %. -100 means left, 0 = center and +100 is right side.

HUSH

This command immediately stops all sound playback

You can play more sounds simultanously. The sound device will mix them on the fly.