Game Development Community

The Breakout Tutorial - Part Three

by Tetraweb · in Torque Game Builder · 03/29/2008 (5:10 pm) · 39 replies

Part Three of The Breakout Tutorial is now live. This thread is intended for discussion, questions and problems specifically related to Part Three.

Thanks,
Greg
The Breakout Tutorial
Page «Previous 1 2
#1
04/07/2008 (2:32 pm)
TDN is back up again, so now I'm going through part three.

Tiles that Break and Tiles that Don't

Quote:We may clear the tile, but we may also add points, weaken the tile, explode it, etc. We need to replace the line $thetileset.clearTile(%dstRef); with the line hitTile(%dstRef,1.0);
That last part should be: with the line $thetileset.hitTile(%dstRef,1.0);

Particpating Particles <-- Typo in Participating

One More Thing
Quote:We are passing the method the %counter variable, which is what we want to count. We could hard code "live" in the method just, but we are keeping it more flexible this way; we can count whatever kind of tiles we may need to later.
The word "just" doesn't make sense there. Maybe you rearranged the sentence and it should read "We could just hard code..."

Quote:We simply get the x/y size of the tile layer and step through every column of tiles, checking the first word of the tile's custom data, If it matches &counter, we increment %tcount and finally return that value.
I think that should be %counter. That's how it is written in the code.

And here's something that works but I don't exactly understand: In the tile brush the custom data you have is something along the lines of "live 3", but when you use tileCount the string you look for is "LIVE". It works, but I'm not sure why, since it's not a string match. Or is it not case sensitive?

It's coming together very well. Thanks again for the great tutorial!
#2
04/08/2008 (6:02 pm)
Making those corrections now. Thanks again for your proofing this. I really do appreciate your taking the time.

The string comparison operator is not case sensitive. I called it LIVE in the passing function just so it was more like a constant in appearance.

Greg
#3
05/05/2008 (2:37 pm)
Here's a concept for improving the Collision toggle for the base. The reason I don't like it as it is is because you stand the chance of Collision not being re-enabled on the base in time if you bounce the ball into the wall and back in a very close proximity.

So why not set a global var for the base, start with collision on, then with each bounce, check for the target, if it's the base, turn it off, if anything else, turn it on.

...psuedo....

onCollision
  if (%dstObj $= "paddleClasses")
     $base.setCollisionActive(0,0);
  else
     $base.setCollisionActive(0,1);

of course this only works for a single ball... but expand the logic to keep base state for each ball?

This at least eliminates the race condition of using a timer hack...
#4
05/06/2008 (5:35 am)
Not bad, though in Part 6 you will see there could be dozens of balls, so this method would get a bit unwieldy.

Since the base itself can be collided with, not just the shield, even close wall proximity collisions will usually not result in losing a ball, as it will still bounce off the base.

Greg
#5
05/13/2008 (11:29 am)
I have been through part three and I have ommitted whatever I needed to in order to not have sound effects. I have the following error and when I test the game nothing happens once the ball hits the tiles.
Does anyone know what I need to remove from the code I think its part of the sound code which is causing the problem and I don't want sound in the game.

cheers



t2dSceneObject::mount() - Object '1327' is not in a SceneGraph!
t2dParticleEffect::playEffect() - Cannot Play; no emitters!
t2dSceneObject::mount() - Object '1326' is not in a SceneGraph!
t2dParticleEffect::loadEffect() - Cannot Load-Effect; not in a scene!
t2dParticleEffect::loadEffect() - Cannot Load-Effect; not in a scene!
t2dParticleEffect::loadEffect() - Cannot Load-Effect; not in a scene!
Unable to locate audio profile 'shieldhit1'
Unable to locate audio profile 'shieldhit2'
Unable to locate audio profile 'wallhit'
Unable to locate audio profile 'wallhit'
Unable to locate audio profile 'shieldhit1'
Unable to locate audio profile 'wallhit'
Unable to locate audio profile 'wallhit'
Unable to locate audio profile 'wallhit'
Unable to locate audio profile 'wallhit'
Unable to locate audio profile 'wallhit'
Unable to locate audio profile 'wallhit'
Unable to locate audio profile 'wallhit'
Unable to locate audio profile 'wallhit'
Unable to locate audio profile 'wallhit'
#6
05/13/2008 (2:58 pm)
Sandy, it's a complete tutorial. It's not the source of a game that I happen to be sharing. Removing parts of it, or trying to achieve a watered-down version, is not what it's designed for, and you will have no end of troubles, and it will only make you frustrated.

A tutorial is supposed to teach, so I can only recommend, as I did in the first paragraph of the series, that you do it all the way through completely, changing and omitting nothing. Then you can of course strip out whatever you don't want, and make your own game; if you do it that way, you will be much better equipped to make those changes, because you will be better at TorqueScript.

Greg
#7
05/13/2008 (6:09 pm)
Yeah, I've now gone through it and added the sound effects and everything its complete to what the tutorial says. However I'm still having problems. I'm up to just before the title called:
Tiles that Break and Tiles that don't.
Now what I'm trying to achieve is the "wallbang effect". I tested it and nothing happens the ball hits the tiles and no effect are shown. There is something wrong with my theLevels.cs could you possibly show me what is meant to go in there at this stage?


