11.07.2015 Views

Here - 1000 BiT

Here - 1000 BiT

Here - 1000 BiT

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.

INSTRUCTOR NOTES 28 ACTION GAMES AND THE FUNCTION KEYSThis long lesson introduces the function keys and the keyboard's box. It shows how tocontrol two simultaneously moving objects on the screen, and how to use PEEK to detect ^collisions. / jUWe develop the CUPID game in this lesson, one piece at a time. It serves as a prototype ^Jfor many different games. This game uses a somewhat abstract method of moving thearrow shot by a diamond while the diamond can still move and be controlled from the ^Jkeyboard. The student may profit from help in understanding how the movements areachieved.^When drawing moving objects, you need to erase each old image before the next image isdrawn.\^jA hit on a target is detected by using PEEK to test the square in front of the projectile. ^If there are several kinds of targets, it is better to test if the square is background. If not,then jump to a subroutine which asks the ASCII number of the target type so appropriateaction can be taken.^jGraphics games may grow to be rather long. BASIC is a little slow for such games. ^J.Maximum speed can be obtained if the working part of the program is first, and theinitialization part is at the end, reached by a call from early in the program. This format ^is discussed in Lesson 32.For maximum speed, avoid repeatedly converting numeric constants to floating point as \^jthe program runs. That is why lines 55, 60 and 65 compare K to variables Fl, F3 and Z0rather than to 4, 5 and 64. This practice is probably the single most important factor in LJobtaining fast programs.The fastest and most versatile way to make graphics is to use the "sprites" in the C-64. ,,This topic is covered later in this book.oQUESTIONS:^1. What ASCII numbers do the function keys have? ^2. How can you detect if a function key has been pressed?3. How can you detect if a key is being held down?4. What number box holds the key being pressed?5. What number is in the box if no key is being pressed? ^j6. Explain how the computer knows to move the arrow and the diamond at the same ^Jtime.156 9o

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

Saved successfully!

Ooh no, something went wrong!