Sunday, September 18, 2011

Game Programming -- Part 3: Sprite/Terrain Creation



Game Programming -- Part 2: Setting Up the Window



Next

Tuesday, August 2, 2011

Unreal Engine

I recently downloaded the Unreal Development Kit (UDK), and it has been the most exciting programming adventure I have ever embarked on.

UDK is a 3D engine, which means that it takes care of the boring parts of the programming for all the 3D graphics and physics and stuff, so that you can focus on what the game looks like and what happens in it (all the fun stuff).

UDK is completely free for personal use, and you can download it here: http://www.udk.com/download

I highly recommend the YouTube tutorials on how to use UDK by TheNewBoston: UDK Tutorials. They are very helpful, and rather entertaining.

I will be uploading some of my own videos of what I'm doing soon.

Tuesday, May 24, 2011

Beginning Programming with Just BASIC -- Tutorial 7: Graphical User Interface



Tutorial 7 -- Graphical User Interface

We have previously been working out of the main window. We no longer wish to be using this window. We now would like to be able to design our own windows. To do this, at the top of the program issue the command

    nomainwin

... and then go on to describe your window:


    WindowWidth = 232
    WindowHeight = 215
    UpperLeftX = 50
    UpperLeftY = 50
    statictext #1.statictext, "This is static text", 26, 16, 152, 20
    button #1.button, "This is a button", [whenClicked], UL, 22, 101, 138, 25
    textbox #1.textbox, 22, 51, 100, 25
    open "Title" for window as #1
    print #1, "font ms_sans_serif 0 16"
    print #1, "trapclose [quit]"

[1.inputLoop]   'wait here for input event
    wait

[whenClicked]   'Perform action for the button named 'button'
    notice "You pressed the button!"
    wait

[quit]
     close #1
     end

So here's how it works: You first list all the elements of the window, such as the text, the buttons, the text fields, etc. I'm not going to list how to enter all of the different kinds of elements since they can be found in the help files, but in general the syntax is as follows: (1) list the element type (e.g. "statictext"), (2) list the handle for the element with the #-symbol, followed by the handle for the entire window, and then an extension that describes the specific element, (3) the text that goes into it/any functionality that needs to be described on this line, (4) numbers that describe upper-left x, upper-left y, width, and height of the element, in that order. After listing all of the elements, open the window:

open "Title" for window as #1

In this line you give it a title, tell it what kind of window it is (in this case just the default window), and give it a handle. Again, a handle is what you use to refer to the window, and it begins with the #-symbol.

All commands concerning the window go in quotations following the print command, such as

print #1, "trapclose [quit]"

This line is called "trapping the close event," and it tells the program to go to the branch label called [quit] when the user clicks the little red x in the upper right corner of the window. In this case, all it does is close the window

close #1

and end the program.

Suppose you want to get input from a textbox. How do you do that? Sneezy.

[whenClicked]   'Perform action for the button named 'button'
    input #1.textbox, text$
    print #1.textbox, "!contents? text$"
    notice "You entered "; text$; " into the textbox!"
    wait

DON'T WASTE TIME!

Just BASIC has this handy little built-in WYSIWYG program that allows you to design your window, and then it produces the code for you. This program cuts down on the time it takes to program your GUI's by a very large amount. To use this feature, click on the RUN drop-down menu, and then click "FreeForm-J GUI" editor. You will be so glad you learned about it upfront.

Now you can make your programs look just the way you want them!

goto [nextTutorial]

Monday, May 23, 2011

Beginning Programming with Just BASIC -- Tutorial 6: File Input and Output



Tutorial 6: File Input and Output

Suppose we want to be able to close a program to go eat supper and come back later. But we want to save all our data. By now you should be familiar with the fact that variables and arrays reset when you close a program.

You can print data to a file. Like this:

input "Give your file a name: "; filename$
open filename$ for output as #save
print #save, "Yotta yotta homina homina jiggabuh."

Some notes about this code: #save is called a handle, and it is used to refer to the output file. Any variable name preceded by a # is a handle, which are used to describe windows in general. So, if you run this program and name your file "output.txt", a new file will be created in the folder that your basic file is saved in named "output.txt," and it will contain a line that says:

Yotta yotta homina homina jiggabuh.

You can also do input files, so you can load a file into your program that you previously saved.

input "What file would you like to open? "; filename$
open filename$ for input as #load
for i = 1 to n
    input data$(i)
next

Here is an example program that allows you to save your work:

[start]
    print "Would you like to (1) write a story, (2) read one you wrote, or (3) exit?"
    input answer
    select case answer
        case 1: goto [write]
        case 2: goto [read]
        case 3: goto [quit]
    end select

[write]
    input "How many lines will your story be? "; n
    dim txt$(n)
    print "Write your story:"
    for i = 1 to n
        input txt$(i)
    next
    input "Enter a name for the file: "; filename$
    open filename$ for output as #save
    for i = 1 to n
        print #save, txt$(i)
    next
    close #save '<- Closes the file afterward
    goto [start]

[read]
    input "What is the file name? "; filename$
    open filename$ for input as #load
    input #load, n
    dim txt$(n)
    for i = 1 to n
        input #load, txt$(i)
        print txt$(i)
    next
    close #load
    goto [start]

[quit]
    end


Some notes about this code: This is a basic example of a program where the user will be producing something (in this case, a story), and then can read it later. Instead of doing it this way, you should look into how to do a file dialog window (it's easier than you might suppose!).

goto [nextTutorial

Sunday, May 22, 2011

Beginning Programming with Just BASIC -- Tutorial 5: Arrays



Tutorial 5: Arrays

Arrays are similar to variables, except that they can hold more than one value. For instance, a list of names and grades. This is a good way to organize data, especially when little is known about the data that is going into them, in particular how many data point there are.

To set up an array in your program requires a little more work than it takes to use a variable. First you have to define how big the array will be, that is, how many values it can hold. You do that with the DIM command:

dim myArray(100)

In parentheses you put a number defining the size of the array. In this case I can put 100 values into the array called myArray(). So how do I do that?

With loops! Arrays are often used in conjunction with FOR loops because of how easy it is to systematically define every value.

for i = 1 to 100
    input myArray(i)
next

This is far easier than having to write out

input myArray(1)
input myArray(2)
input myArray(3)...

You get the picture.

You can also have multidimensional arrays. Say you want to associate two parameters to the same value. You can do that easily:

dim twoDimensional(10,10)
for i = 1 to 10
    for j = 1 to 10
        twoDimensional(i,j) = i*j
    next
next

Those are the essentials of making an array. I decided to include them early on so you don't waste time trying to use variables for some complex program.

goto [nextTutorial]