Tutorial 031 Missiles!


This very simple game was inspired by Alan Thomas' program "Duckshoot" in that amazingly fertile little book "Further programming for the BBC Micro". Its a graphics version of his text based game. Here the the white tracks on a dark background look more like vapour trails of potentially colliding planes or missiles....

The only thing you need to do is press the space bar, but chosing the right time to do that is the difficult bit...

You need to come within a separation of 15 to score a hit, so its not all that easy.

The program is ripe for addition of bells and whistles... Over to you....

      REM: Missiles
      REM: by Richard Weston, 12th June 2003
      MODE8:OFF
      COLOUR9
      PRINTTAB(15)"MISSILES!!";
      COLOUR2
      PRINT"  Just keep pressing <SPACE>"
      COLOUR3
      REM: d=duck
      xd=0
      yd=100+RND(900)
      :
      REM: b=bullet
      xb=1100
      yb=0
      LINE xb,0,xb,5
      MOVE xd,yd
      REPEAT
        PROCsep
        xd=xd+2
        DRAW xd,yd
        G$=INKEY$(1)
      UNTIL G$=" "
      :
      REPEAT
        PROCsep
        MOVE xd,yd
        xd=xd+2
        DRAW xd,yd
        MOVE xb,yb
        yb+=2
        DRAW xb,yb
        G$=INKEY$(1)
        PROCtest
      UNTIL G$=" "
      RUN
      END
      :
      DEFPROCtest
      IF sep<15 THEN
        VDU5
        GCOL0,9
        RECTANGLE FILL xb-10,yb-10,20,20
        PRINT" HIT!"
        G$=GET$
      ENDIF
      ENDPROC
      :
      DEF PROCsep
      sep=INT(SQR((xb-xd)^2 + (yb-yd)^2))
      PRINTTAB(55,0)"Separation = ";sep;"   "
      ENDPROC




Comments

This program needs little explanation:

Using (xd, yd) the "duck"or target plane's coordinates are specified.
Using (xb, yb) the "bullet" or missile's coordinates are given

LINE xb,0,xb,5 shows you where the missile will set off from in a " screen-vertical" direction

PROCsep calculates the separation of the duck and bullet using Pythagoras' Theorem

PROCtest congratulates you for your hit if you come close enough.


Crazy Versions!

You will see that I have taken some liberties with the x,y values in the following versions :
The first two don't take much skill, but the third version, "Wobblers", may or may not involve skill!

      REM: These Missiles can't miss!
      REM: by Richard Weston, 12th June 2003
      MODE8:OFF
      COLOUR9
      PRINTTAB(15)"MISSILES!!";
      COLOUR2
      PRINT"  Just keep pressing <SPACE>"
      COLOUR3
      REM: d=duck
      xd=0
      yd=100+RND(900)
      :
      REM: b=bullet
      xb=1100
      yb=0
      LINE xb,0,xb,5
      MOVE xd,yd
      REPEAT
        PROCsep
        xd=xd+2
        DRAW xd,yd
        G$=INKEY$(1)
      UNTIL G$=" "
      :
      REPEAT
        PROCsep
        MOVE xd,yd
        xd=xd+2
        yd=yd-(0.3)*(yd-yb)
        DRAW xd,yd
        MOVE xb,yb
        yb+=2
        DRAW xb,yb
        G$=INKEY$(1)
        PROCtest
      UNTIL G$=" "
      RUN
      END
      :
      DEFPROCtest
      IF sep<15 THEN
        VDU5
        GCOL0,9
        RECTANGLE FILL xb-10,yb-10,20,20
        PRINT" HIT!"
        G$=GET$
      ENDIF
      ENDPROC
      :
      DEF PROCsep
      sep=INT(SQR((xb-xd)^2 + (yb-yd)^2))
      PRINTTAB(55,0)"Separation = ";sep;"   "
      ENDPROC


      REM: Wobble and Lurch
      REM: by Richard Weston, 12th June 2003
      MODE8:OFF
      COLOUR9
      PRINTTAB(15)"MISSILES!!";
      COLOUR2
      PRINT"  Just keep pressing <SPACE>"
      COLOUR3
      REM: d=duck
      xd=0
      yd=100+RND(900)
      :
      REM: b=bullet
      xb=1100
      yb=0
      LINE xb,0,xb,5
      MOVE xd,yd
      REPEAT
        PROCsep
        xd=xd+2
        DRAW xd,yd
        G$=INKEY$(1)
      UNTIL G$=" "
      :
      REPEAT
        PROCsep
        MOVE xd,yd
        xd=xd+2
        yd=yd-COS(0.2*yb)*(0.3)*(yd-yb)
        DRAW xd,yd
       
        MOVE xb,yb
        yb+=2
        xb=xb-0.2*(xb-xd)
        DRAW xb,yb
        G$=INKEY$(1)
        PROCtest
      UNTIL G$=" "
      RUN
      END
      :
      DEFPROCtest
      IF sep<15 THEN
        VDU5
        GCOL0,9
        RECTANGLE FILL xb-10,yb-10,20,20
        PRINT" HIT!"
        G$=GET$
      ENDIF
      ENDPROC
      :
      DEF PROCsep
      sep=INT(SQR((xb-xd)^2 + (yb-yd)^2))
      PRINTTAB(55,0)"Separation = ";sep;"   "
      ENDPROC


      REM: Wobblers
      REM: by Richard Weston, 12th June 2003
      MODE8:OFF
      COLOUR9
      PRINTTAB(15)"MISSILES!!";
      COLOUR2
      PRINT"  Just keep pressing <SPACE>"
      COLOUR3
      REM: d=duck
      xd=0
      yd=100+RND(900)
      :
      REM: b=bullet
      xb=1100
      yb=0
      LINE xb,0,xb,5
      MOVE xd,yd
      REPEAT
        PROCsep
        xd=xd+2
        DRAW xd,yd
        G$=INKEY$(1)
      UNTIL G$=" "
      :
      REPEAT
        PROCsep
        MOVE xd,yd
        xd=xd+6
        yd=yd-COS(0.2*yb)*(0.3)*(yd-yb)
        DRAW xd,yd
        MOVE xb,yb
        yb+=1
        xb=xb+50*COS(yb)
        DRAW xb,yb
        G$=INKEY$(1)
        PROCtest
      UNTIL G$=" "
      RUN
      END
      :
      DEFPROCtest
      IF sep<15 THEN
        VDU5
        GCOL0,9
        RECTANGLE FILL xb-10,yb-10,20,20
        PRINT" HIT!"
        G$=GET$
      ENDIF
      ENDPROC
      :
      DEF PROCsep
      sep=INT(SQR((xb-xd)^2 + (yb-yd)^2))
      PRINTTAB(55,0)"Separation = ";sep;"   "
      ENDPROC


Next Tutorial


Richard Weston's Homepage