12.07.2015 Views

williams-et-al-1983-apple-ii-computer-graphics

williams-et-al-1983-apple-ii-computer-graphics

williams-et-al-1983-apple-ii-computer-graphics

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

CHAPTER 14-COLLISION COU RSE 163turned off. The next time through, when I = 4, the next bit is <strong>al</strong>so turnedoff. After that the loop is h<strong>al</strong>ted since I has reached the v<strong>al</strong>ue of R%.Therefore, at the end of the loop, V% equ<strong>al</strong>s 12, which in binary is !l/Jl/Jl/Jl/J111/Jl/J. We were trying to check the fourth bit from the right, and we dothat now with line 546. The left-over v<strong>al</strong>ue of I is three, so V% is comparedagainst two to the third, or eight. The only way for V% to be greater thanor equ<strong>al</strong> to eight is for the fourth bit to be on, so the collision flag is s<strong>et</strong>.Whew!I P% V%------ -------------------------------7 128 52 ! 0(.Hl 01006 64 52 ! 0011 01005 32 20 ! 0001 01004 16 4 ! 0000 0100------ -------3 4------------------------Figure 14-2.Figure 14-2 shows the same procedure performed when V% = 52where the fourth bit is off. There should not be a collision indicated . If youfollow the loop through, you will see that the comparison at line 546 fails,so the flag is not s<strong>et</strong>. We told you that it would be rather awkward tocheck single bits!One weakness of this routine (as in the previous one) is that it onlychecks the center of the missile, so it is possible to contact the targ<strong>et</strong> withthe left or right sides and still not d<strong>et</strong>ect a collision. Two trivi<strong>al</strong> modificationsto the routine will cause it to check across the entire width of themissile, but again we leave them for you to discover!When you run this version of the program, you will notice that a collisionis d<strong>et</strong>ected only when the missile actu<strong>al</strong>ly contacts the targ<strong>et</strong>. You will<strong>al</strong>so notice that the animation is slower due to the increased processinginvolved in this scheme-you can't have everythi ng.With a little effort, the BASIC code can be streamlined to enhance theexecution, but the re<strong>al</strong> gain is made by writing this collision d<strong>et</strong>ect inmachine code, som<strong>et</strong>hing we will not cover here.The contact collision d<strong>et</strong>ect is further complicated if you have otherobjects on the screen, such as clouds, where the missile is required toignore the contact. There are two commonly used ways to handle this.In THRESHOLD, a table is kept of the current position for each targ<strong>et</strong>.When any collision is flagged, that table is scanned to see if there is atarg<strong>et</strong> close. If so it is destroyed, and if not the collision is ignored. Oneinteresting side effect is that when two THRESHOLD targ<strong>et</strong>s are close

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

Saved successfully!

Ooh no, something went wrong!