Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 12.16 KB | None | 0 0
  1. Module Module1
  2.     Const Location = "C:\SpaceInvadersSprites\"
  3.     Dim WindowHeight As Integer = Console.LargestWindowHeight - 1
  4.     Dim WindowWidth As Integer = 128
  5.     Dim WorldMap(WindowHeight - 9, WindowWidth) As Char
  6.     Dim ShipMap(8, WindowWidth) As Char
  7.     Dim ShipString As String
  8.     Dim WorldString As String
  9.     Dim XStartArray() As Integer = {12, 27, 42, 57, 72, 87, 102}
  10.     Dim OpedLeggedCunky(,) As Char = LoadAllSprites("Open", "Large")
  11.     Dim CloseLeggedCunky(,) As Char = LoadAllSprites("Closed", "Large")
  12.     Dim OpenLeggedSmall(,) As Char = LoadAllSprites("Open", "Small")
  13.     Dim CloseLeggedSmall(,) As Char = LoadAllSprites("Closed", "Small")
  14.     Dim OpenLeggedMedium(,) As Char = LoadAllSprites("Open", "Medium")
  15.     Dim CloseLeggedMedium(,) As Char = LoadAllSprites("Closed", "Medium")
  16.     Dim PlayerShip(,) As Char = {{" ", " ", " ", " ", " ", " ", "█", " ", " ", " ", " ", " ", " "},
  17.                            {" ", " ", " ", " ", " ", "█", "█", "█", " ", " ", " ", " ", " "},
  18.                            {" ", " ", " ", " ", " ", "█", "█", "█", " ", " ", " ", " ", " "},
  19.                            {" ", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", " "},
  20.                            {"█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█"},
  21.                            {"█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█"},
  22.                            {"█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█"},
  23.                            {"█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█"}}
  24.     Dim UFO(,) As Char = {
  25.                            {" ", " ", " ", " ", " ", " ", "█", "█", "█", "█", " ", " ", " ", " ", " ", " "},
  26.                            {" ", " ", " ", " ", "█", "█", "█", "█", "█", "█", "█", "█", " ", " ", " ", " "},
  27.                            {" ", " ", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", " ", " "},
  28.                            {" ", "█", "█", " ", "█", "█", " ", "█", "█", " ", "█", "█", " ", "█", "█", " "},
  29.                            {"█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█", "█"},
  30.                            {" ", " ", "█", "█", "█", " ", "█", "█", "█", "█", " ", "█", "█", "█", " ", " "},
  31.                            {" ", " ", " ", "█", " ", " ", " ", " ", " ", " ", " ", " ", "█", " ", " ", " "}}
  32.     Function LoadAllSprites(ByVal Leg As String, ByVal Type As String) As Char(,)
  33.         Select Case Leg
  34.             Case Is = "Open"
  35.                 Select Case Type
  36.                     Case Is = "Small"
  37.                         LoadAllSprites = LoadOpenSmall()
  38.                     Case Is = "Medium"
  39.                         LoadAllSprites = LoadOpenMedium()
  40.                     Case Is = "Large"
  41.                         LoadAllSprites = LoadOpenLarge()
  42.                 End Select
  43.             Case Is = "Closed"
  44.                 Select Case Type
  45.                     Case Is = "Small"
  46.                         LoadAllSprites = LoadClosedSmall()
  47.                     Case Is = "Medium"
  48.                         LoadAllSprites = LoadClosedMedium()
  49.                     Case Is = "Large"
  50.                         LoadAllSprites = LoadClosedLarge()
  51.                 End Select
  52.         End Select
  53.     End Function
  54.     Function LoadOpenSmall() As Char(,)
  55.         Dim temp As String
  56.         FileOpen(1, Location & "OpenSmall.txt", OpenMode.Input)
  57.         temp = LineInput(1)
  58.         For outlooper = 1 To 8
  59.             For looper = 1 To 12
  60.                 Select Case Mid(temp, looper, 1)
  61.                     Case Is = "¦"
  62.                         LoadOpenSmall(outlooper, looper) = "█"
  63.                     Case Else
  64.                         LoadOpenSmall(outlooper, looper) = " "
  65.                 End Select
  66.             Next
  67.         Next
  68.         FileClose(1)
  69.     End Function
  70.     Function LoadClosedSmall() As Char(,)
  71.         Dim temp As String
  72.         FileOpen(1, Location & "ClosedSmall.txt", OpenMode.Input)
  73.         temp = LineInput(1)
  74.         For outlooper = 1 To 8
  75.             For looper = 1 To 12
  76.                 Select Case Mid(temp, looper, 1)
  77.                     Case Is = "¦"
  78.                         LoadOpenSmall(outlooper, looper) = "█"
  79.                     Case Else
  80.                         LoadOpenSmall(outlooper, looper) = " "
  81.                 End Select
  82.             Next
  83.         Next
  84.         FileClose(1)
  85.     End Function
  86.     Function LoadOpenMedium() As Char(,)
  87.         Dim temp As String
  88.         FileOpen(1, Location & "OpenMedium.txt", OpenMode.Input)
  89.         temp = LineInput(1)
  90.         For outlooper = 1 To 8
  91.             For looper = 1 To 12
  92.                 Select Case Mid(temp, looper, 1)
  93.                     Case Is = "¦"
  94.                         LoadOpenSmall(outlooper, looper) = "█"
  95.                     Case Else
  96.                         LoadOpenSmall(outlooper, looper) = " "
  97.                 End Select
  98.             Next
  99.         Next
  100.         FileClose(1)
  101.     End Function
  102.     Function LoadClosedMedium() As Char(,)
  103.         Dim temp As String
  104.         FileOpen(1, Location & "ClosedMedium.txt", OpenMode.Input)
  105.         temp = LineInput(1)
  106.         For outlooper = 1 To 8
  107.             For looper = 1 To 12
  108.                 Select Case Mid(temp, looper, 1)
  109.                     Case Is = "¦"
  110.                         LoadOpenSmall(outlooper, looper) = "█"
  111.                     Case Else
  112.                         LoadOpenSmall(outlooper, looper) = " "
  113.                 End Select
  114.             Next
  115.         Next
  116.         FileClose(1)
  117.     End Function
  118.     Function LoadOpenLarge() As Char(,)
  119.         Dim temp As String
  120.         FileOpen(1, Location & "OpenLarge.txt", OpenMode.Input)
  121.         temp = LineInput(1)
  122.         For outlooper = 1 To 8
  123.             For looper = 1 To 12
  124.                 Select Case Mid(temp, looper, 1)
  125.                     Case Is = "¦"
  126.                         LoadOpenSmall(outlooper, looper) = "█"
  127.                     Case Else
  128.                         LoadOpenSmall(outlooper, looper) = " "
  129.                 End Select
  130.             Next
  131.         Next
  132.         FileClose(1)
  133.     End Function
  134.     Function LoadClosedLarge() As Char(,)
  135.         Dim temp As String
  136.         FileOpen(1, Location & "ClosedLarge.txt", OpenMode.Input)
  137.         temp = LineInput(1)
  138.         For outlooper = 1 To 8
  139.             For looper = 1 To 12
  140.                 Select Case Mid(temp, looper, 1)
  141.                     Case Is = "¦"
  142.                         LoadOpenSmall(outlooper, looper) = "█"
  143.                     Case Else
  144.                         LoadOpenSmall(outlooper, looper) = " "
  145.                 End Select
  146.             Next
  147.         Next
  148.         FileClose(1)
  149.     End Function
  150.     Sub Main()
  151.         Dim MoveInvaders As New Threading.Thread(AddressOf TheThread1)
  152.         Dim MoveShip As New Threading.Thread(AddressOf MoveMyShip)
  153.         Console.CursorVisible = False
  154.  
  155.  
  156.         Console.ForegroundColor = ConsoleColor.White
  157.  
  158.         Console.SetBufferSize(WindowWidth, WindowHeight)
  159.         Console.SetWindowSize(WindowWidth, WindowHeight)
  160.         MoveInvaders.Start()
  161.         MoveShip.Start()
  162.         Console.ReadLine()
  163.     End Sub
  164.     Sub DoTheRows(ByVal looper As Integer, ByVal counter As Integer, ByVal legcounter As Integer)
  165.         If legcounter Mod 2 = 0 Then
  166.             RowOfAliens(XStartArray, looper, 5 + counter, OpenLeggedSmall, WorldMap)
  167.             RowOfAliens(XStartArray, looper, 20 + counter, OpenLeggedMedium, WorldMap)
  168.             RowOfAliens(XStartArray, looper, 35 + counter, OpenLeggedMedium, WorldMap)
  169.             RowOfAliens(XStartArray, looper, 50 + counter, OpenLeggedMedium, WorldMap)
  170.             RowOfAliens(XStartArray, looper, 65 + counter, OpedLeggedCunky, WorldMap)
  171.         Else
  172.             RowOfAliens(XStartArray, looper, 5 + counter, CloseLeggedSmall, WorldMap)
  173.             RowOfAliens(XStartArray, looper, 20 + counter, CloseLeggedMedium, WorldMap)
  174.             RowOfAliens(XStartArray, looper, 35 + counter, CloseLeggedMedium, WorldMap)
  175.             RowOfAliens(XStartArray, looper, 50 + counter, OpedLeggedCunky, WorldMap)
  176.             RowOfAliens(XStartArray, looper, 65 + counter, OpedLeggedCunky, WorldMap)
  177.         End If
  178.     End Sub
  179.     Sub TheThread1()
  180.         Dim counter As Integer = 0
  181.         Dim LegCounter As Integer
  182.         Do
  183.             For looper = -5 To 7
  184.                 DoTheRows(looper, counter, LegCounter)
  185.  
  186.                 WorldString = ""
  187.                 WorldString = MapToString(WorldString, WorldMap, WindowHeight - 10, WindowWidth - 1)
  188.                 Console.SetCursorPosition(0, 0)
  189.  
  190.                 Console.Write(WorldString)
  191.                 Threading.Thread.Sleep(500)
  192.                 ClearTheMap(WorldMap, WindowHeight - 10, WindowWidth - 1)
  193.                 LegCounter += 1
  194.             Next
  195.             counter += 1
  196.             For looper = 7 To -5 Step -1
  197.                 DoTheRows(looper, counter, LegCounter)
  198.                 WorldString = ""
  199.                 WorldString = MapToString(WorldString, WorldMap, WindowHeight - 10, WindowWidth - 1)
  200.                 Console.SetCursorPosition(0, 0)
  201.  
  202.                 Console.Write(WorldString)
  203.                 Threading.Thread.Sleep(500)
  204.                 ClearTheMap(WorldMap, WindowHeight - 10, WindowWidth - 1)
  205.                 LegCounter += 1
  206.             Next
  207.             counter += 1
  208.         Loop
  209.     End Sub
  210.     Sub RowOfAliens(ByVal Xstart As Integer(), ByVal Adder As Integer, ByVal Ystart As Integer, ByVal Invader As Char(,), ByVal worldMap As Char(,))
  211.         For looper = 0 To 6
  212.             AddSpriteToMap(Xstart(looper) + Adder, Ystart, Invader, worldMap, 7, 11)
  213.  
  214.         Next
  215.     End Sub
  216.     Sub ClearTheMap(ByVal MyMap As Char(,), ByVal Height As Integer, ByVal width As Integer)
  217.         For looper = 0 To Height
  218.             For looper2 = 0 To width
  219.                 MyMap(looper, looper2) = " "
  220.             Next
  221.         Next
  222.  
  223.     End Sub
  224.     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)
  225.         For looper = 0 To Width
  226.             For looper2 = 0 To Height
  227.                 If Sprite(looper2, looper) = " " Then
  228.                     MyMap(YStart + looper2, XStart + looper) = " "
  229.                 Else
  230.                     MyMap(YStart + looper2, XStart + looper) = "█"
  231.                 End If
  232.  
  233.             Next
  234.         Next
  235.     End Sub
  236.     Function MapToString(ByVal MyString As String, ByVal MyMap(,) As Char, ByVal Height As Integer, ByVal Width As Integer) As String
  237.         For looperX = 0 To Height
  238.             For looperY = 0 To Width
  239.                 If looperY = Height Then
  240.                     MyString = MyString & vbCrLf
  241.                 Else
  242.                     MyString = MyString & MyMap(looperX, looperY)
  243.                 End If
  244.             Next
  245.         Next
  246.         Return MyString
  247.     End Function
  248.     Function MoveMyShip()
  249.         Dim ystart As Integer = WindowHeight - 8
  250.         Dim XStart As Integer = (WindowWidth / 2) - 6
  251.         Dim Input As ConsoleKey
  252.         Do
  253.             Input = GetUserInput()
  254.  
  255.             If Input = ConsoleKey.LeftArrow Then
  256.                 XStart -= 1
  257.             End If
  258.             If Input = ConsoleKey.RightArrow Then
  259.                 XStart += 1
  260.             End If
  261.             ClearTheMap(ShipMap, 8, WindowWidth - 1)
  262.             AddSpriteToMap(XStart, 0, PlayerShip, ShipMap, 7, 12)
  263.             Console.SetCursorPosition(0, ystart)
  264.             ShipString = MapToString(ShipString, ShipMap, 7, WindowWidth - 1)
  265.             Console.Write(ShipString)
  266.             ShipString = ""
  267.         Loop
  268.     End Function
  269.     Sub AddShipToShipMap()
  270.  
  271.  
  272.     End Sub
  273.     Function GetUserInput() As ConsoleKey
  274.         Dim Input As ConsoleKey
  275.         Do Until Input = ConsoleKey.LeftArrow Or Input = ConsoleKey.RightArrow
  276.             Input = Console.ReadKey(True).Key
  277.         Loop
  278.         Threading.Thread.Sleep(500)
  279.         Return ConsoleKey.LeftArrow
  280.     End Function
  281. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement