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.

To get a r<strong>and</strong>om number, we use the pick r<strong>and</strong>om block from the<br />

Opera<strong>to</strong>rs menu. The Opera<strong>to</strong>rs menu (bright green blocks)<br />

contains many mathematical <strong>and</strong> logical operations <strong>and</strong><br />

comparisons that will be very useful in programming.<br />

To use the pick r<strong>and</strong>om block, you specify two numbers <strong>and</strong> then<br />

<strong>Scratch</strong> will r<strong>and</strong>omly pick a number between those two numbers.<br />

Since we want <strong>to</strong> r<strong>and</strong>omly position our poofs on the stage, we<br />

want <strong>to</strong> r<strong>and</strong>omly pick an x value <strong>and</strong> a y value <strong>to</strong> move the poofs<br />

<strong>to</strong>. What should the range of values be for r<strong>and</strong>omly picking an x<br />

<strong>and</strong> r<strong>and</strong>omly pick a y?<br />

Remember the coordinate system underlying the stage?<br />

The x values on the stage range from -240 <strong>to</strong> 240<br />

The y values on the stage range from -180 <strong>to</strong> 180<br />

*HINT* When you are using new blocks in <strong>Scratch</strong>, remember <strong>to</strong> notice the shape of the block, this will<br />

give you a clue as <strong>to</strong> where the blocks can be used.<br />

If we add a go <strong>to</strong> x: y: block <strong>with</strong> our<br />

pick r<strong>and</strong>om blocks included, our cheesy<br />

poofs will show up at a new location<br />

every time we start our program over.<br />

Give it a try <strong>and</strong> see how it works.<br />

Remember, you still need <strong>to</strong> s<strong>to</strong>p (click<br />

the red s<strong>to</strong>p sign) the program <strong>and</strong><br />

restart (click the green flag) the program<br />

<strong>to</strong> see the cheesy poofs repositioned on<br />

the screen.<br />

What would make the game more fun? It would be lots more fun if we didn’t have <strong>to</strong> restart the<br />

program every time we wanted the poofs <strong>to</strong> reappear. How could we change our program so that every<br />

time the dinosaur eats the poofs, they reappear at a new r<strong>and</strong>om location on the screen?<br />

mbrace Game Development Workbook Page 20

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

Saved successfully!

Ooh no, something went wrong!