Ozapell Basic Learn Programming #11

Sometimes you will need to add delays in your program.

Let’s assume you wrote a program in Ozapell Basic to draw a white pixel on a black screen in graphics mode:

BACKCOLOR=COLORBLACK
MODE=1
SETMODE
TEXTCOLOR=COLORWHITE
X=10
Y=10
COLORXY

You run the program and nothing happens. The program executed properly and drew its pixel, but then it returned to text mode when the program ended.

This could also be a problem if a wave audio sound was loaded, played and the program ended. The sound would stop immediately and it might seem as though the sound wasn’t playing correctly.

Here are some delays you can add to the end of your program:

REPEAT
UNTIL FALSE

This will create an infinite loop. Only pressing the ESC key will end the program.

REPEAT
INPUT
UNTIL RESULT

This will loop until a key is pressed. INPUT will return a string character in RESULT. If it is an empty string (length of zero), the loop will continue. If a key is pressed (associated with a string character), then the loop will end.

TIME
OLDTIME=RESULT
REPEAT
TIME
RESULT-OLDTIME
RESULT>1000
UNTIL RESULT

This will loop for 1000 milliseconds (one second).

Ozapell Basic on Steam

 

Advertisements
Ozapell Basic Learn Programming #11

Ozapell Basic Learn Programming #10

Sprite Collision Detection is easy with Ozapell Basic!

Switch to graphics mode:

MODE=1
SETMODE

Assuming a bitmap image file called BITMAP.BMP is in the Documents -> Ozapell Basic folder:

BITMAP=0
ARRAY=BITMAP
FILENAME=”BITMAP”
BITMAPLOAD
BITMAPWIDTH=WIDTH

The array BITMAP now contains all of the pixels for the image loaded. RESULT will return the number of entries (pixels) in the array. WIDTH will contain the width in pixels for the image.

ARRAY=BITMAP
WIDTH=BITMAPWIDTH
X=0
Y=0
ARRAYDRAW

This will draw the image in BITMAP at the upper, leftmost corner of the screen (0,0).

ARRAY=BITMAP
WIDTH=BITMAPWIDTH
X=0
Y=0
OWNER=100
ARRAYDRAWOWNER

Draws the image in BITMAP at 0,0 plus every pixel drawn is associated with the value in OWNER. (Pixels given the a negative value are transparent and will not be associated with an owner value.)

ARRAY=BITMAP
WIDTH=BITMAPWIDTH
X=0
Y=0
ARRAYDRAWCOLLIDE

RESULT will contain the highest owner value associated with any pixel that would be drawn over if ARRAYDRAW was used instead of ARRAYDRAWCOLLIDE. This value can be used to determine collisions such as walls, enemies and bonuses.

OWNER=100
OWNERCLEAR

All pixels (and owner data) with the owner value given in OWNER will be cleared from the screen.

Ozapell Basic on Steam

Ozapell Basic Learn Programming #10

Ozapell Basic Learn Programming #9

The latest version of Ozapell Basic adds support for wave audio.

Assuming there is a valid audio file called AUDIO.WAV in the Documents -> Ozapell Basic folder, then the following code will load it:

FILENAME=”AUDIO”
AUDIOARRAY=0
ARRAY=AUDIOARRAY
WAVEFILELOAD

Now the array AUDIOARRAY contains the audio data. This data can be analyzed or manipulated. RESULT will contain the number of entries (samples) in the array.

Currently, the only wave audio format supported is Uncompressed PCM format, 16 bits per sample (CD quality), 44,100 samples per second (CD quality) and 1 channel (mono).

To copy the audio data from an array to a sound buffer:

ARRAY=AUDIOARRAY
BUFFER=0
WAVEFILEBUFFER

There are 32 sound buffers (0 to 31).

Audio data under 15 seconds in length will be considered a sound effect. 16 sound buffers will be created for these sound effects to allow for up to 16 simultaneous plays of the same sound.

Audio data over 15 seconds in length (with a current maximum of 5 minutes) will only be provided one sound buffer. Only one instance of this sound can be played from this buffer at one time. Playing the sound while it is already playing will cause it stop and start over from the beginning.

To play a sound:

BUFFER=0
WAVEFILEPLAY

To loop a sound:

BUFFER=0
WAVEFILELOOP

To stop all sound buffers for a specific sound:

BUFFER=0
WAVEFILESTOP

Ozapell Basic on Steam

 

Ozapell Basic Learn Programming #9