by David J. Malan <malan@post.harvard.edu>
Printer-Friendly Version of Tutorial

« Previous | Table of Contents | Next »

Oscartime's Oscar Sprite

Oscartime's Oscar sprite uses three threads to keeps track of a player's score and the announcement thereof. The first of these threads provides the game's overall framework:



Essentially, this thread dresses the sprite in its default costume (that of a closed trash can); moves the sprite to its permanent location; sets the global, Boolean variable (named playing) to true, so that the other sprites know a game's in progress; and then plays Oscar's song whilst the player plays the game. Once that song ends (after 134 seconds), the sprite sets the global, Boolean variable (named playing) to false, so that the other sprites know the game's over; announces the player's score, then kills all threads.

The sprite's second thread keeps track, moment by moment, of a player's score:



Essentially, every time some other sprite signals an event (named scored), the above thread handles that event by setting a local, Boolean variable (named scoring) to true, so that the sprite's other thread knows not to change Oscar's costume while this thread is doing so, thereafter popping Oscar out of his trash can to announce the player's current score.

The sprite's third thread induces the lid of Oscar's trash can to rise anytime trash is dragged near it:



Essentially, the lid rises so long as a game is in progress, the sprite isn't already changing Oscar's costume in order to announce the player's score, and some sprite is within 40 pixels of Oscar's trash can.

That's pretty much how Oscartime works. The game's implementation involves lots of blocks, to be sure. But, ultimately, the game is just the result of piecing together building blocks of programming.

Now, though Scratch does support programmatic constructs common to many programming languages, it doesn't do everything. In this tutorial's conclusion, let's survey some programmatic constructs that Scratch doesn't have.

« Previous | Table of Contents | Next »