The errors I'm getting are as followed:

Compiling C:/Users/Sandy/Documents/MyGames/Breakout/game/gameScripts/theLevels.cs...
C:/Users/Sandy/Documents/MyGames/Breakout/game/gameScripts/theLevels.cs Line: 12 - parse error
>>> Advanced script error report. Line 12.
>>> Some error context, with ## on sides of error halt:





^function initializeLevel() {

^^$theballs = new SimSet(){};

^^$thebase.loadBall();

^ initializeEffects();

^

$VMODSTANDARD = 2.0;

$vmod = $VMODSTANDARD; // paddle speed factor

$DEFAULTBSPEED = 90;

$levelBspeed = $DEFAULTBSPEED;##
>>> Error report complete.

Loading compiled script C:/Users/Sandy/Documents/MyGames/Breakout/game/gameScripts/theLevels.cs.
Loading compiled script C:/Users/Sandy/Documents/MyGames/Breakout/game/gameScripts/firing.cs.
Loading compiled script C:/Users/Sandy/Documents/MyGames/Breakout/game/gameScripts/tiles.cs.
Loading compiled script C:/Users/Sandy/Documents/MyGames/Breakout/game/gameScripts/audioDatablocks.cs.
Setting screen mode to 1024x768x32 (fs)...
Killing the texture manager...
Making the rendering context not current...
Deleting the rendering context...
Releasing the device context...
Destroying the window...
Changing the display settings to 1024x768x32...
Creating a new full-screen window...
Acquiring a new device context...
Pixel format set:
32 color bits, 24 depth bits, 8 stencil bits
Creating a new rendering context...
Making the new rendering context current...
Resurrecting the texture manager...
Activating DirectInput...
DirectInput joystick failed to enable!
Compiling C:/Users/Sandy/Documents/MyGames/Breakout/game/data/levels/playlevel.t2d...
Loading compiled script C:/Users/Sandy/Documents/MyGames/Breakout/game/data/levels/playlevel.t2d.
t2dSceneObject::mount() - Object '1331' is not in a SceneGraph!
t2dParticleEffect::playEffect() - Cannot Play; no emitters!
t2dSceneObject::mount() - Object '1330' is not in a SceneGraph!
t2dParticleEffect::loadEffect() - Cannot Load-Effect; not in a scene!
game/gameScripts/theLevels.cs (5): Unable to find object: '' attempting to call function 'countTiles'
The live tile count is
game/gameScripts/theLevels.cs (5): Unable to find object: '' attempting to call function 'countTiles'
The live tile count is
Con::execute - 1318 has no namespace: onSafeDelete
Setting screen mode to 1024x768x32 (w)...
Killing the texture manager...
Making the rendering context not current...
Deleting the rendering context...
Releasing the device context...
Destroying the window...
DirectInput deactivated.
Changing to the desktop display settings (1680x1050x32)...
Creating a new window...
Activating DirectInput...
Acquiring a new device context...
Pixel format set:
32 color bits, 24 depth bits, 8 stencil bits
Creating a new rendering context...
Making the new rendering context current...
Resurrecting the texture manager...
Shutting down the OpenGL display device...
Making the GL rendering context not current...
Deleting the GL rendering context...
Releasing the device context...

Would really appreciate it if you could tell me what the problem is as I have followed everything on the tutorial.
#8
05/13/2008 (6:33 pm)
Can you zip up your whole project and email it to me. My public email is in my profile.

Greg
#9
05/13/2008 (11:21 pm)
Just an added note of what to look for while Tetraweb gets the project and looks it. The "# #" debug tags for error finding are rarely at the source of the actual problem. Take a look at the whole function/method containing the tags.

If you aren't using an IDE I'd highly suggest it. Your objects/vars/funcs will be color coded and the object encapsulation (parentheses and brackets) will be visually represented and help greatly in identifying syntax errors.

Codewaver(Free) = www.torquedev.com

Torsion(Not Free) = www.garagegames.com/products/106/
#10
06/22/2008 (1:41 am)
I'm loving this tutorial!

Having a few little problems that are kind of annoying...

Sometimes the ball goes right through the paddle. It's not a case of hitting the ball, ball hitting the wall and coming straight back to the paddle (I changed the collision to be off for .25 seconds instead of .5) - I actually hit it, then it goes up, hits a brick or wall then top of screen, then comes all the way back down again, and goes right through the paddle! Sometimes it then bounces back up off the base, other times it just goes right on through. It especially does this if I happen to be moving fast enough to give the ball that extra power (which NEVER happened before so I dropped that speed check right down to 80).

Here's the code for my ball collision - if someone can see anything wrong with it, please let me know:

if (%dstObject.class $= "paddleClass") 
   {
      %dstObject.schedule(250, "makeHittable");
      %dstObject.setCollisionActive(0, 0);
      %speed = getWord($theBase.getlinearVelocitypolar(), 1);
      if (%speed > 80) 
      {
         %force = t2dVectorScale(%normal, (-%speed * 2));
         %srcObject.setImpulseForce(%force, false);
      }
      %r = getRandom(1, 2);
      %hitsound = "shieldhit"@%r;
      alxPlay(%hitsound);
      
      $wallbang.setPosition(%points);
      $wallbang.playEffect(false);
   }

Also, it's REALLY hard for me to control the ball's angle - it seldom goes in the direction I want it to. Is this just a matter of adding some more points on the collision poly? Or is there something in the above that might cause it? (maybe this problem is related to the one above)

@Sandy, in your code above (if you're still wondering what was wrong with it, even though it's been over a month), there seems to be a missing closing } for the initializeLevel() function.
#11
06/24/2008 (11:24 am)
I'm having an issue with "Painting with Brushes." I've downloaded the zip file, put the three png files in the images file, replaced the brushes.cs file in the managed file, saved all of that, exited the TGB editor after saving, and reloaded it, but under the brush dropdown it's empty. I've repeated this step two or three times with the same affect. What happens is the brushes.cs file, when I replace it and save the work it reverts back to the old brushes.cs file. What is happening and how can I fix that?

