Vous êtes sur la page 1sur 9

Introduction to BlitzMax 2010

Chapter # 1
Introduction:

Thank you for taking the time and looking at my site is that is where you had gotten this from or
if you took time and got it from my blog site as well. Anyways I would to take some time and give you a
idea of who I am.

I am a born and raised Wyoming boy living in Cheyenne, I have been around computers sense I
was young starting to get my hands around things since I was 6 or 7, I worked on my grandfather's lap
learning the ways of DOS and AutoCAD. I started programming when I was in Jr. High learning from a
friend that used QBasic and then moved to North Carolina for 2 years, returning I started in High School
doing Visual Basic, and then taking my spare time working with C++ and other programming languages
like Pascal (I hated it). I then got into Blitz Basic don't remember the dates and/or times but later I got
Blitz3d, I beta tested BlitzMax which was nice, but I don't remember if Mark (owner of Blitz Research)
remembers this.

Now I'm here to help teach all you about blitzmax and how it works and I hope you enjoy it as
much as I do. I know that this may look like something you have seen in the past and it may be boring at
times, but this will be a interactive experience and each chapter will be based on your votes on what
you want to learn and where you want to go next.

Time to learn programming:

Now that you know a bit about me lets us work together on the first bit of BlitzMax. The first
thing you can do is download the demo from the link provided on my blog, and then we will try to learn
BlitzMax together in 30 days or less and see what you think and where you want to go with it. Now if
this ever gets published then you can get a copy of the demo from my CD that I will provide with the
book (with Blitz Research Permission).

Okay so let's get to it; I am under the understanding at this point that you have installed the
program and everything is ready, and you are ready to get coding. So let's look at the MaxIDE together
and we can see how things work. BlitzMax's IDE is multi plat formed and can be used on LINUX, MACOS,
and WINDOWS, and BlitzMax's IDE is easy to use unlike some others you might of seen in the past. So
let's get to looking!

In the image provide (figure 1a) you will see that the idea is very clean, simple and doesn't
require a lot of training to use it. Now there are other IDEs you can get for free or even purchase, but
for now we will stick with what is given to use and make use of it.

1
Introduction to BlitzMax 2010

figure 1a:

The first things I would like to do is go over the icons on the IDE and tell you which two icons are
going to be your best of friends. The two icon that we will be exploring are the BUILD and BUILD-RUN
icons .

The BUILD icon will let you test code without running the program to see
if there is any wrong

The BUILD - RUN icon will let you do what it says build the code then run
it.

As you can see there is not a lot to the IDE so far, but we haven't even started programming yet,
so let's see if you can make some make and start programming something amazing, but wait! We need
to discuss things a bit more so you can better understand the concept of how BlitzMax is different from
other programming languages and what makes it so amazing.

Now that you have the IDE open and you have the screen that looks like figure 1a, I want to you
make it so it looks like figure 1b and to do this we need to make a new file to put our code into.

2
Introduction to BlitzMax 2010

figure 1b:

I would like you to press Ctrl - N or hit the icon at the top that looks like a piece of paper with
start in the right hand corner. Once you have what is in figure 1b lets continue and work on the basics
of BlitzMax programming.

I want you to all understand something though I'm not going to make a oh look this is a
command and then this is want is does, I want you to come back from this book or PDF however you got
this publishing and say wow I have really learned a lot form this and now I know what I can do to make a
successful game or program. BTW that brings me to the next thing, if you decide you like this
programming language there are Module expansions that will help with future projects, one of my
favorites is the MaxGUI module and this will allow you to make a application program such as a level
editor of scripting programmer. The MaxIDE was made using the MaxGUI and has available source for
you all to look at.

I want to explain the process of getting the Max program to work correctly under different
conditions, and that would be thru the framework provided. In order to make the .EXE files smaller
there is a nice set of functions or commands you can use to do this.

Framework builds the BlitzMax application with only the Module specified rather than all
modules installed. (TAKEN FROM BLITZMAX DOCS)

3
Introduction to BlitzMax 2010

Framework BRL.Max2D

