Blitz BASIC

From Bauman National Library
This page was last modified on 8 June 2016, at 21:57.
BlitzBasic
BlitzBasicLogo.gif
Developer Blitz Research Ltd.
Implementation language Compiled to C++, but the languages are dialects of BASIC
Platform Crossplatform
OS IDE for Microsoft Windows, Mac OS X, Linux
License zlib license
Website www.blitzbasic.com

Blitz BASIC refers to the programming language dialect that was interpreted by the first [Blitz]] compilers, devised by New Zealand-based developer Mark Sibly. Being derived from BASIC, Blitz syntax was designed to be easy to pick up for beginners first learning to program. The languages are game-programming oriented but are often found general-purpose enough to be used for most types of application. The Blitz language evolved as new products were released, with recent incarnations offering support for more advanced programming techniques such as object-orientation and multi-threading. This led to the languages losing their BASIC moniker in later years.

History

The first iteration of the Blitz language was created for the Amiga platform and published by the Australian firm Memory and Storage Technology[1]. Returning to New Zealand, Blitz2 was published several years later by Acid Software (a local Amiga game publisher)[1]. Since then, Blitz compilers have been released on several platforms[1].

Versions

During its existence, Blitz Basic has undergone many changes and rebirth. It currently supports three main forms of the language Blitz Basic:

BlitzMax

BlitzMax is a BASIC dialect, and the latest Blitz language by Blitz Research Limited. It is the first to run on multiple operating systems; it runs on Mac OS, Linux and Microsoft Windows. The language is converted to assembler, then assembled - allowing it to be somewhat platform agnostic. From a gaming standpoint this is possible because, unlike earlier versions, BlitzMax can use OpenGL for rendering.

Other major changes from earlier Blitz products are its object-oriented and modular nature.

Features

  • BlitzMax compiler
  • Core BlitzMax modules
  • Max2D graphics module
  • IDE
  • debugger
  • sample code and documentation.

Data Types BlitzMax

All constants, variables, functions and expressions have an associated type. BlitzMax supports the following types[2]:

Description Syntax Minimum value Maximum value
8 bit unsigned integer Byte 0 255
16 bit unsigned integer Short 0 65535
32 bit signed integer Int −2^31 +2^31-1
64 bit signed integer Long −2^63 +2^63-1
32 bit floating point Float (+/-)10^-38 (+/-)10^38
64 bit floating point Double (+/-)10^-308 (+/-)10^308
16 bit unicode string String - -
Object obj:TObject - -
Array array{:type}[..] - -
Function Function:{return type}(Parameters) - -
Pointer Pointer ValueType Ptr - -
Variable VariableType Var -

Operators

BlitzMax supports the following operators. Operators are grouped into levels of precedence, starting with the highest precedence operators[3]:

Operator Syntax
Sub expression ( Expression )
New object New Typename
Literal Value
Identifier Value
Self object Self
Super object Super
Null value Null
Pi Pi
True True
False False
Minimum Min ( Expression1 , Expression2 )
Maximum Max ( Expression1 , Expression2 )
Member Expression . Identifier
Index Expression [ IndexExpressions ]
Call Expression ( Parameters )
Negate - Expression
Posate + Expression
Bitwise complement ~ Expression
Boolean not Not Expression
Absolute value Abs Expression
Sign Sgn Expression
Value byte size SizeOf Expression
Variable address Varptr Variable
Convert type expression Type Expression
Power Expression ^ Expression
Multiply Expression * Expression
Divide Expression / Expression
Remainder Expression Mod Expression
Bitwise shift left Expression Shl Expression
Bitwise shift right Expression Shr Expression
Arithmetic shift right Expression Sar Expression
Add Expression + Expression
Subtract Expression - Expression
Bitwise and Expression & Expression
Bitwise or Expression
Bitwise exclusive or Expression ~ Expression
Equal Expression = Expression
Not equal Expression <> Expression
Less than Expression < Expression
Greater than Expression > Expression
Less than or equal Expression <= Expression
Greater than or equal Expression >= Expression
Conditional and Expression And Expression
Conditional or Expression Or Expression

Variables

Variables are used to store values that change during the execution of your program[4].

Variables should be declared in your program before use. Declaring a variable means defining a name and type for the variable and, optionally, an initial value[4].

The general syntax for declaring a variable is:

Declaration Identifier : Type = Expression

Multiple variables may be declared in one statement using the comma separator[4].

If the type of a variable is omitted, the variable defaults to being of type Int. If the initial value expression is omitted, the variable is assigned an initial value of Null[4].

There are 3 kinds of variable, each of which differs by how and where the variable is stored:

Local Variables

Local variables are used to store temporary values that will eventually be discarded. Local variables are associated with the block of code they are declared in, and are only visible to code within that block. A block of code is represented by one of the following[4]:

  • The body of a function or loop
  • The body of an if/then/else statement
  • The body of a case or default statement

To declare a local variable, use a Local declaration:

Local int_var
Local string_var:String="Str",float_var:Float=10.5

Comment: You should prefer the use of local variables, as they are the fastest to use.

Global Variables

Global variables are variables that exist for the entire lifetime of a program[4].

