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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 14-COLLISION COU RSE 16 1<strong>al</strong>ways miss the spider so you do not have to check either coordinateagain, just l<strong>et</strong> the missile make its way to the top of the screen. This sort ofspeci<strong>al</strong>ized adjustment can often streamline your animation.The box m<strong>et</strong>hod used in the example is fairly simple, but it is a littlesloppy since it declares a collision based on some imaginary squ are insteadof actu<strong>al</strong> contact with the targ<strong>et</strong>. Further, we only checked for the centerof the missile, and the center may actu<strong>al</strong>ly miss the spider when one of theedges hits it. Unfair! If you have ever played a game which has sloppycollision d<strong>et</strong>ection (and there are a bunch of them) you know how frustratingthat can be.Checking across the full width of the missile is pr<strong>et</strong>ty easy, so we leav<strong>et</strong>hat to you. The problem of d<strong>et</strong>ecting an actu<strong>al</strong> contact is more interesting.To accomplish that, you will have to take a PEEK at Hi-Res memory to seeif the missile is about to move onto a dot which is <strong>al</strong>ready turned on. (Inthis example, the only dots turned on are in the targ<strong>et</strong>.) De<strong>al</strong>ing directlywith memory from BASIC is <strong>al</strong>ways complex, and it g<strong>et</strong>s worse because weneed to look at ind ividu<strong>al</strong> bits. Type the following changes to the existingprogram.DEL 4, 75 GOSUB 1 : REM CALC Y ADDR .515 Q% = M I 7:R% = M-7 * Q% :R% R% + 1536 V% = PEEK (Y%(Y) + Q%)538 FOR I = 7 TO R% STEP -154 P% = 2 A I542 IF V% > P% THEN V% = V%-P%544 NEXT I546 IF V% > 2 A I THEN c = 11 REM11 REM CALCULATE Y12 REM COORDINATES13 REM14 DIM Y% (192)15 FOR I = TO 184 STEP 8: READ SA%16 FOR J = TO 7:Y%(I + J) = SA% +J * 12417 NEXT J,I18 DATA 8192,832, 8448,8576,874,8832, 896,98819 DATA 8232,836, 8488, 8616 ,8744,8872, 9,912811 DATA 8272,84,8528,8656,8784,8912, 94,9168111 RETURNLines 5 and 1000 to 1100 should be fam iliar from previous chapters; they

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

Saved successfully!

Ooh no, something went wrong!