home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
526-550
/
apd529
/
shipwalker
/
shipwalk.amos
/
shipwalk.amosSourceCode
Wrap
AMOS Source Code
|
1993-11-29
|
8KB
|
312 lines
' Walk through maze routine demo.
' by Sarv. Engelhardt, Sept 1990
' exit with Esc key
' see doc.file for how to specify maze walls as data
' size of maze is specified by XLIMIT and YLIMIT
' make sure MAZE() array is large enough to hold data!
' direction facing is D (1,2,3,4 for N,E,S,W)
' starting position in maze is XW,YW
Load "shipicons.abk"
' Make Icon Mask doesn't seem to be necessary
' colour 0 is treated as transparent
Screen Open 0,320,250,16,Lowres
Flash Off : Curs Off : Cls 0
' could use Get Sprite Palette here
Palette $0,$ECA,$D00,$F60,$90,$3F1,$F,$2CD,$F0C,$A00,$BBB,$AAA,$999,$888,$777,$222
Ink 1,0
Box 9,9 To 125,121
' Double buffer with autoback 0
' screen is swapped in SPICT procedure
' after drawing the view. Very smooth!
Double Buffer
Autoback 0
Ink 1,0
Box 9,9 To 125,121
Dim MAZE(20,40),W(17),XP(8),YP(8),XM(8),YM(8)
Global XLIMIT,YLIMIT,D,XW,YW,LEVEL
Global MAZE(),W(),XP(),XM(),YP(),YM()
XLIMIT=6 : YLIMIT=36
'set up initial position
D=4 : XW=2 : YW=2 : LEVEL=1
'load data for level 1
MAZEDAT["L1"]
'set up initial view
WALK
' Scan the keyboard
' cursor up = walk forward in direction facing
' cursor left/right = turn left/right
' cursor down = turn around
Do
While K$=""
K$=Inkey$
Wend
CODE=Scancode
' exit if ESC pressed
Exit If CODE=69
' Move in direction D, but only if not facing
' a wall W(12)
If CODE=76 and W(12)<>1
If D=1 : Dec YW : End If
If D=2 : Inc XW : End If
If D=3 : Inc YW : End If
If D=4 : Dec XW : End If
WALK
End If
If CODE=78
Inc D
If D>4 : D=1 : End If
SPICT
End If
If CODE=79
Dec D
If D<1 : D=4 : End If
SPICT
End If
If CODE=77
D=D+2
If D>4 : D=D-4 : End If
SPICT
End If
K$=""
Loop
End
'move forward
Procedure WALK
' check limits of maze. The maze wraps around
' if you walk beyond edges
If XW<0 Then XW=XW+XLIMIT
If XW>XLIMIT-1 Then XW=XW-XLIMIT
If YW<0 Then YW=YW+YLIMIT/2
If YW>YLIMIT/2 Then YW=YW-YLIMIT/2
Y2=2*YW : YP(0)=Y2 : XP(0)=XW
XP(1)=XW+1 : XP(2)=XW+2 : XP(3)=XW+3
XM(1)=XW-1 : XM(2)=XW-2 : XM(3)=XW-3
YP(1)=Y2+1 : YP(2)=Y2+2 : YP(3)=Y2+3
YP(5)=Y2+5 : YP(6)=Y2+6 : YP(7)=Y2+7
YM(1)=Y2-1 : YM(2)=Y2-2 : YM(3)=Y2-3
YM(4)=Y2-4 : YM(5)=Y2-5 : YP(4)=Y2+4
For I=1 To 7
If XM(I)<0 Then XM(I)=XM(I)+XLIMIT
If YM(I)<0 Then YM(I)=YM(I)+YLIMIT
If YP(I)>YLIMIT Then YP(I)=YP(I)-YLIMIT
If XP(I)>XLIMIT Then XP(I)=XP(I)-XLIMIT
Next I
If XW=1 and YW=16
' Load maze data for new level
MAZEDAT["L2"]
End If
SPICT
End Proc
'these next four procedures calculate the view
'in each direction
Procedure NORTH
W(0)=MAZE(XP(0),YM(5))
W(1)=MAZE(XP(1),YM(5))
W(2)=MAZE(XP(0),YM(4))
W(3)=MAZE(XP(1),YM(4))
W(4)=MAZE(XM(1),YM(4))
W(5)=MAZE(XP(0),YM(3))
W(6)=MAZE(XP(1),YM(3))
W(7)=MAZE(XP(0),YM(2))
W(8)=MAZE(XP(1),YM(2))
W(9)=MAZE(XM(1),YM(2))
W(10)=MAZE(XP(0),YM(1))
W(11)=MAZE(XP(1),YM(1))
W(12)=MAZE(XP(0),YP(0))
W(13)=MAZE(XM(1),YP(0))
W(14)=MAZE(XP(1),YP(0))
W(15)=MAZE(XP(0),YP(1))
W(16)=MAZE(XP(1),YP(1))
End Proc
Procedure EAST
W(0)=MAZE(XP(3),YP(0))
W(1)=MAZE(XP(3),YP(2))
W(2)=MAZE(XP(3),YP(1))
W(3)=MAZE(XP(3),YP(3))
W(4)=MAZE(XP(3),YM(1))
W(5)=MAZE(XP(2),YP(0))
W(6)=MAZE(XP(2),YP(2))
W(7)=MAZE(XP(2),YP(1))
W(8)=MAZE(XP(2),YP(3))
W(9)=MAZE(XP(2),YM(1))
W(10)=MAZE(XP(1),YP(0))
W(11)=MAZE(XP(1),YP(2))
W(12)=MAZE(XP(1),YP(1))
W(13)=MAZE(XP(1),YM(1))
W(14)=MAZE(XP(1),YP(3))
W(15)=MAZE(XP(0),YP(0))
W(16)=MAZE(XP(0),YP(2))
End Proc
Procedure SOUTH
W(0)=MAZE(XP(1),YP(7))
W(1)=MAZE(XP(0),YP(7))
W(2)=MAZE(XP(0),YP(6))
W(3)=MAZE(XM(1),YP(6))
W(4)=MAZE(XP(1),YP(6))
W(5)=MAZE(XP(1),YP(5))
W(6)=MAZE(XP(0),YP(5))
W(7)=MAZE(XP(0),YP(4))
W(8)=MAZE(XM(1),YP(4))
W(9)=MAZE(XP(1),YP(4))
W(10)=MAZE(XP(1),YP(3))
W(11)=MAZE(XP(0),YP(3))
W(12)=MAZE(XP(0),YP(2))
W(13)=MAZE(XP(1),YP(2))
W(14)=MAZE(XM(1),YP(2))
W(15)=MAZE(XP(1),YP(1))
W(16)=MAZE(XP(0),YP(1))
End Proc
Procedure WEST
W(0)=MAZE(XM(3),YP(2))
W(1)=MAZE(XM(3),YP(0))
W(2)=MAZE(XM(2),YP(1))
W(3)=MAZE(XM(2),YM(1))
W(4)=MAZE(XM(2),YP(3))
W(5)=MAZE(XM(2),YP(2))
W(6)=MAZE(XM(2),YP(0))
W(7)=MAZE(XM(1),YP(1))
W(8)=MAZE(XM(1),YM(1))
W(9)=MAZE(XM(1),YP(3))
W(10)=MAZE(XM(1),YP(2))
W(11)=MAZE(XM(1),YP(0))
W(12)=MAZE(XP(0),YP(1))
W(13)=MAZE(XP(0),YP(3))
W(14)=MAZE(XP(0),YM(1))
W(15)=MAZE(XP(0),YP(2))
W(16)=MAZE(XP(0),YP(0))
End Proc
'load mazedata
Procedure MAZEDAT[LVL$]
Restore LVL$
For I=0 To YLIMIT
For J=0 To XLIMIT
Read MAZE(J,I)
Next J
Next I
L1: Data 1,1,3,3,1,1,1
Data 1,1,3,0,3,1,1
Data 1,1,0,0,1,1,1
Data 1,1,0,0,0,1,1
Data 1,0,0,0,0,1,1
Data 1,2,0,0,0,2,1
Data 0,1,1,1,1,0,1
Data 3,1,0,2,1,0,1
Data 0,0,0,0,1,2,1
Data 3,1,0,1,2,0,3
Data 0,1,1,0,0,0,1
Data 3,1,0,2,1,0,3
Data 0,0,0,0,1,1,0
Data 3,1,0,1,2,0,3
Data 0,1,1,0,0,0,0
Data 3,1,0,2,1,0,3
Data 0,0,0,0,1,1,0
Data 3,1,0,1,2,0,3
Data 0,1,1,0,0,0,0
Data 3,1,2,1,1,0,3
Data 0,0,0,0,2,1,0
Data 3,1,1,1,1,2,1
Data 0,0,0,0,0,0,0
Data 3,1,1,0,2,1,1
Data 0,1,2,1,1,0,0
Data 3,1,0,1,0,1,1
Data 0,0,0,0,0,0,0
Data 3,1,0,1,0,1,1
Data 0,0,1,2,2,0,0
Data 1,1,1,0,1,1,1
Data 0,0,0,0,0,0,0
Data 1,2,1,0,1,2,1
Data 1,0,1,1,0,0,1
Data 1,1,1,0,2,1,1
Data 0,1,0,0,1,1,0
Data 1,1,1,0,1,1,1
Data 0,0,3,3,0,0,0
' level 2
L2: Data 1,1,1,1,1,1,1
Data 1,0,1,0,1,0,1
Data 0,1,0,0,1,0,0
Data 1,1,2,0,0,1,1
Data 1,0,1,1,0,1,1
Data 1,0,1,0,1,0,1
Data 0,0,0,0,2,2,0
Data 1,0,1,0,1,1,1
Data 0,0,1,2,0,0,0
Data 1,0,1,0,1,1,1
Data 1,2,0,0,0,0,1
Data 1,0,1,0,1,1,1
Data 0,1,2,1,0,0,0
Data 1,1,0,1,0,1,1
Data 0,0,0,0,1,0,0
Data 1,1,0,1,1,0,1
Data 2,2,1,1,0,1,2
Data 1,0,1,2,1,1,1
Data 1,0,1,0,0,0,1
Data 1,0,1,2,1,1,1
Data 0,1,1,0,0,0,0
Data 1,0,1,2,1,2,1
Data 1,0,1,0,1,0,1
Data 1,0,1,2,1,2,1
Data 0,1,1,0,0,1,0
Data 1,0,1,2,1,0,1
Data 1,0,1,0,1,0,1
Data 1,0,1,2,1,0,1
Data 0,1,1,0,2,1,0
Data 1,2,1,2,1,0,1
Data 1,0,1,0,1,2,1
Data 1,0,1,2,1,0,1
Data 1,0,1,0,0,1,1
Data 1,1,1,2,2,1,1
Data 0,1,1,0,1,0,0
Data 1,1,1,2,1,1,1
Data 0,0,1,1,0,0,0
End Proc
' show the view
Procedure SPICT
'get walls for direction faced
On D Proc NORTH,EAST,SOUTH,WEST
' background
Paste Icon 10,10,38
' create view
' 1 means wall; 2 means door; 3 means window
If W(0)<>0 Then Paste Icon 54,41,1
If W(0)=3 Then Paste Icon 55,43,36
If W(1)<>0 Then Paste Icon 74,41,2
If W(1)=3 Then Paste Icon 74,42,37
If W(2)<>0 Then Paste Icon 54,41,3
If W(2)=2 Then Paste Icon 62,44,20
If W(2)=3 Then Paste Icon 56,44,29
If W(3)<>0 Then Paste Icon 81,41,5
If W(3)=3 Then Paste Icon 83,44,30
If W(4)<>0 Then Paste Icon 10,41,4
If W(4)=3 Then Paste Icon 10,44,31
If W(5)<>0 Then Paste Icon 43,33,7
If W(5)=2 Then Paste Icon 48,38,23
If W(5)=3 Then Paste Icon 46,38,34
If W(6)<>0 Then Paste Icon 81,34,6
If W(6)=2 Then Paste Icon 84,39,24
If W(6)=3 Then Paste Icon 82,39,35
If W(7)<>0 Then Paste Icon 43,34,8
If W(7)=2 Then Paste Icon 62,40,19
If W(7)=3 Then Paste Icon 47,40,26
If W(8)<>0 Then Paste Icon 92,34,13
If W(8)=2 Then Paste Icon 110,40,19
If W(8)=3 Then Paste Icon 96,40,28
If W(9)<>0 Then Paste Icon 10,34,11
If W(9)=2 Then Paste Icon 14,40,19
If W(9)=3 Then Paste Icon 10,40,27
If W(10)<>0 Then Paste Icon 19,18,9
If W(10)=2 Then Paste Icon 31,35,21
If W(10)=3 Then Paste Icon 24,30,32
If W(11)<>0 Then Paste Icon 91,18,10
If W(11)=2 Then Paste Icon 98,35,22
If W(11)=3 Then Paste Icon 94,33,33
If W(12)<>0 Then Paste Icon 19,17,12
If W(12)=2 Then Paste Icon 51,29,18
If W(12)=3 Then Paste Icon 30,29,25
If W(13)<>0 Then Paste Icon 10,17,16
If W(14)<>0 Then Paste Icon 116,17,17
If W(15)<>0 Then Paste Icon 10,10,14
If W(16)<>0 Then Paste Icon 116,10,15
'transporter to next level
If XW=1 and YW=15 and D=3 Then Paste Icon 49,23,39
Screen Swap : Wait Vbl
End Proc