Archive for October, 2009

No More Errata!

Tom and I finished the last chapter (with coding) in the 2d Game Building for Teens book and didn’t find any further problems. Well, except that wherever you see $MeBatty replace it with $BattyPlayer.

After we got done we added a couple more things:

  • Tom added a second ghost so it’s a little harder.
  • We made it so Batty can fire to the left and to the right.

Later this weekend I’m planning on adding an effect of some kind for when Batty gets hit by the ghost, a limit on the lives Batty has, and a way to keep score of the number of ghosts Batty has killed.

And then it will almost be a “real” game! =:)

2D Game Building for Teens – Errata #4

There are not too many things wrong in chapter 8 of 2D Game Building for Teens — but the things that are wrong will keep your game from working.

First, on page 218 the line of code that looks like this:

function BattyPlayer::createDeathray()

…should look like this:

function BattyPlayer::createDeathray(%this)

If you don’t pass in a reference to $BattyPlayer your deathray will never show up. That code is also shown again on page 222 at the top.

At the top of page 219, as part of the playerDeathray::fire function, the lines of code should be like this:

        %this.setWorldLimit(kill,"-50 -30 40 30");
	%this.setLinearVelocityX(%this.missileSpeed);
	%this.setPositionX(%this.player.getPositionX()+4);
	%this.setPositionY(%this.player.getPositionY()+7);
	%this.setImageMap(deathrayImageMap);
	%this.setSize("8 4");//approximately half size of original graphic
	%this.setCollisionActive(true,true);
	%this.setCollisionPhysics(false,false);
	%this.setCollisionCallback(true);

Some of those lines are the same as in the book, I just pasted the entire chunk here to make it easy for you to grab the whole block.

I did make a couple changes, however.

The book uses %this.setPosition(%this.player.getPosition()) which is fine if you want to set the deathray to the same position as Batty — but the raygun is supposed to be shooting, not the bat. So I used setPositionX and setPositionY so I could add an offset for each and make it look like the deathray was actually coming from the gun.

The other change is in the setSize line – the book said to set the values at 83 and 38, but for me that made a HUGE deathray, the size of half the screen. The values shown above fixed things.

Why that kind of change, after all, we’re only trying to set the size of a known graphic?

I’ll explain why in another post here later. =:)

That code above is also shown on page 222 as part of the entire listing.

One more thing, as in previous chapters, $BattyPlayer is mistakenly referred to as $MeBatty in the code on page 220 — make sure wherever you see $MeBatty you change it to $BattyPlayer.

Firing The Deathray

Looks like Tom and I *almost* have the problems whipped in the “deathray” chapter of the book. I have it working, but don’t want to post the fixes until after I understand *why* the changes work– because the problem isn’t just typos,it goes a little deeper than that.

The only things left we have to finish the book are making the ghosts explode and adding some sound.

After that the plan is to add a little more code to make the game more fun/challenging:

1. More than one ghost on screen at a time.
2. Ghosts come from both sides of the screen.
3. Score counts up when ghost is killed.

And maybe even a couple more things…we shall see.=:)

More From the Batty Book

I finally got off the computer long enough to give Tom a shot at it a few days ago and he dove into the next chapter of 2D Game Building for Teens. In that chapter he gives Batty a raygun and can shoot the ghosts before they bump into him.

Well, that’s what’s supposed to happen, anyway. =:)

After fixing a few typos that Tom introduced I got the program to the point where I realized the code in that chapter wasn’t able to work right out of the book.

I’m going through it now and banging my head against things I just don’t know about in TorqueScript. I found one big problem fairly quickly, but the code still isn’t working, so now I’m down to looking at what should be happening rather than at the code itself.

Because I don’t even know if the logic is correct — I’d hate to be looking for typos when the problem is bigger than that.

More later when I have something positive to report…

Jay