You can see that in the box above I will be placing code for now let's just talk about what you
see above and then later you will see how it's used.

Frameworks are the base module of the program you are working on, later if you plan on using
other Modules and they already include a main structure then you can just use that module as your
framework, as above you can see I have used the Framework with BRL.Max2D.

BRL.Max2D is the main module for Max and it already includes most of the required commands
need to start working on a basic program, but I do also want to mention to that you can use different
graphic drivers as well if you one of those people that believe that DirectX is for windows and OpenGL is
for the rest , or you just want to make everyone else mad and just force them to use OpenGL.

BlitMax comes with four graphics drivers and maybe later down the road, and these graphics
drivers are listed below.

 GLMax2DDriver - OpenGL graphics driver; this can be used across multiple platforms and is
graphics if you want to provide your program to everyone.
 D3D7Max2DDriver - DirectX7 graphics driver; great for use on older windows machines that
have yet jumped into the 21st century of game playing, I would recommend this if you plan on
just releasing it on Windows and/or releasing only a small basic game (ex: Puzzle game).
 D3D9Max2DDriver - This is the best if you are wanting to release a more professional title only
for Windows, this is the longest lasting Driver for DirectX and has the most bugs worked out,
but like I said if it's a simple title use DirectX7

Now that you know what drivers you have available for 2d game making I just wanted to let you
know of one other thing that you can do in BlitzMax and that is ... DRUM ROLL .. OPENGL 3D
programming. Yes OpenGL in its raw form is available as well, but I haven't really touched it much and I
don't plan on doing a tutorial for this for a long time this is another PDF or Book.

Framework BRL.Max2D

SetGraphicsDriver() GLMax2DDriver()

So once again you can see the code above and yes for now I will be choosing the OpenGL option
so that all the readers can follow along, but if you want to use DirectX then just change the Driver using
one of the other provided in the list above.

4
Introduction to BlitzMax 2010
Now that we have that done we need to start getting the window made and show a black
screen, so let's go ahead of and make the huge header file and include it in the main file and start
coding. The first thing you need to do and keep the code from the previous box above and let's start
adding the code for the header.

Framework BRL.Max2D

SetGraphicsDriver() GLMax2DDriver()

Graphics 640, 480, 0, 0

Okay it's done and now let's go ahead and start adding more, oh wait where done and the
greatest thing in the world is there isn't a header file and any other expensive lines of code, but you
need to know that deep down there is a beating heart of C++. That's right another thing you might not
know about BlitzMax is that you can build modules in C++, then import them and then run it with just a
few lines of code, but right now we will stick with what is given to us.

Okay so now you have the Graphics command, you are probably wanting to know what it does,
and that is want I'm going to tell you. This command gives us a window and builds us a buffer to work
with, that we can draw to using other commands, and that we will get to after I talk about structure.

So let's get to that now; next few pages are going to show u graphics and charts that I would
recommend you print and keep with you to better understand what is happen and a recommended way
to setup your code. First thing you need to do is put in our loop function, and for that we will be using
another new command known as the Function.

Function MainLoop(runtime:int)

So above you see the new command and now of course it's time for me to explain it, and once
again that's what I'm going to do.

So a Function has multiple uses and as you can see we are going to use a function to create our
loop, and so you will want to add more to the loop so let me show you what we are going to add to
make the function work.

5
Introduction to BlitzMax 2010

Function MainLoop(runtime:int)

While Not KeyHit(KEY_ESCAPE) or AppTerminate()

Select runtime

Case run_main

EndSelect

Wend

EndFunction

Okay so yeah that is a lot of code, but don't worry once again I'm here to save the day. Now
that you can see the full Function in code you are asking yourself I see a few new pieces of code as well,
yes your right and no your eyes are not playing a trick on you. The code as the loop in it using the While
... Wend command, the Select ... EndSelect, KeyHit(), AppTerminate(), and last but not at least the Case
command, okay the last one is a requirement of the Select command. Now that you see the code you
are probably wanting to know what each of the commands do, and here you are in techno blue...

 While ... Wend - This is a looping command similar to that of another command that is not as
