Code: Select all
' |
' |
' |
' +-------> x
' /
' /
' / y
'
Dim Shared As Integer floor(20,20)
Dim Shared As Integer counter
Dim Shared As Any Ptr blockImage
Dim As Uinteger c
'code rgb colors of sprite
dim as uinteger sColor(5)
sColor(0)=&HFFFF00FF 'pink transparent color
sColor(1)=&HFF010101 'black
sColor(2)=&HFF00FE00 'green
sColor(3)=&HFF0000FE 'blue
sColor(4)=&HFFFE0000 'red
screenres 640,480,32,2 'two pages
screenset 1,0 'select page
blockImage = ImageCreate( 32, 32 ) ' allocate memory for 32x32 sprite
'read block image
For y As Integer = 0 To 31
For x As Integer = 0 To 31
Read c
Pset blockImage,(x,y), sColor(c)
Next x
Next y
'read floor data
For y As Integer = 0 To 19
For x As Integer = 0 To 19
Read floor(x,y)
Next x
Next y
'dim as integer x,y,z
Dim Shared As Integer cx,cy
cy = 200
cx = 200
Sub Set3DPixel(x As Integer,y As Integer,z As Integer,c As Uinteger)
Pset(x-y+cx,cy+y-z),c
End Sub
Sub Paint3D(x As Integer, y As Integer, z As Integer, c1 As Uinteger, c2 As Uinteger)
Paint(x-y+cx,cy+y-z),c1,c2
End Sub
Sub line3D(x1 As Integer,y1 As Integer, z1 As Integer, x2 As Integer,y2 As Integer, z2 As Integer, c As Uinteger)
Line (x1-y1+cx,cy+y1-z1)-(x2-y2+cx,cy+y2-z2),c
End Sub
Sub putBlock(x As Integer,y As Integer,z As Integer)
Put (x*20-y*10+cx,cy+y*10-z*20),blockImage,trans
End Sub
Sub displayWorld()
Dim As Integer x,y,z,xx,yy
Cls
'draw x coordinate
z = 0:y=0
For x = 0 To 440
set3DPixel(x,y,z,rgb(255,255,255))
Next x
x=0:y=0
For z = 0 To 400
set3DPixel(x,y,z,rgb(255,255,255))
Next z
'draw y coordinate
z = 0:x=0
For y = 0 To 400
set3DPixel(x,y,z,rgb(255,255,255))
Next y
'paint walls and floor
Paint (440,20),rgb(100,100,100),rgb(255,255,255)
Paint (20,20),rgb(50,50,50),rgb(255,255,255)
Paint (638,440),rgb(127,127,0),rgb(255,255,255)
z = 0
For y = 0 To 19
For x = 0 To 19
If floor(x,y)=1 Then
putBlock(x,y,z)
End If
Next x
Next y
'scan floor for blocks and move them
For y = 1 To 18
For x = 1 To 18
If floor(x,y)=1 Then
xx = Int(Rnd(1)*3)-1
yy = Int(Rnd(1)*3)-1
If floor(x+xx,y+yy)=0 Then
floor(x,y)=0 'erase old position
floor(x+xx,y+yy)=1 'insert in new position
End If
End If
Next x
Next y
Locate 1,1
Print counter
counter = counter + 1
screencopy
End Sub
' MAIN PROGRAM
Dim As Double now
now = Timer
Do
If TIMER>(now+0.03) Then
displayWorld()
now = Timer
End If
Loop Until multikey(&H01)
End
'block DATA
Data 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
Data 0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,0
Data 0,0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,1,0
Data 0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,1,0
Data 0,0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,1,0
Data 0,0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,1,0
Data 0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,1,0
Data 0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,3,1,0
Data 0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,3,3,1,0
Data 0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,3,3,3,3,3,3,3,3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