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.

160 APPLE II COMPUTER GRAPHICSHPLOT 137,38 TO 153 ,38, HPLOT TO 153 , 51HPLOT TO 137, 51HPLOT TO 137 ,38As we move the missile up the screen we will check to see if it movesinside that box, and if so- BOOM! To g<strong>et</strong> that to happen, add these linesto your program:4(i' REM5(i' REM SET BOUNDARIES6(i' REM7(i' YMAX = 51:MINX = 137:MAXX 15351(i' PRINT CHR$ (7) : REM BELL52(i' C = <strong>ii</strong>': REM COLLISION FLAG53<strong>ii</strong>' FOR Y = 149 TO <strong>ii</strong>' STEP -154(i' IF Y < YMAX THEN IF M > MINXAND M < MAXX THEN C = 1: REM COLLISION ! !55<strong>ii</strong>' IF C THEN PRINT CHR$ (7) ; CHR$ (7) ;CHR$ (7) : XDRAW 2 AT M,Y + 1: GOTO 62<strong>ii</strong>'561i' XDRAW 2 AT M, Y + 1: XDRAW 2 AT M , Y571i' NEXT Y58<strong>ii</strong>' REM ERASE MISSILE @) TOP591i' y = y + 16(i'fi' XDRAW 2 AT M ,Y61fi' REM DRAW NEXT MISSILE62fi' XDRAW 2 AT M, 15<strong>ii</strong>'63fi' RETURNListing 14-2.Line 7(/J s<strong>et</strong>s the boundaries for the square. The upper boundary is ignoredin this example because the missiles <strong>al</strong>ways come from below.Line 54(/J is the line that actu<strong>al</strong>ly d<strong>et</strong>ects any collision. It first checks theY-coordinate at the tip of the missile to see if it is high enough to possiblystrike the box. If so, then the X position is checked to see if it is in thecorrect horizont<strong>al</strong> range. If the answer to <strong>al</strong>l of these is "yes," then wehave a coll ision and the flag (C) is s<strong>et</strong> to 1 for later reference.Line 55(/J is where you jump to g<strong>et</strong> your nifty explosion routine, but sinc<strong>et</strong>his is only an example, <strong>al</strong>l we do is s<strong>et</strong> off the bells and whistles. We thenerase the missile from its last position and jump to where a new missile idrawn at the bottom- big de<strong>al</strong>!In this case, since the targ<strong>et</strong> is stationary, it would be advantageous tocheck the X-coordinate before the Y. If the X v<strong>al</strong>ue is within the range ofthe targ<strong>et</strong>, there is bound to be a collision. In that case you need to checkonly the Y-coordinate as the missile rises in order to tell you when themissile strikes the targ<strong>et</strong>. If the X is not within range, then the missile will

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

Saved successfully!

Ooh no, something went wrong!