well used and that would be the Repeating loop, which has multiple ending stories to it, and
we will see that later. While command lets us do a set line of code until a condition is meet
and in this case I have added two conditions (KeyHit , and AppTerminate()).
 KeyHit() - Command allowing you to press a key and get a reaction from it, right now I'm using
it for Escape, but the KeyHit() has a cousin know as the KeyDown() which is if the key is left
down do something as long as its down.
 Select ... EndSelect - Okay so I haven't shown you the cousin to this command yet, but its
basicly a If ... Then statement that has multiple selections that can be made, and the Case
command contorls them.

Now you can see that what each of the commands do now I'm going to show you how to get the
function to work, the image on the next page will show you this and also should complete the final
stages of the chapter. I am trying to keep these chapters small in size so we can spend as much time as
we can together , and so that I have more to write about on my blog http://fbepyon.blogspot.com/.

So like I said the last page of this chapter will have the finish coding from the IDE and copy able
code.

6
Introduction to BlitzMax 2010

Framework BRL.Max2D
Import BRL.GLMax2D

SetGraphicsDriver() GLMax2DDriver()

Graphics 640, 480, 0, 0

MainLoop(run_main)

Function MainLoop(runtime:int)

While Not KeyHit(KEY_ESCAPE) or AppTerminate()

Select runtime

Case run_main

EndSelect

Wend

EndFunction

Okay so I lied a bit but who doesn't I wanted to add in a bit more on this chapter and then I will
end it and that is some variables, the diagram I was talking about showing what we are working with,
and where the code will be going. The variables that we need are very basic but I should explain to you
something about them, and that is I don't use my constants the same as most people do, or maybe I do,
but this was the way I was always taught.

As you see in the code there is a runtime, and run_main; these are variables, but on is a local
and the other is constant variable. Local variables can only be used during its time spent within the time
it was ran and the time in which was used in a function, the local variable in the function you can see is
my runtime variable and that was assigned as a INT (integer). I couldn't use anything else because of the
way I am using the variable, and that is explained by the constant, which is my run_main, and this
constant will be defined at the top of the code like shown.

Framework BRL.Max2D
Import BRL.GLMax2D

Const run_main:INT = 1

7
Introduction to BlitzMax 2010
I use constants thru out the whole runtime of the program, and reason for this is because I like
to be able to have a better structure of my program, and that bring us to the last part of the chapter.

One other thing is the new command Import this will allow us to use other modules with and
because I chose to use OpenGL , I had to import BRL.GLMax2d, your job if you want to use DirectX 7 or 9
is to find out the mystery import.

Below this line is a diagram of my game / program :

Framework Initialization
BRL.Max2D Graphics 640, 480

MainLoop()
While ... Wend Variables / Functions
Select ... EndSelect

RunTime Images and player inputs


•Runtime is list of variables and •Not covered yet and will be
functions used to contorl objects discussed in the next chapter.
on the screen and other items
(ex: player, npcs, monsters)

I wanted to best show you how the commands will all go into one .EXE file and when launched they all
work together. Now in later chapters I will be added in other functions and we will be seeing a larger
tree form and at end of ever chapter you will see that tree until within 30days you have a working
program of you own.

8
Introduction to BlitzMax 2010
BTW don't forgot the mystery import its under the help files, if you can't figure it out I will put it in my
blog post for chapter 2.

FINAL CODE PRESENTED TO YOU :

Framework BRL.Max2D
Import BRL.GLMax2D

Const run_main:Int = 1

SetGraphicsDriver GLMax2DDriver()

Graphics 640, 480, 0, 0

MainLoop(run_main)

Function MainLoop(runtime:Int)

While Not KeyHit(KEY_ESCAPE) Or AppTerminate()

Select runtime

Case run_main

EndSelect

Wend

EndFunction

- QUIZ TIME -

Question #1 :

The answer to the first question will be found in the final code; what is the command used to end the
program without having to hit escape.

Answer on the last page of book, or found on the blog at http://fbepyon.blogspot.com/

© 2010 Fallen Flames Design, By: William McCollom (aka FBEpyon)

Vous aimerez peut-être aussi