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
#21
05/11/2008 (5:32 pm)
I checked all of that and everything is ok. I also get the following line:

Missing file: C:/Users/Sandy/Documents/MyGames/Breakout/game/gameScripts/exec.cs!

The file shouldn't be missing its in that very file and there is nothing mispelt.
#22
05/11/2008 (6:05 pm)
The exec.cs file should be in the /game/ directory, not deeper in the /game/gameScripts/ directory. So it is not finding that to exec, and therefore not exec'ing the base.cs file.

Greg
#23
05/12/2008 (2:48 am)
Yeah thats where I put the file before and still doesn't work :(
#24
05/12/2008 (4:44 am)
I did away with the whole exec.cs file because it seems unecessary when the exec parts can be put in the main.cs. The problem I have now is:
Missing file: C:/Users/Sandy/Documents/MyGames/Breakout/game/gameScripts/base.cs!
Missing file: C:/Users/Sandy/Documents/MyGames/Breakout/game/gameScripts/theLevels.cs!

They are both in those files...
#25
05/12/2008 (10:39 am)
Can't wait to try out this tutorial. Thanks for the resource.
#26
05/12/2008 (3:24 pm)
Sandy, see my post here:
http://www.garagegames.com/mg/forums/result.thread.php?qt=73662

Greg
#27
05/21/2008 (8:10 pm)
Quick note about a line when you first start the scripting portion. You say to:

"Create a new file in your /Breakout/game/ directory called exec.cs and add the following line to it:"

But shouldn't it be:

"Create a new file in your /Breakout/game/gameScripts directory called exec.cs and add the following line to it:"

After changing what directory the exec.cs file was in, my paddle started moving, where it wasn't before.
Thanks for the great tutorial!
#28
05/21/2008 (9:39 pm)
Tallyn, it sounds like you just entered the wrong path in your game.cs when you "exec'ed" the exec.cs file.

It does work the way Tetraweb wrote it in the tutorial.
#29
05/22/2008 (4:45 am)
Your exec.cs file should definitely be in /Breakout/game/ and all the lines in it are in the form of
exec("./gameScripts/base.cs");

You should carefully double check your file layout to make sure it matches this:
www.tetraweb.com/tgb/layout.png
Greg
#30
05/22/2008 (5:35 am)
Yeah that sounds like the problem I had. I followed the tutorial too carefully it seems.
#31
05/22/2008 (4:55 pm)
Yeah the tutorial says

exec("./base.cs");

not

exec("./gameScripts/base.cs");

Tetraweb may want to change it in the tutorial.
#32
05/22/2008 (5:36 pm)
Unfortunately, that's one of the problems with a Wiki -- anyone can edit it.

It was originally correct, but someone thought they were 'fixing' it and so edited it. Which of course, broke it.

I have set it back to the original now, so everything says ./gameScripts correctly.


Greg
#33
05/23/2008 (12:38 am)
Does anyone elses paddle get pushed all the way down to the bottom of the screen so that you can barely see the particle effects? No matter where I put the base it always starts at the very bottom of the screen.
#34
05/23/2008 (5:29 am)
What is your screen resolution (outside of TGB)?

Greg
#35
05/23/2008 (10:58 pm)
1680 x 1050
#36
05/30/2008 (6:38 pm)
I am stuck on the first page of the tutorial and I can not for the life of me figure out why the base will only move to the right. I tried copying and pasting the code directly from the tutorial and it still doesn't work.
#37
05/31/2008 (3:13 am)
I found out what was wrong. The collision settings of the paddle and the base are conflicting. This can be resolved with a little group manipulation, but I just decided to get rid of the base collisions all together and extend the paddle polygon to encompass the base (as the paddle is probably the part that matters).
To make it even cleaner I'm thinking about mounting the base to the paddle (rather than vice-versa) and moving the BaseClass settings to the PaddleClass. Since the base is just for show (so far anyway) I don't see a need for a BaseClass at all. Maybe it has a larger role later in the tutorial? I'll have to work through the rest of the tutorial to see if these changes disrupt anything.
#38
05/31/2008 (6:01 am)
Wes, double check your collision settings for the base and paddle, make sure you followed the text of the tutorial, not just the code. It is designed to work just as it is written.

I don't suggest you make the changes you are suggesting, the base does play a role later. It will make things difficult for you in later parts of the tutorial.

Greg
#39
06/21/2008 (1:03 am)
I'm having both of the problems listed above. It's not the code at fault. I typed it all in, had the issues, so replaced it with a copy/paste of what's in the tutorial. Still getting the ship disappearing off the screen at the bottom, and it's not responding well to the mouse.

First time, it WOULD move to the right when I moved the mouse in that direction. But when I moved the mouse left, the ship moved VERY slowly and only a very short distance, then started moving slowly back to the right again. If I left the mouse alone, the ship slowly dragged to the right.

Knowing it wasn't the code, I deleted everything on the level and started again. Same thing happened, only this time it moved LEFT when I moved left, but ignored me when I moved right!

Not really understanding what Wes had explained, I did my own experimenting, and it did indeed appear that the base and the arch were colliding and causing the problem. I dismounted the arch and moved it right away, and the base appeared in the right spot (didn't disappear off the screen), and it responded perfectly to the mouse movements. I mounted the arch, and it got all sluggish and stubborn again.

Your tutorial doesn't say to set the layer or group of the arch, so I left them both at 0. But changing the arch to be on the same layer and in the same group as the base, then changing the base to NOT collide with objects in group 2, completely solved the problem. And NOW I understand what Wes was saying, and am guessing you're going to tell me that's going to cause issues down the track, so here's exactly what I've got set up for both of them (which I believe is correct according to the tutorial, but is causing the issues), and you may be able to tell me if they're right or not...

Base
Scene Object:
Position (0.000 64.819)
Size - width 25.000 height 12.500
Layer - 1
Group - 2
all others are untouched

Collision:
Send Collision, Receive Collision, Send Physics, Callback and Superscribe Ellipse are all checked. Receive Physics is unchecked. Detection Mode is Polygon and Collision Response is Clamp. All collision layers and groups are selected.


Arch
Scene Object:
Position (-0.063 63.344)
Size - width 25.000 height 27.429
Layer - 0
Group - 0
all others are untouched

Collision:
Receive Collision, Callback and Superscribe Ellipse are checked (you didn't say to uncheck this, so I left it as the default). All others are unchecked. Detection Mode is polygon and collision response is Clamp. All collision layers and groups are selected.


As an alternative, changing the collision polygons on both the arch and the base so the two don't overlap, makes them move correctly too. I'll proceed with that, and leave the layers and groups as you suggest, and see what further trouble I can get into...
#40
07/17/2008 (6:19 pm)
I had similar issues with sluggish/bumpy mouse movement in one direction. After playing with the collision poly, I got one to work even though theArch's poly overlaps theBase's. Here's the CollisionPoly setting from my playlevel.t2d file:

CollisionPolyList = "-0.869 0.118 -0.815 -0.157 -0.648 -0.388 -0.403 -0.565 -0.177 -0.683 0.172 -0.688 0.467 -0.570 0.707 -0.383 0.830 -0.147 0.918 0.113";

And for reference, here's the one that did NOT work:

CollisionPolyList = "-0.859 -0.005 -0.791 -0.201 -0.599 -0.422 -0.334 -0.599 -0.074 -0.702 0.221 -0.707 0.442 -0.575 0.643 -0.417 0.815 -0.167 0.894 -0.020";