sub main
completed = 0
starttime = Clock.ElapsedMilliseconds
For x = 0 To w / size ' calculate ray position and direction
cameraX = 2 * x / (w / size) - 1 ' x-coordinate in camera space
rayPosX = posX
rayPosY = posY
rayDirX = dirX + planeX * cameraX
rayDirY = dirY + planeY * cameraX
'
'which box of the map we're in
mapX = Math.Floor(rayPosX)
mapY = Math.Floor(rayPosY)
' length of ray from current position to next x or y-side
sideDistX = 0
sideDistY = 0
' length of ray from one x or y-side to next x or y-side
deltaDistX = Math.SquareRoot(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX))
deltaDistY = Math.SquareRoot(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY))
perpWallDist = 0
'what direction to step in x or y-direction (either +1 or -1)
stepX = 0
stepY = 0
hit = 0 ' was there a wall hit?
side = 0 ' was a NS or a EW wall hit?
' perform DDA
' trace a "ray" until it hits a wall, and determine if it's an "X" (horizontal) or "Y" (vertical) wall
While hit = 0 ' jump to next map square, OR in x-direction, OR in y-direction
If sideDistX < sideDistY Then
sideDistX = sideDistX + deltaDistX
mapX = mapx + stepX
side = 0
Else
sideDistY = sideDistY + deltaDistY
mapY = mapy + stepY
side = 1
EndIf
' Check if ray has hit a wall
If worldMap[mapX][mapY] > 0 Then
hit = 1
EndIf
EndWhile
' Calculate distance projected on camera direction.
If side = 0 Then
perpWallDist = Math.Abs((mapX - rayPosX + (1 - stepX) / 2) / rayDirX)
Else
perpWallDist = Math.Abs((mapY - rayPosY + (1 - stepY) / 2) / rayDirY)
EndIf
' Calculate height of line to draw on screen
lineHeight = Math.Abs(h / perpWallDist)
lineHeight = Math.Round (lineheight)
'if height if line to be drawn is > than height of graphics window then limit height of line
'If lineHeight > h Then
' lineHeight = h
'EndIf
'
' calculate lowest and highest pixel to fill in current stripe
drawStart = (lineHeight * -1) / 2 + h / 2
'If drawStart < 0 Then
' drawStart = 0
'EndIf
drawEnd = lineHeight / 2 + h / 2
'If drawEnd >= h Then
' drawEnd = h - 1
'EndIf
' set up the colours depending on the block numbers
' default colour is grey (RGB values are equal)
'
' define some parameters that state how big the map is
mapsizex = Text.GetLength (mapline[1])
mapsizey = array.GetItemCount (mapline)
'
'try to read this in and convert it into a two dimensional array
For yloop = 1 To mapsizey
For xloop = 1 To mapsizex
worldmap[xloop][yloop] = Text.GetSubText(mapline[yloop],xloop,1)
EndFor
EndFor
EndSub
Sub setuptexture
'blue panel
texline[1] = "777777777777777777777777777777"
texline[2] = "774444444444444444444444444477"
texline[3] = "777777777777777777777777777777"
For yloop = 1 To texHeight
For xloop = 1 To texWidth
texture[5][xloop][yloop] = Text.GetSubText(texline[yloop],xloop,1)
EndFor
EndFor
'red panel
texline[1] = "777777777777777777777777777777"
texline[2] = "777722222222222222222222227777"
texline[3] = "777777777777777777777777777777"
For yloop = 1 To texHeight
For xloop = 1 To texWidth
texture[6][xloop][yloop] = Text.GetSubText(texline[yloop],xloop,1)
EndFor
EndFor
'closed door
texline[1] = "111111111111111111111111111111"
texline[2] = "111111778555555555555877111111"
texline[3] = "111111778555555555555877111111"
For yloop = 1 To texHeight
For xloop = 1 To texWidth
texture[7][xloop][yloop] = Text.GetSubText(texline[yloop],xloop,1)
EndFor
EndFor
'gray panel
texline[1] = "777777777777777777777777777777"
texline[2] = "771111111111111111111111111177"
texline[3] = "777777777777777777777777777777"
For yloop = 1 To texHeight
For xloop = 1 To texWidth
texture[8][xloop][yloop] = Text.GetSubText(texline[yloop],xloop,1)
EndFor
EndFor
'open door
texline[1] = "887777777777777777777777777788"
texline[2] = "887778844000000000000448877788"
texline[3] = "887778844000000000000448877788"
For yloop = 1 To texHeight
For xloop = 1 To texWidth
texture[9][xloop][yloop] = Text.GetSubText(texline[yloop],xloop,1)
EndFor
EndFor