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
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
#2
03/30/2008 (12:13 am)
Thanks, this will be very usefull for a lot of people.
#3
I'm coming back to TGB after a hiatus. This looks like a great way for me to get back into the swing of things. Thanks for all the hard work you no doubt put into this. You've gone above and beyond to help you fellow TGBers. Thank you.
04/01/2008 (5:54 pm)
@Tetraweb:I'm coming back to TGB after a hiatus. This looks like a great way for me to get back into the swing of things. Thanks for all the hard work you no doubt put into this. You've gone above and beyond to help you fellow TGBers. Thank you.
#4
04/01/2008 (6:09 pm)
Thanks alot for this. The more tutorials we get, the better.
#5
In the code examples to hide and show the mouse, you use "canvas.hidecursor()" and "canvas.showcursor" and that didn't work for me because Canvas needs to be capitalized. So I capitalized it in both of those examples.
I then noticed a small typo. "First, we loading the new effect..." (emphasis added) I changed it to "First, we load the new effect..."
04/05/2008 (12:09 am)
I made a tiny edit to the wiki before I saw that you wanted total control over changes. Here's what I changed:In the code examples to hide and show the mouse, you use "canvas.hidecursor()" and "canvas.showcursor" and that didn't work for me because Canvas needs to be capitalized. So I capitalized it in both of those examples.
I then noticed a small typo. "First, we loading the new effect..." (emphasis added) I changed it to "First, we load the new effect..."
#6
Technically there's nothing wrong with this, but throughout the tutorial you seem to name your variables by a lowercase first word, and uppercase of any other words. So in my opinion, the variable "$thebase.myTrail.isplaying" should be "$thebase.myTrail.isPlaying"
And I just noticed that $thebase perhaps should also be $theBase.
In this section of code, you've not capitalized a lot of things, such as getWord, getLinearVelocityPolar(), and playEffect.
And finally, you haven't been consistent in the way you use opening and closing brackets. At the beginning of the tutorial you wrote functions with brackets on separate lines. For example:
But by the end most of your starting brackets were on the same line as the function or conditional statements. For example:
I admit this is a little nitpicky, but I think that at least the capitalization should be important--especially with TorqueScript's built in functions--and especially because you stress at the beginning of the tutorial the capitalization is important.
Thanks for taking the time and effort in making such a great tutorial! I hope this information helps improve it.
I'll most likely start part 2 tomorrow.
04/05/2008 (12:35 am)
I just finished part 1 of the tutorial and I also noticed that at the end, in the particle effects, you have some more case inconsistencies.%trail = new t2dParticleEffect() {
scenegraph = %scenegraph;
effectFile = "~/data/particles/basetrail.eff";
useEffectCollisions = "0";
effectMode = "INFINITE";
effectTime = "0";
size = "15.000 15.000";
};
%linkIndex = %trail.mount($thebase, "0.000 1.000");
%trail.playEffect(false);
$thebase.myTrail = %trail;
$thebase.myTrail.isplaying=true;Technically there's nothing wrong with this, but throughout the tutorial you seem to name your variables by a lowercase first word, and uppercase of any other words. So in my opinion, the variable "$thebase.myTrail.isplaying" should be "$thebase.myTrail.isPlaying"
And I just noticed that $thebase perhaps should also be $theBase.
function baseClass::onTimer(%this) {
%speed = getword(%this.getlinearVelocitypolar(),1);
if ( (%this.myTrail.isplaying==true) && (%speed < 5) ) {
%this.myTrail.stopEffect(true,false);
%this.myTrail.isplaying=false;
} else if ( (%speed > 5) && (%this.myTrail.isplaying==false) ) {
%this.myTrail.playeffect(false);
%this.myTrail.isplaying=true;
}
}In this section of code, you've not capitalized a lot of things, such as getWord, getLinearVelocityPolar(), and playEffect.
And finally, you haven't been consistent in the way you use opening and closing brackets. At the beginning of the tutorial you wrote functions with brackets on separate lines. For example:
function functionName()
{
// code here
}But by the end most of your starting brackets were on the same line as the function or conditional statements. For example:
if (%val) {
// code here
}I admit this is a little nitpicky, but I think that at least the capitalization should be important--especially with TorqueScript's built in functions--and especially because you stress at the beginning of the tutorial the capitalization is important.
Thanks for taking the time and effort in making such a great tutorial! I hope this information helps improve it.
I'll most likely start part 2 tomorrow.
#7
You're right about the capitalization; I think I paid more attention to that detail in the later tutorials. And it is important, especially for beginning users.
The lowercase "canvas" worked with no problem on my Win XP with 1.6 and 1.7.2, as well as on my Mac. Thanks for changing that though, if it did not work on your system.
Greg
04/05/2008 (6:00 am)
Thanks, Deozaan.You're right about the capitalization; I think I paid more attention to that detail in the later tutorials. And it is important, especially for beginning users.
The lowercase "canvas" worked with no problem on my Win XP with 1.6 and 1.7.2, as well as on my Mac. Thanks for changing that though, if it did not work on your system.
Greg
#8
04/05/2008 (6:06 am)
TorqueScript is case insensitive, but I will usually change the capitalization of a variable if I capitalized it wrong; just because I can.
#9
I've been meaning to stop into this thread just to say "awesome!" It is a really solid tutorial (though, admittedly, I haven't yet had the chance to meander through it entirely). I imagine it will help a lot of people to get a grasp on TS.
Out of curiosity, how long did it take you to conjure up the entire tutorial? You mention that it was sort of a "spontaneously" arising creature, born your own notes and what may. Once you saw the potential for it and made the decision to craft it into a tutorial, how much time do you think it required to get to the point you have now?
Seriously good stuff!
04/07/2008 (3:01 pm)
Tetraweb:I've been meaning to stop into this thread just to say "awesome!" It is a really solid tutorial (though, admittedly, I haven't yet had the chance to meander through it entirely). I imagine it will help a lot of people to get a grasp on TS.
Out of curiosity, how long did it take you to conjure up the entire tutorial? You mention that it was sort of a "spontaneously" arising creature, born your own notes and what may. Once you saw the potential for it and made the decision to craft it into a tutorial, how much time do you think it required to get to the point you have now?
Seriously good stuff!
#10
TGB beginners can never get enough detail like this, it's a great help in getting started...
But maybe if is possible for you at the end of each tutorial, can you put the complete script,
so people like me can compare our work with your scripting.
I doing the first tutorial and every thing is OK but i can stop the effect below the base ,I
thing i doing something wrong but i don't know what.
I m doing two time whit same result.
appreciated if is possible for you.
Thanks a lot in advances.
This is a wonderful tuto
Thanks again
04/14/2008 (5:12 pm)
Hi All, I 'm new to the scripting and to torque GB.TGB beginners can never get enough detail like this, it's a great help in getting started...
But maybe if is possible for you at the end of each tutorial, can you put the complete script,
so people like me can compare our work with your scripting.
I doing the first tutorial and every thing is OK but i can stop the effect below the base ,I
thing i doing something wrong but i don't know what.
I m doing two time whit same result.
appreciated if is possible for you.
Thanks a lot in advances.
This is a wonderful tuto
Thanks again
#11
I'm not sure what you mean exactly with your error, " stop the effect below the base" but I would like to help. Can you either describe it in more detail or zip up your project and email it to me (check my profile) and I will take a look.
Greg
04/14/2008 (5:47 pm)
Hi, it's a little more complicated than that, because the scripts are spread out among several separate .cs files; also I am afraid it would encourage people to simply skip to the end and copy all the scripts without doing the tutorial. I put too much effort into it to not have people learn from it. :)I'm not sure what you mean exactly with your error, " stop the effect below the base" but I would like to help. Can you either describe it in more detail or zip up your project and email it to me (check my profile) and I will take a look.
Greg
#12
I had a similar problem (and several others throughout the tutorial) but it just ended up that I didn't use a semicolon or some other simple coding error on my part. Usually what helped me most was checking the console and/or trying to run the script from Torsion, since it will catch most errors like that and ask if you want to fix them first.
04/14/2008 (10:02 pm)
I think what he means is that the particle effect won't stop when the base isn't moving.I had a similar problem (and several others throughout the tutorial) but it just ended up that I didn't use a semicolon or some other simple coding error on my part. Usually what helped me most was checking the console and/or trying to run the script from Torsion, since it will catch most errors like that and ask if you want to fix them first.
#13
Greg
04/15/2008 (5:03 am)
Yes,Deozaan is right. Concarster please check the console (ctrl ~) when running the game and let me know if there are any errors there.Greg
#14
I'm on part one of this tutorial and for some reason when I go to do the first test the sprite won't move at all. I've followed the tutorial through twice thoroughly and I can't see where I'm going wrong. Any ideas?
Thanks
05/10/2008 (10:00 am)
Hey,I'm on part one of this tutorial and for some reason when I go to do the first test the sprite won't move at all. I've followed the tutorial through twice thoroughly and I can't see where I'm going wrong. Any ideas?
Thanks
#15
What version of TGB are you using? It may not be relavent but you never know. Also, make sure with each step of the tutoral, when you launch the game to test it, check the console for errors (Ctrl+~ will toggle the console up); errors will be in red. If you have any, don't progress through the tutorial until you've cleared them up.
Hope this helps.
05/10/2008 (10:04 am)
@SandyWhat version of TGB are you using? It may not be relavent but you never know. Also, make sure with each step of the tutoral, when you launch the game to test it, check the console for errors (Ctrl+~ will toggle the console up); errors will be in red. If you have any, don't progress through the tutorial until you've cleared them up.
Hope this helps.
#16
I'm running version 1.5.1. I can't get on the console for some reason, just won't work.
05/10/2008 (10:16 am)
HeyaI'm running version 1.5.1. I can't get on the console for some reason, just won't work.
#17
Also, for me, in the Windows version of TGB, Just pressing ' will bring up the console. That's the button next to the 1, that also has this symbol on it: ~
05/10/2008 (1:45 pm)
I believe the tutorial was made for version 1.7.2.Also, for me, in the Windows version of TGB, Just pressing ' will bring up the console. That's the button next to the 1, that also has this symbol on it: ~
#18
The first parts of the series will work fine on 1.5.1, so there is almost certainly a typo of some sort causing you trouble. This should be evident in the log.
For those wondering about the long delayed super fun Part 6 of this series, my wife had a baby 5 weeks premature, so I have been a little busy. I'm back now, so I promise it won't be long now.
Greg
05/11/2008 (12:50 pm)
You can also check the console.log file which will be written to the main Breakout directory.The first parts of the series will work fine on 1.5.1, so there is almost certainly a typo of some sort causing you trouble. This should be evident in the log.
For those wondering about the long delayed super fun Part 6 of this series, my wife had a baby 5 weeks premature, so I have been a little busy. I'm back now, so I promise it won't be long now.
Greg
#19
game/gameScripts/game.cs (41): Unable to find object: '' attempting to call function 'setImpulseForce'
On this line is:
$thebase.setImpulseForce((%newXPos)*2.0,0);
Congratulations on your new born.
05/11/2008 (1:57 pm)
Well I re did the whole of part 1 in 1.7.2 and now the ship moves very slowly to the right without moving my mouse. The console still wont come up even with the ' button. Checked the console file and this line is repeated hundreds of times:game/gameScripts/game.cs (41): Unable to find object: '' attempting to call function 'setImpulseForce'
On this line is:
$thebase.setImpulseForce((%newXPos)*2.0,0);
Congratulations on your new born.
#20
Look in base.cs, the beginning should look like this:
Greg
05/11/2008 (4:22 pm)
So it sounds like the global $thebase is not set, since it can't find the object ''Look in base.cs, the beginning should look like this:
function baseClass::onLevelLoaded(%this, %scenegraph)
{
$thebase = %this;then make sure you are pulling base.cs in by having this in your exec.cs file:exec("./gameScripts/base.cs");Greg
Torque Owner Terry
Default Studio Name