Search Results

Sunday, January 23, 2011

Setting Up Development for BennuGD - Part 2

Okay, so now that we've got the IDE (Integrated Development Environment) set up for use with the BennuGD programming language, it's time to make a simple program with it, and finally, port it to the Caanoo!
Here is the source code...
import "mod_text"; // These commands import the necessary functions and variables
import "mod_video"; // to control the program; mod_text = text functions
import "mod_joy"; // mod_video = screen functions / variables
import "mod_key"; // mod_joy and mod_key = joystick and keyboard functions / variables
import "mod_proc"; // mod_proc = process functions like let_me_alone()
import "mod_map"; // mod_map = graphics functions like png_load()

begin // This is the beginning of the BennuGD program.

set_fps(60, 0); // This command sets the Frames Per Second to 60, if possible, and
// also tells BennuGD not to skip drawing game frames to maintain
// the Frames Per Second (FPS) of the game
set_mode(320, 240, 16); // This command sets the game to run at 320 pixels wide, 240
// pixels tall, and 16-bit color, which GPH's Caanoo uses as well.

write(0, 160, 120, 4, "Hello World!"); // This command writes the string, "Hello World!"
// to the screen at position 160, 120. The argument '4' designates the alignment of the
// text (4 = center vertically and center horizontally), while the first argument is the
// ID of the font object to use. Because it is 0, it will use the built-in font, though
// we could create a font object using fnt_load or ttf_load and use the number
// returned from that function instead.

Sprite(); // This runs the Sprite process defined below - a process is kind of
// like a class, in that one calls a process to make it run. When you call a process, it returns a processID, which could be considered an ID of an object
// Because the sprite function loops, we don't need to constantly call
// it inside of the game loop below

loop // This will loop indefinitely until the game quits - the Game Loop

if ((joy_numjoysticks() and get_joy_button(0,8) == true) or (key(_ESC) == True) )
// If the game receives any quitting action (Home for the
// Caanoo or ESC for the PC, it will use...

let_me_alone(); // This function to kill all processes running except this one,
// The main one, and then...

exit(); // it will exit the game.


frame; // This tells BennuGD to pause this process for the current
// game frame; When all processes have run, then the next
// game frame begins.


process Sprite();

graph = load_png('sprite.png'); // The 'graph' variable is a built-in variable that
// defines what image this process will display. This
// is essentially a game object, and so has properties
// controlling its position in game as well as how it
// is drawn. So, we set the built-in graph property
// to an external png sprite.

x = 160; // This sets the position of the center of the sprite
y = 140; // to 160, 140 onscreen;
// notice that the screen starts from 0, 0
// in the top-left corner of the screen and increases
// downwards to the bottom-right corner (320, 240).
frame; // This tells BennuGD to pause this process, like the 'frame;' command
// above.

So this source code will draw the text "Hello World!" onscreen as well as draw a sprite onscreen, the sprite located in the file 'sprite.png', with the sprite file being in the same folder as the compiled game file. The program is fairly simple, and is well commented, as you can see. You can step through the code and see what's doing what, but rather than writing each line yourself, I've made a zip of this project. Here's the link to my Hello World BennuGD Source Code.

Now, then. You'll probably want to test it out, right? Okay. So, unzip the source code to a folder. Then, open up Komodo Edit and create a new Project file - open the Project File, then click New Project. Save a new project in the Source Code folder. Now, open the Main.prg file - that's the source code for the Hello World demo. Now, then - assuming you've set up Komodo Edit's commands and keybindings as explained in Part 1, you can press F5 to build the project. You shouldn't see any problems in the console output - it should list the number of processes, variables, and other values and return the value 1 to show that it built correctly. Press F6, and the game should run on your screen!

Hello World running correctly after building it.

Now, you'd probably want to port it to the GPH Caanoo. To do that is pretty simple. Included in the source code zip file you downloaded is a 'bgd-runtime' folder and a 'game.gpe' file - these will run the compiled game on the Caanoo. If you've gotten a runtime for Caanoo from BennuGD's homepage at the beginning of the tutorial, rename it to 'bgd-runtime'; otherwise, there is one for the Caanoo ready for use included in the source code.

So, you'll need to have an SD card to store the game on to use in the Caanoo. Once you've got one, make sure there's a games folder on the SD card; if there isn't, create one. Then, inside of that, you'll need to make a folder for your Hello World game; name it "Hello". Inside of it, you'll put the 'bgd-runtime' folder, the 'main.dcb' (the compiled Hello World game file) file, the 'sprite.png' file (our graphic that is loaded in-game), and the 'game.gpe' file. The 'game.gpe' file is a script and will use the BennuGD runtime (the Caanoo version of the bgdi executable) in the 'bgd-runtime' folder to run the compiled game file (main.dcb). It is already written for this purpose, so be sure the 'bgd-runtime' folder is inside of the 'Hello' game folder. Also, because it uses the file named 'main.dcb', you can simply copy that file to work with any other project with the same game file name.

Finally, you'll create a configuration file (a .ini file) that will point to the script that runs the game - the Caanoo needs this file to find the games. Back in the games folder of the SD card, create a text file that is named, "Hello.ini". In it, the only thing you need to put is:

name="Hello World"

That's it! Save the .ini file back, go to the Games menu, and run the "Hello World" game! It should display essentially just like the game on the computer. Press the Home button to back out.

For extra credit, try making it so that the sprite moves downwards constantly. It should be simple enough to do in one or two lines. Note that making the 'game.gpe' file is a bit difficult - you should use a file editor that allows for using Unix-style line endings. If you can't get it to work, simply use the file packaged in the source code. Anyway, that's all for setting up development for BennuGD! Have fun!

~ SolarLune


  1. Hey thanks for the tutorial. I am a developer looking into this platform. I have a correction for the Caanoo instructions above. The path should be path="/Hello/game.gpe".

    I also have an issue where the caanoo will flash the app and then the app will not start. Do you happen to know what is going on there? Thank you.

    1. Sorry for taking so long to reply, but thanks for the instructions. I'm not sure why the app doesn't start - try asking on a forum like the forums.