Block Breaker

Most of this is out of a book called Flash Professional 8 Game Development. It’s not a great book but it has value in its massive amounts of examples. I can’t say I’m enjoying Flash gamedev. It’s very kiddy and simple. Sure, you get results but there’s really bad things (maybe just in this book) like soft-references.

Soft references are building a variable on the fly. It’s a rookie thing to do.

var number = 1;
var box = "box_number_" + number; // this makes box_number_1
number++;
var box = "box_number_" + number; // this makes box_number_2 and so on

This way later they can say box._x (the x position) and box._y (the y position) and box changes to be box #1 and then box #2 (so you can place the boxes to hit with the paddle). It’s really a bad idea. I mean it makes sense to the novice but it’s not “serious”. A better way to make two boxes would be to do it like C/Java and use an array.


for (var i = 0; i < 2; i++) {
var box[i]._x = something; // set x of box
var box[i]._y = something; // set y of box
}

Now if I was good, I'd rewrite their example from the book and make it better like this but I'm lazy or just wrong about Flash so I'm posting what I have so far. I made some minor improvements, very minor. I made the score and lives numbers more arcade-y by padding zeros in front. It's a bit more old school imo.

function arcadeScoreFormat(score):String
{
if (score < 10) {
return "0000" + score;
} else if (score >= 10 && score < 100) {
return "000" + score;
} else if (score >= 100 && score < 1000) {
return "00" + score;
} else if (score >= 1000 && score < 9999) {
return "0" + score;
} else if (score >= 10000 && score < 99999) {
return "99999";
}
}

And then the code from the book uses the above function like this:

lives = 5;
score = 0;
lives_txt.text = arcadeScoreFormat(lives);
score_txt.text = arcadeScoreFormat(score);

UPDATE: Whelp, looks like things break on flash players possibly older than 9. And also the fonts are broken on Windows. I’ll make some changes tonight and embed the fonts so it looks right.

UPDATE: Ok looks like embedding fonts worked.

The game is after the jump …

No Comments so far
Leave a comment



Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>