To declare a global variable, use a Global declaration:

Global int_var
Global string_var:String="Str",float_var:Float=10.5

Field Variables

Field variables are declared within user-defined types using a Field declaration[4]:

Field int_var
Field string_var:String="Str",float_var:Float=10.5

Assigning variables

Once declared, a variable's value may be changed using an assignment statement[4]:

Variable = Expression

You can also perform 'modifying' assignments, which are shorthand for Variable = Variable Operator Expression. The syntax for modifying assignments is:

Syntax Operator
 :+ Addition
 :- Subtraction
 :* Multiplication
 :/ Division
 :Mod Remainder
 :& Bitwise and
 :&#124; Bitwise or
 :~ Bitwise exclusive or
 :Shl Bitwise shift left
 :Shr Bitwise shift right
 :Sar Arithmetic shift right

For example, the code my_var:+1 can be used in place of my_var=my_var+1.

Functions

A function is a self contained block of code that can be called from multiple points in your program.

Functions are declared using the syntax:

Function Identifier : ReturnType ( Parameters )
Function statements...
End Function

If ReturnType is omitted, the function defaults to returning an Int.

Parameters is a comma separated list of parameters for the function. The syntax of each parameter is similar to a variable declaration: Identifier : Type. Function parameters may be used inside a function in the same way as local variables.

The Return statement is used to return a value from a function.

Here is an example of a simple function that adds 2 integers and returns their sum:

Function AddInts:Int( x:Int,y:Int )
Return x+y
End Function

This function can then be called by other code:

Print AddInts( 10,20 )  'prints 30!

Function parameters can be assigned constant 'default values' using syntax similar to initializing a variable: Identifier : Type = ConstantExpression.

Default parameters can then be optionally omitted when the function is called:

Function IncInt:Int( n:Int,p:Int=1 )
Return n+p
End Function
Print IncInt( 1 )   'Prints 2
Print IncInt( 1,3 ) 'Prints 4

Blitz3D

Blitz3D was released for Microsoft Windows in September 2001, competing with other similar PC game-development languages of the time (such as Dark Basic). Blitz3D extended BlitzBasic's command-set with the inclusion of an API for a DirectX 7-based 3D engine.

Although originally Blitz3D's distribution rights were owned by Idigicon, Blitz Research Ltd. later signed a deal with the firm so as to allow Blitz Research Ltd. to distribute Blitz3D themselves. In return, Idigicon were granted full rights to distribute BlitzBasic and to clear any outstanding stock copies of Blitz3D.

Blitz3D was released as Open Source on 4 August 2014.

Overview

If you've been yearning to create games but have been frustrated by the complexity of programming languages such as C++ or Java, you've come to the right place[5]!

Blitz3D provides a simple yet powerful environment for game creation - simple, because its based around the popular and easy to use BASIC programming language; and powerful, thanks to a highly optimized underlying 2D/3D engine[5].

Blitz3D includes many commands to help you out with game creation - but not too many! Rather than confuse you with tons of commands, Blitz3D's command set has been carefully designed to provide maximum flexibility for minimum effort[5].

And if you get stuck, there is always the huge Blitz3D user community to call upon for help. Buying Blitz3D provides you with access to the official Blitz Research forums, home to thousands of dedicated and talented Blitz3D enthusiasts[5].

Can you write commercial quality games in Blitz3D? Why not - others are! Great titles such as Best Friends, Wonderland and Juno Nemesis were written in Blitz. In fact, many shareware authors are moving to Blitz from languages such as C++ due to the faster development time[5].

Super flexible entity system

Blitz3D is designed around the idea of entities. Typically, a 3D game will consist of many types of 3D elements such as cameras, lights, meshes and so on. In Blitz3D, these are all considered to be entities. This means that the same commands can be used to manipulate and deal with a wide range of 3D objects - for example, the TurnEntity command can be used to turn a camera, a light, a mesh, or even a massive terrain[5]!

Meshes

Meshes are the workhorse of any 3D engine. Blitz allows you to either create your own meshes from scratch, or load existing meshes in either X, 3DS or B3D format. The B3D format is unique to Blitz3D, and has been designed to provide for all the features of the Blitz3D engine. B3D exporters are available for a wide range of modelling software including 3D Studio, Lightwave and Truespace. Blitz3D meshes provide features such as vertex colors and multiple texture coordinate sets[5].

Terrains

Blitz3D terrains can be used to generate apparently HUGE scenes! This is achieved through a trick known as LOD (level-of-detail) reduction. This completely automatic process works by picking a set of polygons which approximates the shape of a very high resolution heightmap. Blitz3D terrains can also be modified in realtime - great for blowing holes in things[5]!

Sprites

Sprites are simply textured 2D rectangles - easy to setup and great for things like particle effects, heads-up-displays and so on. Sprites can be setup to automatically orient themselves to face the camera, giving the illusion of a spherical object, but without the overhead of drawing a ton of polygons[5].

Cameras

Blitz3D cameras offer the programmer direct control over viewport, zoom, clipping range, fog effects and even offer an isometric mode. Multiple cameras are also no problem - simply use CreateCamera as many times as you want[5]!

