Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Const Location = "C:\SpaceInvadersSprites\"
- Dim WindowHeight As Integer = Console.LargestWindowHeight - 1
- Dim WindowWidth As Integer = 128
- Dim WorldMap(WindowHeight - 9, WindowWidth) As Char
- Dim ShipMap(8, WindowWidth) As Char
- Dim ShipString As String
- Dim WorldString As String
- Dim XStartArray() As Integer = {12, 27, 42, 57, 72, 87, 102}
- Dim OpedLeggedCunky(,) As Char = LoadAllSprites("Open", "Large")
- Dim CloseLeggedCunky(,) As Char = LoadAllSprites("Closed", "Large")
- Dim OpenLeggedSmall(,) As Char = LoadAllSprites("Open", "Small")
- Dim CloseLeggedSmall(,) As Char = LoadAllSprites("Closed", "Small")
- Dim OpenLeggedMedium(,) As Char = LoadAllSprites("Open", "Medium")
- Dim CloseLeggedMedium(,) As Char = LoadAllSprites("Closed", "Medium")
- Dim PlayerShip(,) As Char = {{" ", " ", " ", " ", " ", " ", "█", " ", " ", " ", " ", " ", " "},
- {" ", " ", " ", " ", " ", "█", "█", "█", " ", " ", " ", " ", " "},
- {" ", " ", " ", " ", " ", "█", "█", "█", " ", " ", " ", " ", " "},
- {" ", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", " "},
- {"█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█"},
- {"█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█"},
- {"█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█"},
- {"█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█"}}
- Dim UFO(,) As Char = {
- {" ", " ", " ", " ", " ", " ", "█", "█", "█", "█", " ", " ", " ", " ", " ", " "},
- {" ", " ", " ", " ", "█", "█", "█", "█", "█", "█", "█", "█", " ", " ", " ", " "},
- {" ", " ", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", " ", " "},
- {" ", "█", "█", " ", "█", "█", " ", "█", "█", " ", "█", "█", " ", "█", "█", " "},
- {"█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█"},
- {" ", " ", "█", "█", "█", " ", "█", "█", "█", "█", " ", "█", "█", "█", " ", " "},
- {" ", " ", " ", "█", " ", " ", " ", " ", " ", " ", " ", " ", "█", " ", " ", " "}}
- Function LoadAllSprites(ByVal Leg As String, ByVal Type As String) As Char(,)
- Select Case Leg
- Case Is = "Open"
- Select Case Type
- Case Is = "Small"
- LoadAllSprites = LoadOpenSmall()
- Case Is = "Medium"
- LoadAllSprites = LoadOpenMedium()
- Case Is = "Large"
- LoadAllSprites = LoadOpenLarge()
- End Select
- Case Is = "Closed"
- Select Case Type
- Case Is = "Small"
- LoadAllSprites = LoadClosedSmall()
- Case Is = "Medium"
- LoadAllSprites = LoadClosedMedium()
- Case Is = "Large"
- LoadAllSprites = LoadClosedLarge()
- End Select
- End Select
- End Function
- Function LoadOpenSmall() As Char(,)
- Dim temp As String
- FileOpen(1, Location & "OpenSmall.txt", OpenMode.Input)
- temp = LineInput(1)
- For outlooper = 1 To 8
- For looper = 1 To 12
- Select Case Mid(temp, looper, 1)
- Case Is = "¦"
- LoadOpenSmall(outlooper, looper) = "█"
- Case Else
- LoadOpenSmall(outlooper, looper) = " "
- End Select
- Next
- Next
- FileClose(1)
- End Function
- Function LoadClosedSmall() As Char(,)
- Dim temp As String
- FileOpen(1, Location & "ClosedSmall.txt", OpenMode.Input)
- temp = LineInput(1)
- For outlooper = 1 To 8
- For looper = 1 To 12
- Select Case Mid(temp, looper, 1)
- Case Is = "¦"
- LoadOpenSmall(outlooper, looper) = "█"
- Case Else
- LoadOpenSmall(outlooper, looper) = " "
- End Select
- Next
- Next
- FileClose(1)
- End Function
- Function LoadOpenMedium() As Char(,)
- Dim temp As String
- FileOpen(1, Location & "OpenMedium.txt", OpenMode.Input)
- temp = LineInput(1)
- For outlooper = 1 To 8
- For looper = 1 To 12
- Select Case Mid(temp, looper, 1)
- Case Is = "¦"
- LoadOpenSmall(outlooper, looper) = "█"
- Case Else
- LoadOpenSmall(outlooper, looper) = " "
- End Select
- Next
- Next
- FileClose(1)
- End Function
- Function LoadClosedMedium() As Char(,)
- Dim temp As String
- FileOpen(1, Location & "ClosedMedium.txt", OpenMode.Input)
- temp = LineInput(1)
- For outlooper = 1 To 8
- For looper = 1 To 12
- Select Case Mid(temp, looper, 1)
- Case Is = "¦"
- LoadOpenSmall(outlooper, looper) = "█"
- Case Else
- LoadOpenSmall(outlooper, looper) = " "
- End Select
- Next
- Next
- FileClose(1)
- End Function
- Function LoadOpenLarge() As Char(,)
- Dim temp As String
- FileOpen(1, Location & "OpenLarge.txt", OpenMode.Input)
- temp = LineInput(1)
- For outlooper = 1 To 8
- For looper = 1 To 12
- Select Case Mid(temp, looper, 1)
- Case Is = "¦"
- LoadOpenSmall(outlooper, looper) = "█"
- Case Else
- LoadOpenSmall(outlooper, looper) = " "
- End Select
- Next
- Next
- FileClose(1)
- End Function
- Function LoadClosedLarge() As Char(,)
- Dim temp As String
- FileOpen(1, Location & "ClosedLarge.txt", OpenMode.Input)
- temp = LineInput(1)
- For outlooper = 1 To 8
- For looper = 1 To 12
- Select Case Mid(temp, looper, 1)
- Case Is = "¦"
- LoadOpenSmall(outlooper, looper) = "█"
- Case Else
- LoadOpenSmall(outlooper, looper) = " "
- End Select
- Next
- Next
- FileClose(1)
- End Function
- Sub Main()
- Dim MoveInvaders As New Threading.Thread(AddressOf TheThread1)
- Dim MoveShip As New Threading.Thread(AddressOf MoveMyShip)
- Console.CursorVisible = False
- Console.ForegroundColor = ConsoleColor.White
- Console.SetBufferSize(WindowWidth, WindowHeight)
- Console.SetWindowSize(WindowWidth, WindowHeight)
- MoveInvaders.Start()
- MoveShip.Start()
- Console.ReadLine()
- End Sub
- Sub DoTheRows(ByVal looper As Integer, ByVal counter As Integer, ByVal legcounter As Integer)
- If legcounter Mod 2 = 0 Then
- RowOfAliens(XStartArray, looper, 5 + counter, OpenLeggedSmall, WorldMap)
- RowOfAliens(XStartArray, looper, 20 + counter, OpenLeggedMedium, WorldMap)
- RowOfAliens(XStartArray, looper, 35 + counter, OpenLeggedMedium, WorldMap)
- RowOfAliens(XStartArray, looper, 50 + counter, OpenLeggedMedium, WorldMap)
- RowOfAliens(XStartArray, looper, 65 + counter, OpedLeggedCunky, WorldMap)
- Else
- RowOfAliens(XStartArray, looper, 5 + counter, CloseLeggedSmall, WorldMap)
- RowOfAliens(XStartArray, looper, 20 + counter, CloseLeggedMedium, WorldMap)
- RowOfAliens(XStartArray, looper, 35 + counter, CloseLeggedMedium, WorldMap)
- RowOfAliens(XStartArray, looper, 50 + counter, OpedLeggedCunky, WorldMap)
- RowOfAliens(XStartArray, looper, 65 + counter, OpedLeggedCunky, WorldMap)
- End If
- End Sub
- Sub TheThread1()
- Dim counter As Integer = 0
- Dim LegCounter As Integer
- Do
- For looper = -5 To 7
- DoTheRows(looper, counter, LegCounter)
- WorldString = ""
- WorldString = MapToString(WorldString, WorldMap, WindowHeight - 10, WindowWidth - 1)
- Console.SetCursorPosition(0, 0)
- Console.Write(WorldString)
- Threading.Thread.Sleep(500)
- ClearTheMap(WorldMap, WindowHeight - 10, WindowWidth - 1)
- LegCounter += 1
- Next
- counter += 1
- For looper = 7 To -5 Step -1
- DoTheRows(looper, counter, LegCounter)
- WorldString = ""
- WorldString = MapToString(WorldString, WorldMap, WindowHeight - 10, WindowWidth - 1)
- Console.SetCursorPosition(0, 0)
- Console.Write(WorldString)
- Threading.Thread.Sleep(500)
- ClearTheMap(WorldMap, WindowHeight - 10, WindowWidth - 1)
- LegCounter += 1
- Next
- counter += 1
- Loop
- End Sub
- Sub RowOfAliens(ByVal Xstart As Integer(), ByVal Adder As Integer, ByVal Ystart As Integer, ByVal Invader As Char(,), ByVal worldMap As Char(,))
- For looper = 0 To 6
- AddSpriteToMap(Xstart(looper) + Adder, Ystart, Invader, worldMap, 7, 11)
- Next
- End Sub
- Sub ClearTheMap(ByVal MyMap As Char(,), ByVal Height As Integer, ByVal width As Integer)
- For looper = 0 To Height
- For looper2 = 0 To width
- MyMap(looper, looper2) = " "
- Next
- Next
- End Sub
- Sub AddSpriteToMap(ByVal XStart As Integer, ByVal YStart As Integer, ByVal Sprite As Char(,), ByVal MyMap As Char(,), ByVal Height As Integer, ByVal Width As Integer)
- For looper = 0 To Width
- For looper2 = 0 To Height
- If Sprite(looper2, looper) = " " Then
- MyMap(YStart + looper2, XStart + looper) = " "
- Else
- MyMap(YStart + looper2, XStart + looper) = "█"
- End If
- Next
- Next
- End Sub
- Function MapToString(ByVal MyString As String, ByVal MyMap(,) As Char, ByVal Height As Integer, ByVal Width As Integer) As String
- For looperX = 0 To Height
- For looperY = 0 To Width
- If looperY = Height Then
- MyString = MyString & vbCrLf
- Else
- MyString = MyString & MyMap(looperX, looperY)
- End If
- Next
- Next
- Return MyString
- End Function
- Function MoveMyShip()
- Dim ystart As Integer = WindowHeight - 8
- Dim XStart As Integer = (WindowWidth / 2) - 6
- Dim Input As ConsoleKey
- Do
- Input = GetUserInput()
- If Input = ConsoleKey.LeftArrow Then
- XStart -= 1
- End If
- If Input = ConsoleKey.RightArrow Then
- XStart += 1
- End If
- ClearTheMap(ShipMap, 8, WindowWidth - 1)
- AddSpriteToMap(XStart, 0, PlayerShip, ShipMap, 7, 12)
- Console.SetCursorPosition(0, ystart)
- ShipString = MapToString(ShipString, ShipMap, 7, WindowWidth - 1)
- Console.Write(ShipString)
- ShipString = ""
- Loop
- End Function
- Sub AddShipToShipMap()
- End Sub
- Function GetUserInput() As ConsoleKey
- Dim Input As ConsoleKey
- Do Until Input = ConsoleKey.LeftArrow Or Input = ConsoleKey.RightArrow
- Input = Console.ReadKey(True).Key
- Loop
- Threading.Thread.Sleep(500)
- Return ConsoleKey.LeftArrow
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement