home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
authors
/
stephan_scholz
/
dogfight.amos
/
dogfight.amosSourceCode
Wrap
AMOS Source Code
|
1986-08-03
|
8KB
|
290 lines
' **********************************************************
' * LA OROYA written by *
' * 1993 Stephan Scholz *
' * >>> DOGFIGHT <<< *
' * *
' * An elementary shooting game between two tiny ships. *
' * *
' * 4 Cursor keys: left, right, speed up, break. *
' * Space bar : fire. *
' * *
' * Features 360 degree movement, Plot and Draw being *
' * used to draw the ships - no Bobs or Sprites... *
' * Trigonometrical values are pre-calculated and stored *
' * in tables for direct access when ships are drawn. *
' * *
' **********************************************************
'
Set Buffer 40
Screen Open 0,320,256,16,Lowres
Degree
Curs Off : Cls 0 : Hide On
Locate 0,6
Paper 0 : Pen 4
Print " LA OROYA"; : Pen 2 : Print " presents: " : Pen 3
Print : Print : Print " >>> DOGFIGHT <<<" : Pen 2
Print : Print :
Print : Print " Ship Controls:"
Print : Print " The Four Cursor Arrows:"
Print : Print " Left-Right-Acceletate-Break"
Print : Print " and Spacebar to Fire" : Pen 5
Print : Print
Print : Print " Please wait, reading datas..."
Dim H#(360,8)
Dim S#(360,3,2)
X#=70
X2#=250
Y#=180
Y2#=180
VELOZ#=0
V2#=0
RUMBO=180
R2=180
BODY=-8
MILI#=5
Proc DATOS
Bell
Locate 0,23
Pen 3
Print " O.K. Press any key to start "
Wait Key
Cls 0 : Pen 5
'ship control variables for straightening, turning and speeding up
CORR#=0.1
RCH#=0.2
VCH#=0.02
Do
'reads keyboard
If Key State(76) Then If SP<3 Then VELOZ#=VELOZ#+VCH# : SP=VELOZ#
If Key State(78) Then If CHRUMBO#>-3 Then CHRUMBO#=CHRUMBO#-RCH#
If Key State(77) Then If SP>0 Then VELOZ#=VELOZ#-VCH# : SP=VELOZ#
If Key State(79) Then If CHRUMBO#<3 Then CHRUMBO#=CHRUMBO#+RCH#
If Key State(64) Then If DISPARO=0 Then Proc DISPARO
'changes your heading if you are turning
RUMBO=RUMBO+CHRUMBO#
'changes red ship�s course sometimes
If Rnd(200)=0 Then CH2#=Rnd(2.0)-1.0
'accelerates red ship
If V2#<3 Then V2#=V2#+VCH# : SP2=Int(V2#)
'changes red ship�s heading if it�s turning
R2=R2+CH2#
'straightens you out
CHRUMBO#=CHRUMBO#-Sgn(Int(CHRUMBO#*10))*CORR#
'straightens red ship out
CH2#=CH2#-Sgn(Int(CH2#*10))*CORR#
'factor corrections
If RUMBO<1 Then Add RUMBO,360
If R2<1 Then Add R2,360
If RUMBO>360 Then Add RUMBO,-360
If R2>360 Then Add R2,-360
'selects speed (sp=0 to 3)
X#=X#+S#(RUMBO,SP,1)
X2#=X2#+S#(R2,SP2,1)
Y#=Y#+S#(RUMBO,SP,2)
Y2#=Y2#+S#(R2,SP2,2)
'converts to integers
X=X#
Y=Y#
X2=X2#
Y2=Y2#
'erases previous position and draws ships at new positions
Plot X1,Y1,0 : Draw To X1+H#(RUMBO1,3),Y1+H#(RUMBO1,4)
Plot X1,Y1 : Draw To X1+H#(RUMBO1,5),Y1+H#(RUMBO1,6)
Plot X,Y,2 : Draw To X+H#(RUMBO,3),Y+H#(RUMBO,4)
Plot X,Y : Draw To X+H#(RUMBO,5),Y+H#(RUMBO,6)
Plot X3,Y3,0 : Draw To X3+H#(R3,3),Y3+H#(R3,4)
Plot X3,Y3 : Draw To X3+H#(R3,5),Y3+H#(R3,6)
Plot X2,Y2,4 : Draw To X2+H#(R2,3),Y2+H#(R2,4)
Plot X2,Y2 : Draw To X2+H#(R2,5),Y2+H#(R2,6)
'if you've fired
If DISPARO
'give bullet your heading
DX#=DX#+H#(MUMBO,1)
DY#=DY#+H#(MUMBO,2)
DX=DX#
DY=DY#
'erase previous bullet position and draw new one
Plot DX1,DY1,0
Plot DX,DY,2
'if bullet nears other ship, score a hit.
'The 15 can be reduced to increase difficulty.
If Abs(DX-X2)<15
If Abs(DY-Y2)<15 : Proc HIT : End If
End If
'decrease missile counter so if 0 make bullet disappear
Dec MISS
If MISS<1
DISPARO=0
Plot DX,DY,0
End If
End If
'if red ship has fired
If FEUER
'give bullet red ship�s heading
DX2#=DX2#+H#(M2,1)
DY2#=DY2#+H#(M2,2)
DX2=DX2#
DY2=DY2#
'draw it
Plot DX3,DY3,0
Plot DX2,DY2,2
'if near you, score a hit
If Abs(DX2-X)<15
If Abs(DY2-Y)<15 : Proc DADO : End If
End If
'decrease bullet counter, if 0 make it disappear
Dec MS2
If MS2<1
FEUER=0
Plot DX2,DY2,0
End If
End If
'if red ship is near your ship, and if it hasn't fired, it
'will turn either away or towards you, and fire (evasive or
'offensive action)
If Abs(X-X2)<100
If Abs(Y-Y2)<100
If Not FEUER
CH2#=CH2#+Rnd(2.0)-1.0
Proc FEUER
End If
End If
End If
'register previous data to free variables for new data
RUMBO1=RUMBO
R3=R2
DX1=DX
DX3=DX2
DY1=DY
DY3=DY2
X1=X
Y1=Y
R3=R2
X3=X2
Y3=Y2
'wrap around for your ship
If X#>319 Then X#=0
If Y#>254 Then Y#=0
If Y#<0 Then Y#=254
If X#<0 Then X#=319
'wrap around for red ship
If X2#>319 Then X2#=0
If Y2#>254 Then Y2#=0
If Y2#<0 Then Y2#=254
If X2#<0 Then X2#=319
'wrap around for your bullet
If DX#>319 Then DX#=0
If DY#>254 Then DY#=0
If DY#<0 Then DY#=254
If DX#<0 Then DX#=319
'wrap around for red ship�s bullet
If DX2#>319 Then DX2#=0
If DY2#>254 Then DY2#=0
If DY2#<0 Then DY2#=254
If DX2#<0 Then DX2#=319
'the bullet wrap-arounds can be eliminated to
'get more program speed - you save 8 If's...
'decrease missle counters
Dec MC1
Dec MC2
Loop
Procedure DISPARO
Shared X#,Y#,RUMBO,DX#,DY#,MISS,DISPARO,MUMBO,MC1,H#()
'if time for next shot has not expired, don't shoot
If MC1>0 Then Pop Proc
Shoot
'time counter to avoid too frequent shots
MC1=35
'shot flag
DISPARO=1
'distance counter
'bullet travels 12*speed (12)=144 pixels
MISS=12
'heading for bullet
MUMBO=RUMBO
'speed for bullet
DX#=X#+H#(MUMBO,7)
DY#=Y#+H#(MUMBO,8)
End Proc
Procedure FEUER
'same comments as previous procedure, but for red ship�s bullet
Shared X2#,Y2#,R2,DX2#,DY2#,MS2,FEUER,M2,MC2,H#()
If MC2>0 Then Pop Proc
Shoot
MC2=35
FEUER=1
MS2=12
M2=R2
DX2#=X2#+H#(M2,7)
DY2#=Y2#+H#(M2,8)
End Proc
Procedure DADO
'if you have been hit
Shared X,Y,MS2,DADO,VELOZ#,SP
Boom
'slows you down
If Int(VELOZ#)>0 Then VELOZ#=VELOZ#-1 : SP=Int(VELOZ#)
'increases damage counter
Inc DADO
'stops red ship�s bullet�s distance counter
MS2=0
'draws "explosion"
For M=1 To 0 Step -1
For N=1 To 20 Step 4
Ink M
Circle X,Y,N
Next N
Next M
'register the damage
Locate 30,28
Print DADO
End Proc
Procedure HIT
'same comments as above, but if you hit oyther ship,
'so hits are scored as hit points for you.
Shared X2,Y2,MISS,HIT,V2#,SP2
Boom
If Int(V2#)>0 Then V2#=V2#-1 : SP2=Int(V2#)
Inc HIT
MISS=0
For M=1 To 0 Step -1
For N=1 To 20 Step 4
Ink M
Circle X2,Y2,N
Next N
Next M
Locate 2,28
Print HIT
End Proc
Procedure DATOS
'trigonometrical data to draw ship and bullet positions
Shared BODY#,H#(),S#()
'size
BODY#=-8
'all the angles
For N=1 To 360
K=N
If N-15<0 Then K=N+360
If N+15>360 Then K=N-360
'bullet speed
H#(N,1)=12*Sin(N)
H#(N,2)=12*Cos(N)
'both sides of the "V" of the ships
H#(N,3)=BODY#*Sin(K+15)
H#(N,4)=BODY#*Cos(K+15)
H#(N,5)=BODY#*Sin(K-15)
H#(N,6)=BODY#*Cos(K-15)
'full speed
S#(N,3,1)=3*Sin(N)
S#(N,3,2)=3*Cos(N)
'cruising speed
S#(N,2,1)=2*Sin(N)
S#(N,2,2)=2*Cos(N)
'slow speed
S#(N,1,1)=Sin(N)
S#(N,1,2)=Cos(N)
'no speed
S#(N,0,1)=0
S#(N,0,2)=0
Next N
End Proc