20.03.2013 Views

Introduction to Computer Science with Scratch and App Inventor

Introduction to Computer Science with Scratch and App Inventor

Introduction to Computer Science with Scratch and App Inventor

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Now that we have the mole on the canvas, let’s think about how we are going <strong>to</strong> get him <strong>to</strong> move<br />

around. The way that Whack-a-Mole works:<br />

The mole shows up at r<strong>and</strong>om locations<br />

The mole is only visible for a short period of time<br />

Then the mole moves <strong>to</strong> a new r<strong>and</strong>om location<br />

This means that we will need some sort of way <strong>to</strong> control how long the mole is visible each time it<br />

appears. Luckily, just like <strong>Scratch</strong> had a built in timer that we could use, <strong>App</strong> Inven<strong>to</strong>r has a Clock<br />

element that we can add <strong>to</strong> our program.<br />

Drag a Clock block from the Basic palate<br />

on<strong>to</strong> the MoleMash screen in the Viewer<br />

pane. Instead of showing up on the screen,<br />

the clock will show up underneath in a<br />

section labeled non-visible components.<br />

Now that the clock is added, rename it<br />

MoleTimer. Also, under Properties, set the<br />

interval <strong>to</strong> be 500. The interval is in<br />

milliseconds – there are 1000 milliseconds in<br />

a second, so by setting the interval <strong>to</strong> 500,<br />

our clock will trigger every half-second.<br />

Now we are all ready <strong>to</strong> write the code that will move our mole around the screen! So far we have been<br />

using the interface builder in <strong>App</strong> Inven<strong>to</strong>r. To write code, we need <strong>to</strong> open the Blocks Edi<strong>to</strong>r<br />

To open the Blocks Edi<strong>to</strong>r, click the but<strong>to</strong>n in the<br />

upper right-h<strong>and</strong> corner of your screen. You may see<br />

some security warnings from Windows. Blocks Edi<strong>to</strong>r<br />

is 100% safe <strong>to</strong> run, so click OK or Run on the<br />

warning dialog boxes that pop up.<br />

mbrace Game Development Workbook Page 38

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!