Game Development Community

A New Tutorial Series - The Breakout Tutorial

by Tetraweb · in Torque Game Builder · 03/29/2008 (12:17 pm) · 78 replies

Hi, I have a seven part tutorial series on creating a Breakout/Arkanoid type of game. I am almost finished with part seven, so I thought I would begin posting the first parts in the series now.

Overall Goal of the Series
This series began as an experiment a year ago, while I was teaching myself how to program in TorqueScript. I began writing notes for my own use on how to do certain things. These notes kind of spontaneously organized themselves into a tutorial, and I found that I liked writing it. It was also a great way to help solidify things in my mind.

A Few Things to Note

What? No Behaviors?
There are no behaviors whatsoever used in this tutorial. I began writing Part 1 when TGB was at version 1.13, but that's not why I didn't include behaviors. The main thrust of this series is scripting, using TorqueScript to accomplish things; building logical, understandable code to create a game.

Behaviors are a method of abstracting code into a LevelBuilder drop down. They are not always the correct choice. For one thing, they add a certain amount of overhead, both in amount of code and in complexity, which is not always necessary, particular for simple object actions. Also, they may lead to a certain sameness across your games, it's almost too easy to build a game from your set library of behaviors that you always use, perhaps hindering innovation.

Now, I'm not really against behaviors, and may use them in a future tutorial, but I wanted to present a complete game that did not use them.

Breakout? What is this 1987?
I'm a real fan of TGB, I think it has a tremendous amount of potential. When people first begin using it, they almost always begin thinking along the lines of platformer or side scroller, assuming that is its natural strength. I disagree, I think it is perfectly suited for almost every casual game you can think of.

I'm not a huge fan of breakout in particular, but I love all kinds of casual games; matching games, card games, unusual logic games. The BreakoutTutorial started almost randomly, I think, because the last game I had been playing was a wonderful Arkanoid kind of game called BreakQuest. As I played it, I thought "I bet TGB could do this."

A Finished Game
Part of the goal of the series, and one reason it is so long, is that I wanted to have, at the end, a complete and finished game. Sound effects, music, particle effects, game logic, multiple levels, high scores, game state saving (unlocking levels,) etc. I didn't want to create a tutorial that provided a shell of a game, and then tells the user, "OK, now finish it up!"

Intended Audience
The intended audience for this series is everyone. I wrote it with a beginning user in mind, so if you have been using TGB for a while, you may find some step details too obvious. However, I would not hesitate to recommend it to intermediate or even advanced scripters. It's fun, and you may learn some TorqueScript techniques or methods you haven't been using.

I do urge everyone who follows the tutorial to read it completely. Just jumping from code section to code section and copying and pasting will teach you nothing, and you may miss some important information. For very new users, I promise you that if you take it slowly, digesting every part of it and understanding each line of the code you are pasting in, by the end of part seven you will have a pretty firm command of TGB.


Well, that was a longer preamble than I had intended, so here is the link to part 1 of the series.
The Breakout Tutorial - Part 1

I'm putting up parts one, two and three today. Part four should go up tomorrow, and five shortly after that. The final two parts will go up a little bit later as I proof and test them, but I'm hoping it will all be up in the next week or so.

I am going to start a thread for each subsequent part, which I intend to be used for discussion, questions, etc.

Thanks,
Greg
Page«First 1 2 3 4 Next»
#61
11/03/2009 (9:46 pm)
did anyone tried to use any tutorial in windows7 ?????

im fed up..i tried many times not this tutorial but the fish demo and game one as well.....
:( :(
#62
11/23/2009 (11:50 am)
Thank you so much for this tutorial. It has cleared up a lot of misconceptions I had about Torque.

If you're still looking for syntax help, I did find a small thing:

"We gave our base the class baseClass so when the level is loaded, this function will be run. The first line assigns the base to a global variable so we can always access it throughout the game. The next five lines modify the physics of how it responds to movement and collisions."

There are six lines following the global variable ;)

#63
12/11/2009 (3:26 pm)
This is a great tutorial and I've tried both the solutions Jesse Tucker and Max Kielland have proposed for balls getting stuck in certain instances.

And yeah I gotta say I'd love to see what the rest of the tutorial was going to entail. This was definitely one of the best walkthroughs I've seen of any engine to date.
#64
01/03/2010 (8:21 pm)
I tried everything listed here and in the tutorial and still cant get the ship to move I get a unable to find object:' " attempting to call Function 'setImpulsForce' Everything is in the right place and I copy and paste all the code and still nothing.
#65
01/03/2010 (8:24 pm)
Quote:I tried everything listed here and in the tutorial and still cant get the ship to move I get a unable to find object:' " attempting to call Function 'setImpulsForce' Everything is in the right place and I copy and paste all the code and still nothing.

I'm not sure if you made the typo just in your post or in your code, but setImpulseForce is missing an E in your quote above. If that was just a typo in your post then I'm sorry I'm not much help.
#66
01/03/2010 (8:33 pm)
Ya it was a typo in the post and not in the script Sorry.
#67
01/03/2010 (8:52 pm)
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/xml.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/properties.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/common.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/audio.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/canvas.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/cursor.cs
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/profiles.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/cursors.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/messageBoxOk.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/messageBoxYesNo.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/messageBoxYesNoCancel.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/messageBoxOKCancel.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/messageBoxOKCancelDetailsDlg.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/messagePopup.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/options.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/remap.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/console.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/NetworkMenu.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/startServer.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/joinServer.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/waitingForServer.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/helpDlg.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/messageBox.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/help.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gui/chatGui.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/screenshot.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/metrics.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/Gui/FrameOverlayGui.gui.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/scriptDoc.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/keybindings.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/options.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/levelManagement.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/projectManagement.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/projectResources.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/common/gameScripts/align.cs.

Torque Game Builder (v1.7.4) initialized...
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/managed/datablocks.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/managed/persistent.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/managed/brushes.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/gameScripts/datablocks.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/gameScripts/guiProfiles.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/gui/mainScreen.gui.
Compiling C:/Users/Jarred/Documents/MyGames/Breakout/game/gameScripts/game.cs...
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/gameScripts/game.cs.
Compiling C:/Users/Jarred/Documents/MyGames/Breakout/game/exec.cs...
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/exec.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/gameScripts/base.cs.
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/gameScripts/theLevel.cs.
Activating DirectInput...
DirectInput joystick failed to enable!
Loading compiled script C:/Users/Jarred/Documents/MyGames/Breakout/game/data/levels/playlevel.t2d.
game/gameScripts/game.cs (45): Unable to find object: '' attempting to call function 'setImpulseForce'

#68
01/03/2010 (11:24 pm)
K I got it working I just compile a new .exe and use that and it work yay!!
#69
01/09/2010 (4:37 am)
Where can I find the images for this tutorial? Also, when I do

Expand the Scripting section and set the class to wallClass (remember, case is important so make sure it you don't call it 'wallclass' or 'Wallclass'.)

it will not allow me to keep the wallClass name as is, it changes it to WallClass. Or am I supposed to see a dropdown menu ?
#70
03/09/2010 (2:50 pm)
Hello, im new to TGB and im trying out this tutorial and taking it slowly but ive read Moving with the Mouse over and over and re-did the scripting parts but the Ship does not move with my mouse, the part where i get confused at is the script.
$thebase.setImpulseForce((%newXPos)*2.0,0);
You break it into long breaks i dont know all the places the scripts are supposed to go into to. If you can help me i would appreciate it. as ive tried getting over this part for some time. Thank you for your time at looking at my post and i look forward to some help in a response.
Thanks
Uldon
#71
03/16/2010 (7:15 am)
heylo! first: great tutorial!! just what i needed

second: i almost finished part1 right before the particles. But the base moves fine to the right but when moved to the left, its slow and clunky. Why? and if the mouse doesnt move, the pad slowllyyyy drift to the right

plz help!

ps: im on windows 7, TGB 1.74
#72
05/24/2010 (1:35 pm)
I had the same problem. Apparently, the cause were some invisible objects that started there since the beginning. After deleting them, the base moves properly. It still moves by itself a little, but to the left this time. Also, if I lower the trigger so it doesn't share space with the shield, the base won't move properly again, but this time to the right. It's weird.
#73
07/02/2010 (9:34 am)
I really appreciate this tutorial, has been an excellent learning vehicle.

Couple of questions:

1. Trying to get the base to move in both x and y direction. Got it to respond to moves in y, but it automatically goes back to bottom. Cannot find out what is doing that! Here is how I modified the movePaddle:

function movePaddle(%worldPosition) {

%newXPos = getword(%worldPosition,0);
%newYPos = getword(%worldPosition,1);
if (%newXPos < 0) { %posXmod=-1; } else { %posXmod = 1; }
if (mAbs(%newXPos) > 95) %newXPos = %posXmod * 95;

if (%newYPos < 0) { %posYmod=-1; } else { %posYmod = 1; }
if (mAbs(%newYPos) > 95) %newYPos = %posYmod * 95;
$thebase.setImpulseForce((%newXPos)*$vmod,(%newYPos)*$vmod);
sceneWindow2D.setMousePosition("0 0");
}

2. Also, have not been able to get ScoreboardGui to be visible! I have searched all forums and tried what I found, but it just doesn't show. I know it gets called and updated, but never is visible. All other Gui's are working fine.

Thanks in advance...
#74
07/02/2010 (10:29 am)
Is it just me or is this the problem?

if (%newYPos < 0) { %posYmod=-1; } else { %posYmod = 1; }

What you're saying there is if the mouse has moved up (%newYPos < 0), move the paddle up. But if the mouse has held still or moved down (%newYPos >= 0), move the paddle down.

Of course, if that's the problem, the paddle should also be moving to the right automatically, since you're using the same logic for horizontal movement.

If you try not to be so tricky with your code and expand it out fully, it can be easier to read and understand what it's doing, for yourself and for others whom you might ask for help.

if (%newYPos < 0)
{
    %posYmod=-1;
} else { // this means "if (%newYPos >= 0)" which includes the mouse not even moving
    %posYmod = 1;
}
#75
07/02/2010 (1:46 pm)
thanks for response. Cleaned up code style. The base object does indeed drift to the right, but much slower than the downward shift.

I modified code, trying to eliminate moves when mouse movement was small. I find that I am getting many mouse movement calls... when mouse is not moving. Values then are x 0.00000 and y 0.00001. New code is below.

But it still doesn't work! The base will move with mouse, but quickly moves back down (in Y direction) and still drifts very slowly to the right! I am at a loss.

-John
====================== code==============


%newXPos = getword(%worldPosition,0);
%newYPos = getword(%worldPosition,1);

echo("mouse moved");

// will limit reaction to values larger than abs(.1)
if (%newXPos < -0.1)
{
%posXmod=-1;
}
else
{
if (%newXPos >0.1)
{
%posXmod = 1;
}
else
{
%posXmod = 0;
}
}

// take this limiter out for now, haven't seen values this high
// if (mAbs(%newXPos) > 95){%newXPos = %posXmod * 95;}
// else {%newXPos = mAbs(%newXpos) * %posXmod);}

%newXPos = (mAbs(%newXpos) * %posXmod);

if (%newYPos < -0.1)
{
%posYmod=-1;
}
else
{
if (%newYPos >0.1)
{
%posYmod = 1;
}
else
{
%posYmod = 0;
}
}

// take this limiter out for now, haven't seen values this high
// if (mAbs(%newYPos) > 95) {%newYPos = %posYmod * 95;}
// else {%newYPos = mAbs(%newYpos) * %posYmod);}

%newYPos = (mAbs(%newYpos) * %posYmod);

echo("move base");
echo("xpos and posXmod");
echo(%newXPos,%posXmod);
echo("ypos and posYmod");
echo(%newYPos,%posYmod);

// if movement on either x or y reached limit, then do move
if ((%newXPos!=0) || (%newYPos!=0))
{
$thebase.setImpulseForce((%newXPos)*$vmod,(%newYPos)* $vmod);
}
sceneWindow2D.setMousePosition("0 0");
}
#76
07/02/2010 (4:09 pm)
It also helps in these forums if you put your code inside code blocks so that it formats it properly.

I can't promise a solution, but if you zip up your project folder I'll take a look at it. You can e-mail it to garagegames (@t) deozaan (d0t) c()m
#77
07/03/2010 (12:13 pm)
Well I figured out what was causing the paddle to go down all the time.

The paddle is made up of two parts, the base and the arch. They were colliding with each other, which was forcing the base down, and since the arch is mounted to the base, the arch went down too.

The reason why it slowly creeped to the right is because it couldn't go down any further so moved very slightly to the right.

The fix is pretty simple. Basically, the arch is the only thing that should be colliding with the ball, so select the base and uncheck all of the "Send/Receive Collisions" and "Send/Receive Physics" boxes.

I also noticed that your ball will slightly creep to the bottom of the screen when it stops for the next level to be loaded. This is because there are a couple of spots in your code where you give the code a ConstantForce on the Y coordinate. If you comment those out then the ball stops as it should.

I haven't looked into getting the GUI to show up. I remember when I was first getting into TGB having trouble with GUIs as well and eventually just giving up on trying to figure them out. As such, I've never gotten a GUI to show up and wouldn't be much help with that problem.
#78
07/03/2010 (2:35 pm)
This helped out quite a bit.Thanks
Page«First 1 2 3 4 Next»