Mike
#12
06/24/2008 (1:29 pm)
I finally got it I missed the tile edit map, save layer step and took out the brushes.cs.dos file and it all compiled correctly after I debugged it. :)

Mike
#13
08/12/2008 (10:52 pm)
Yeah, it seems like TGB keeps regenerating the brushes.cs file unless you do a full exit out of the builder, NOT just a "reload"

Thanks as again, Greg, for the kickass tutorial.
#14
08/23/2008 (10:48 pm)
The following lines are not returning a value where they are:
$liveTileCount=$thetileset.countTiles("live");
      echo("The live tile count is " @ $liveTileCount);

they should instead be put at the end of tileClass::onLevelLoad
#15
08/23/2008 (10:50 pm)
I had no hassles with this - worked just as it should have for me. Did you check your countTiles function?
#16
08/24/2008 (11:46 am)
The following lines are not returning a value where they are:
$liveTileCount=$thetileset.countTiles("live");
      echo("The live tile count is " @ $liveTileCount);

they should instead be put at the end of tileClass::onLevelLoad
#17
10/05/2008 (3:33 pm)
The fix for the paddle/ball sticking worked ok for me. I have noticed that if you have the delay set to 500 (0.5sec), the ball can hit the base sometimes instead of the paddle. A much shorter delay might work well, but I haven't messed with that yet. As others have noted, the ball also gets stuck to the walls & tiles sometimes. Here's what I did to keep the ball from sticking to the walls & tiles.

In ball.cs in the onCollision function, put the following code after the else if line with "wallClass" in it:
//fix for the ball getting stuck on the wall sometimes
%dstObject.schedule(20,"makeHittable"); //set to 20ms - adjust as low as possible
%dstObject.setCollisionActive(0,0);

In the same onCollision function, put the following code after the else if line with $thetileset in it:
//fix for the ball getting stuck on the tiles sometimes
%dstObject.schedule(20,"makeHittable"); //set to 20ms - adjust as low as possible
%dstObject.setCollisionActive(0,0);

In tiles.cs, add the following function (I put mine at the end of the file):
// makeHittable sets collisions to active - this is called after a small delay after a ball to wall collision
function tileClass::makeHittable(%this){
	%this.setCollisionActive(0,1);
}


Create a new file in game/gameScripts/ called wall.cs. Put the following function in that file:
// makeHittable sets collisions to active - this is called after a small delay after a ball to wall collision
function wallClass::makeHittable(%this){
	%this.setCollisionActive(0,1);
}

Finally, add this in [b]exec.cs[b] after the exec base.cs line:
exec("~/gameScripts/wall.cs");

The above changes work for me, but I haven't tested it with more than one ball.

I've also noticed that when I have a high velocity of the base, the ball usually continues down past the base after a collision. I changed the sign on %speed and it seems to have fixed it. Here's how a code snip from onCollision in base.cs:
if (%speed > 150) { 
//			%force = t2dVectorScale(%normal,(-%speed*2));  //note - sign on speed.  Hmmmm.
			%force = t2dVectorScale(%normal,(%speed*2)); //removed - sign on %speed
		 	%srcObject.setImpulseForce(%force, false);
		}

@Shaz I was seeing the same thing with the control of the angle the ball went after a collision with the paddle. I added about twice as many points to the collision polygon & it's now much more playable.

@Greg Thanks for the great tutorial!
#18
10/05/2008 (6:58 pm)
Hi Bryan and thanks for your post, now i realize a well fix for those problems, but i recently remake the game and i change the triggers of the walls with static sprites, and works great, and i use the playground tutorial behavior for the paddle, and everything works nice, now im adapting the code of this tutorial to my game and everything is going well.. the strange thing is that i put the triggers again just to see if i can realize what is the problem.. and is gone.. really i don't know how, but i was able to recreate the error, by resizing the ball to a minor value so i guess the problem comes that way.
by the way thanks for the sign tip, i didn't realize it.
#19
04/07/2009 (12:29 am)
sorry my fault
#20
05/24/2009 (11:30 am)
user error, nvm.
Page «Previous 1 2