This is an introductory tutorial about getting started with Brutus2D. It will not teach you how to program or how to make a complete game, instead, this tutorial is focused on saving you time during the first few hours with Brutus2D. This tutorial is aimed at those who have never programmed before and those who are looking for an introduction to Brutus2D.
Brutus2D Minimum Tutorial
So, you want to make 2D games with Brutus2D? The first thing to do is get a blank, error-free window open on your desktop. We begin with objects.
Object oriented
Brutus2D is object oriented. It has several built in objects you use and you can make your own objects, which really helps in making a game engine and organizing your game design. Consider objects as your minions who do your evil bidding.
If you want to draw text to the screen, you tell the graphics object to do it. The code looks like this graphics.SetText. The first part of the code is graphics, which is the object name. The second part, after the period, is the order you are giving the object. In this example you are effectively saying "Graphics object! Draw text for me!". In a real-life game, this command would be followed by specifically what text you want to draw and where.
The objects you will be using most are the graphics object, the keyboard object and the mouse object.
Waking up built-in objects
Before you can do anything with Brutus2D's built in objects (and therefore anything at all with Brutus2D), you need to initialize (wake up) the object you want to use. Initializing any object in Brutus2D can be accomplished by the command .Initialize. Here are examples for the three most used objects :
graphics.Initialize
key.Initialize
mouse.Initialize
After you initialize an object, you can put it to work for you by using it's other functions. You should initialize the objects you want to use in the first few lines of your code.
Putting objects to sleep
After you are done with an object, you need to put it back to sleep again. Doing so frees up the memory and cleans up the mess an object makes (if any). You can kill any object by using .Terminate. Here are examples for the three most used objects :
graphics.Terminate
key.Terminate
mouse.Terminate
It is good practice to do this before you kill the game. However any unterminated object in Brutus2D will be terminated automatically when the program exits.
Comments
A comment is like a note you leave to yourself. The Brutus2D virtual machine ignores the comments and knows that they are not actually game code. Brutus2D supports both C-like and BASIC-like comments, but does not support REM. For this tutorial, we will only use the apostrophe ( ' ), but if you want to know more about comments, see the comment page.
Everything on the same line as the apostrophe is ignored by Brutus2D :
' this is a comment, I can say anything I want to say here
graphics.Initialize
The minimum code
Every Brutus2D game needs a certain amount of code to run properly. Since Brutus2D is a 2D game programming language, you have to initialize the graphics object. Since you are using the graphics object, you will have to kill it when you are done. You will also have to clear each frame with graphics.Clear before drawing a new one and draw each frame with graphics.Display. This is not as complex as it sounds, see the code below :
graphics.Initialize
graphics.Clear
graphics.Display
graphics.Terminate
To try this, copy it into your Brutus2D IDE and press F5.
This will cause a window to pop up and immediately shut down because there is no other code to run. However, this is the bare minimum for a proper Brutus2D game.
The Game Loop
Every game has a game loop. The game loop runs until the game is over. To exit the loop, you will need to initalize the keyboard object as well (and terminate it) because you will have to check for keyboard input.
graphics.Initialize
key.Initialize
' this is the game loop
' hit the excape key or the X to exit
do while not key.Pressed(vk_escape) and not key.Pressed(vk_windowx)
graphics.Clear
'draw your stuff here
graphics.Display
loop
graphics.Terminate
key.Terminate
This will cause a game window to be opened and this time it will not close immediately. This is because the game loop will run until the player presses the escape key key.Pressed(vk_escape) or the x on the window key.Pressed(vk_windowx) .
In a real game, you will put all of your main game code into the main game loop.
Conclusion
We hope we have saved you some time during your first few hours using Brutus2D. Now that you know the minimum you need to know to get started, you can try making your own game, or, if you need further guidance, check out our tutorials section.
Related Pages
Backlinks
These pages link back to this tutorial. You may find them helpful.
Discuss