Lights

Blitz3D offers directional lights, point lights and spot lights. You can control the color, range and 'cone' of lights with ease[5].

Super flexible brush system

Blitz3D makes extensive use of the idea of brushes to color, texture and otherwise manipulate the appearance of entities. Brushes offer a wide range of effects such as tinting, multitexturing and specular highlights[5].

Multitexturing

Multitexturing allows you to apply up to 8 layers of texture to an entity. This can be used to achieve such effects as lightmapping, detail texturing, specular highlights and a host more. The multitexturing system in Blitz3D also allows you to precisely control how textures are combined together[5].

Environment mapping

Environment mapping creates the illusion of reflections with in a scene. Blitz3D provides 2 forms of environment mapping - spherical or cubic. Cubic environment maps can even be updated in realtime, providing for awesome, dynamic reflection effects[5].

Examples of programs

Нello world

Graphics 800,600                 ; - Graphic mode 800x600
While Not KeyDown(1)             ; - Start the main loop
 Cls()                           ; - Clean the screen
  Text 10, 20, "Hello, World!" ; - Write the text "Hello world" in point 10,20
 Flip()                          ; - Output on display
Wend ; Stop the cycle by pressing the button Esc
End                              ; The end programm

Нello world with using variables

                   
Graphics 800,600 
Global a$="Hello"
Global b$="World"              
While Not KeyDown(1)                           
 Cls()                          
  Text 0,0,a$+b$
 Flip()                        
Wend
End

Working woth images

                     
Graphics 800,600  
Global Image = LoadImage("picture.bmp")
            
While Not KeyDown(1)                          
 Cls()                          
  DrawImage Image,100,100
 Flip()                        
Wend
End

Working with 3D-Grafics

                     
Graphics3D 800,600                     ;Setting graphics mode 
Global model = LoadMesh("helloworld.3ds")          ;Loading the three-dimensional model lettering "Hello, World"
PositionEntity model,0,0,0            ;Setting the mode in point 0,0,0
Global camera = CreateCamera()             ;Creating the cemera
PositionEntity camera,0,0,-10             ;Setting the cemera behind the object

While Not KeyDown(1)                         ;Beginning of the loop  
 Cls()                          ; Cleaning of display
 RenderWorld()                  ; Doing rander of image
 Flip()                        ; Output on display
Wend                           ;The end of loop
End                             ;The end of programm

BlitzPlus

Overview

BlitzPlus provides developers with a complete 2D programming solution for the PC. Utilising a BASIC/C hybrid language for use with its compiler, BlitzPlus is capable of creating any type of 2D program, with minimal development-time and with minimal hassle. Just run the included IDE (or use one of your own), type your code and your Windows executable file will be created, ready to be run on any computer running Windows 95/NT 4 or later[6].

Language

BlitzPlus' language is a BASIC/C hybrid. As well featuring the classic BASIC constructs such as goto and gosub, it also features C influences such as functions and types. On top of this, BlitzPlus' command set features over 500 commands. This command set is highly streamlined meaning complete programs require very few lines of code indeed[6].

2D Engine

BlitzPlus' 2D engine is based on 'pure' 2D blitting operations, as opposed to 'fake' 3D ones. This has the combined benefit of allowing for pixel-perfect graphics, as well as allowing for compatibility with virtually all graphics cards, 2D or 3D. The 2D engine itself is highly capable, with the capability of performing thousands of blitting operations per second[6].

GUI Support

BlitzPlus' GUI support is implemented via an event-driven 'Gadget' system. Simply by adding GUI gadgets to your program, and setting up a small loop which deals with program events, you instantly have yourself a fully-blown application to compare with anything created by other languages[6].

IDE

BlitzPlus comes with its very own Integrated Development Editor (IDE). The IDE allows you to edit, test, debug and compile your program all from the one environment. If the included IDE is not to your liking, then you are free to use the code editor of your choice, as the Blitz compiler features command line capabilities[6].

Executables

Creating executable files (i.e. program files) in BlitzPlus is simply a matter of clicking a button. Once you have done so, the executable will then be able to run on any Windows95/NT4 or later compatible machine independently of BlitzPlus. You are free to do with BlitzPlus executable files what you want, with absolutely no restrictions or obligations with regards to distributing them or selling them[6].

Documentation

Included with Blitz is a full and thorough documentation. All 500+ commands have their own help pages, explaining what that command does, and most commands have their own examples too. There are also a language reference and tutorials included with Blitz to help you get started[6].

Community

The Blitz community is a large and active one. Its main areas of activity are the official Blitz forums on this site and the unofficial, but still busy BlitzCoder forums. Should you ever be in need of assistance with your Blitz programming, or just want someone to take a look at your game - these are the places to go[6].

References

  1. 1.0 1.1 1.2 Blitz Product History
  2. BlitzMax Types
  3. BlitzMax Operators
  4. 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 BlitzMax Variables
  5. 5.00 5.01 5.02 5.03 5.04 5.05 5.06 5.07 5.08 5.09 5.10 5.11 5.12 5.13 About Blitz3D
  6. 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 About Blitzplus

External links