Advertisement
Teraunce

Teraunce's game engine circa 2009

Sep 2nd, 2022
1,990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 17.29 KB | None | 0 0
  1.  
  2. Imports System.Math
  3. Imports System.Drawing.Drawing2D
  4. Imports System.IO
  5. Imports System.Uri
  6. Imports System.Threading
  7. Imports System.String
  8. Public Class Form1
  9.     Private lvln As Decimal
  10.     Private leveln As String
  11.     'Private lvl0 As Bitmap = New Bitmap("Prolougelevel.bmp")
  12.     'Private lvl1a As Bitmap
  13.     'Private lvl1b As Bitmap
  14.     Private level As Bitmap
  15.     'repeat for number of levels needed-ignore
  16.     Private canvas As Graphics
  17.     Private sccanvb As Graphics
  18.     Private scpic As Bitmap
  19.     Private sccanvp As Graphics
  20.     Private sccanve As Graphics
  21.     Private sccanva As Graphics
  22.     Private lvlx As Integer = 0
  23.     Private lvly As Integer = 0
  24.     Private lvlw As Integer
  25.     Private lvlht As Integer
  26.     Private terx As Integer = 5
  27.     Private tery As Integer = 5
  28.     Private terw As Integer
  29.     Private terht As Integer
  30.     Private fw As Integer
  31.     Private fht As Integer
  32.     Private picx As Integer
  33.     Private picy As Integer
  34.     Private teraunce As Bitmap = New Bitmap("Teraunce0.bmp")
  35.     Private terrect As Rectangle
  36.     Private ters As Integer = 0
  37.     Private win As Boolean = False
  38.     Private quit As Boolean = False
  39.     Private terj As Integer = 0
  40.     Private terjump1 As Boolean = False
  41.     Private terjump2 As Boolean = False
  42.     Private terjump3 As Boolean
  43.     Private terright As Boolean = False
  44.     Private fired As Boolean = False
  45.     Private floor1 As Rectangle
  46.     Private floor2 As Rectangle
  47.     Private plat1r As Rectangle
  48.     Private plat2r As Rectangle
  49.     Private plat3r As Rectangle
  50.     Private wall1rr As Rectangle
  51.     Private wllrrx1 As Integer
  52.     Private wllrry1 As Integer
  53.     Private wllrrw1 As Integer
  54.     Private wllrrh1 As Integer
  55.     Private wall2rr As Rectangle
  56.     Private wllrrx2 As Integer
  57.     Private wllrry2 As Integer
  58.     Private wllrrw2 As Integer
  59.     Private wllrrh2 As Integer
  60.     Private wall3rr As Rectangle
  61.     Private wllrrx3 As Integer
  62.     Private wllrry3 As Integer
  63.     Private wllrrw3 As Integer
  64.     Private wllrrh3 As Integer
  65.     Private wall1rl As Rectangle
  66.     Private wllrlx1 As Integer
  67.     Private wllrly1 As Integer
  68.     Private wllrlw1 As Integer
  69.     Private wllrlh1 As Integer
  70.     Private wall2rl As Rectangle
  71.     Private wllrlx2 As Integer
  72.     Private wllrly2 As Integer
  73.     Private wllrlw2 As Integer
  74.     Private wllrlh2 As Integer
  75.     Private wall3rl As Rectangle
  76.     Private wllrlx3 As Integer
  77.     Private wllrly3 As Integer
  78.     Private wllrlw3 As Integer
  79.     Private wllrlh3 As Integer
  80.     Private enemy1r As Rectangle
  81.     Private enemy1 As Bitmap
  82.     Private enemy2r As Rectangle
  83.     Private enemy2 As Bitmap
  84.     Private enemy3r As Rectangle
  85.     Private enemy3 As Bitmap
  86.     Private goblin As Bitmap 'enemy bitmaps once found
  87.     Private troll As Bitmap
  88.  
  89.     Private exit1r As Rectangle
  90.     Private exit2r As Rectangle
  91.     Private exit3r As Rectangle
  92.     Private ceilingr As Rectangle
  93.     Private terbit As String
  94.     Private run As Boolean = False
  95.     Private lvlmove As Matrix
  96.     Private termove As Matrix
  97.     Private enemymove As Matrix
  98.     Private terup As Boolean
  99.     Private hp As Integer = 8
  100.     Private maxhp As Integer = 8
  101.     Private mp As Integer = 3
  102.     Private maxmp As Integer = 3
  103.     Private xp As Integer = 0
  104.     Private lvlxp As Integer = 100
  105.     Private TerLvl As Integer = 1
  106.     Private sjump As Decimal
  107.     Private Sjump2 As Decimal
  108.     Private sjump3 As Decimal
  109.     Private arrows As Integer = 20
  110.     Private arrowrect As Rectangle
  111.     Private bitArrow As Bitmap = New Bitmap("arrowr.bmp")
  112.     Private tempstring As String
  113.     Private temprect As Rectangle
  114.     Private rightmove As Matrix
  115.     Private leftmove As Matrix
  116.     Private remover As Rectangle = New Rectangle(-9999, -9999, 1, 1)
  117.     Private gravity As Matrix = New Matrix(1, 0, 0, 1, 0, -5)
  118.     Private antigrav As Matrix = New Matrix(1, 0, 0, 1, 0, 6)
  119.     Private mat_jump As Matrix
  120.     Private dy As Decimal
  121.     Private dx As Decimal
  122.     Private dly As Integer = 0
  123.     Private dlx As Integer = 0
  124.     Private dex As Integer = 0
  125.     Private dey As Integer = 0
  126.     Private dax As Integer = 0
  127.     Private day As Integer = 0
  128.     Private arx As Integer
  129.     Private ary As Integer
  130.     'repeat as necessary
  131.     Private Sub startbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startbtn.Click
  132.         'variables set...
  133.         scpic = New Bitmap(PicAnim.Width, PicAnim.Height)
  134.         terrect = New Rectangle(terx, tery, teraunce.Width, teraunce.Height)
  135.         sccanvb = Graphics.FromImage(scpic)
  136.         sccanvp = Graphics.FromImage(scpic)
  137.         sccanve = Graphics.FromImage(scpic)
  138.         sccanva = Graphics.FromImage(scpic)
  139.         floor1 = remover
  140.         floor2 = remover
  141.         bitArrow.MakeTransparent(Color.Blue)
  142.         fw = PicAnim.Width
  143.         fht = PicAnim.Height
  144.         startbtn.Enabled = False
  145.         closebtn.Enabled = False
  146.         levelselect.Enabled = False
  147.         If levelselect.Text = "   ." Then
  148.             levelselect.Text = "000."
  149.         End If
  150.         lvln = levelselect.Text
  151.         canvas = PicAnim.CreateGraphics
  152.         quit = False
  153.         terht = teraunce.Height
  154.         terw = teraunce.Width
  155.         Do
  156.             If terjump1 = False Then
  157.                 tersprite() 'cycles through idle animation sprites
  158.             Else
  159.                 If terup = True Then 'jump area
  160.                     terjumpup()
  161.                 ElseIf terright = False Then
  162.                     terjumpleft()
  163.                 Else
  164.                     terjumpright()
  165.  
  166.                 End If
  167.             End If
  168.             HPcurLbl.Text = Convert.ToString(hp)
  169.             HPmaxLbl.Text = maxhp
  170.             MPcurLbl.Text = mp
  171.             MPmaxLbl.Text = maxmp
  172.             LvlCurLbl.Text = TerLvl
  173.             XPcurLbl.Text = xp
  174.             NextLvlLbl.Text = lvlxp
  175.             passwordlevel.Text = lvln
  176.             If run = False Then
  177.                 terlevel()
  178.             End If
  179.             'YTF is it skipping levels?---Fixed
  180.             Application.DoEvents()
  181.             canvas.DrawImage(scpic, 0, 0)
  182.             'sccanvb.MultiplyTransform(gravity) 'not transforming for some reason. IDK why though. major bug that needs fixing.
  183.             sccanvb.DrawImage(level, lvlx + dlx, lvly + dly)
  184.             Thread.Sleep(1)
  185.             sccanvp.DrawImage(teraunce, terrect)
  186.             leveldo()
  187.             If hp <= 0 Then
  188.                 lvln = 666
  189.                 lvlx = 0
  190.                 lvly = 0
  191.             End If
  192.             dly = dly - 5
  193.             If run = True Then
  194.                 If terrect.IntersectsWith(enemy1r) = True Then
  195.                     hp = hp - 1
  196.                 ElseIf terrect.IntersectsWith(enemy2r) = True Then
  197.                     hp = hp - 1
  198.                 ElseIf terrect.IntersectsWith(enemy3r) = True Then
  199.                     hp = hp - 1
  200.                 ElseIf terrect.IntersectsWith(exit1r) = True Then
  201.                     fexit1()
  202.                 ElseIf terrect.IntersectsWith(exit2r) = True Then
  203.                     fexit2()
  204.                 ElseIf terrect.IntersectsWith(exit3r) = True Then
  205.                     fexit3()
  206.                 ElseIf terrect.IntersectsWith(floor1) = True Then
  207.                     'sccanvb.MultiplyTransform(antigrav)
  208.                     dly = dly + 6
  209.                 ElseIf terrect.IntersectsWith(floor2) = True Then
  210.                     'sccanvb.MultiplyTransform(antigrav)
  211.                     dly = dly + 6
  212.                 End If
  213.             End If
  214.             If fired = True Then
  215.                 If terright = True Then
  216.                     dax = dax + 10
  217.                 Else
  218.                     dax = dax - 10
  219.                 End If
  220.                 arx = terx + dax - dlx
  221.                 ary = tery + day - dly
  222.                 arrowrect = New Rectangle(arx, ary, bitArrow.Width, bitArrow.Height)
  223.                 sccanva.DrawImage(bitArrow, arrowrect)
  224.                 If temprect.Intersect(arrowrect, enemy1r) <> Nothing Then
  225.                     enemy1r = remover
  226.                     arrowrect = remover
  227.                     fired = False
  228.                     sccanva.DrawImage(bitArrow, arrowrect)
  229.                     sccanve.DrawImage(enemy1, enemy1r)
  230.                     xp = xp + 15
  231.                 ElseIf temprect.Intersect(arrowrect, enemy2r) <> Nothing Then
  232.                     enemy2r = remover
  233.                     arrowrect = remover
  234.                     fired = False
  235.                     sccanva.DrawImage(bitArrow, arrowrect)
  236.                     sccanve.DrawImage(enemy2, enemy2r)
  237.                     xp = xp + 15
  238.                 ElseIf temprect.Intersect(arrowrect, enemy3r) <> Nothing Then
  239.                     enemy3r = remover
  240.                     arrowrect = remover
  241.                     fired = False
  242.                     sccanva.DrawImage(bitArrow, arrowrect)
  243.                     sccanve.DrawImage(enemy3, enemy3r)
  244.                     xp = xp + 15
  245.                 ElseIf ary < 0 Then
  246.                     fired = False
  247.                 ElseIf ary > level.Height Then
  248.                     fired = False
  249.                 ElseIf arx < 0 Then
  250.                     fired = False
  251.                 ElseIf arx > level.Width Then
  252.                     fired = False
  253.                 End If
  254.             End If
  255.             'lvly = lvly - 5
  256.             Thread.Sleep(100)
  257.         Loop Until quit = True
  258.         'Close()
  259.     End Sub
  260.     Function fexit1()
  261.         If lvln = 0 Then
  262.             lvln = 0.1
  263.             terx = 200
  264.         End If
  265.     End Function
  266.     Function fexit2()
  267.  
  268.     End Function
  269.     Function fexit3()
  270.  
  271.     End Function
  272.     Function rectfix()
  273.         wall1rl = New Rectangle(wllrlx1 + lvlx, wllrly1 + lvly, wllrlw1 + lvlx, wllrlh1 + lvly)
  274.         wall2rl = New Rectangle(wllrlx2 + lvlx, wllrly2 + lvly, wllrlw2 + lvlx, wllrlh2 + lvly)
  275.         wall3rl = New Rectangle(wllrlx3 + lvlx, wllrly3 + lvly, wllrlw3 + lvlx, wllrlh3 + lvly)
  276.         wall1rr = New Rectangle(wllrrx1 + lvlx, wllrry1 + lvly, wllrrw1 + lvlx, wllrrh1 + lvly)
  277.         wall2rr = New Rectangle(wllrrx2 + lvlx, wllrry2 + lvly, wllrrw2 + lvlx, wllrrh2 + lvly)
  278.         wall3rr = New Rectangle(wllrrx3 + lvlx, wllrry3 + lvly, wllrrw3 + lvlx, wllrrh3 + lvly)
  279.  
  280.     End Function
  281.     Function tersprite()
  282.         'Do
  283.         If ters <= 16 Then
  284.             terbit = Convert.ToString(ters)
  285.             teraunce = New Bitmap("Teraunce" + terbit + ".bmp") 'should return Teraunce0.bmp to teraunce16.bmp
  286.             ters = ters + 1
  287.             teraunce.MakeTransparent(Color.Blue)
  288.         Else
  289.             ters = 0
  290.         End If
  291.         'Loop While quit = False <---Unneeded, couldn't be escaped.
  292.  
  293.         'sample function-finished
  294.         'TODO://Draw Idle/Walk/jump/glide animation for Teraunce-incomplete; placeholder added.
  295.     End Function
  296.     Function terjumpup()
  297.         If terjump1 = False Then
  298.             sjump = 0
  299.             sjump2 = 0
  300.             sjump3 = 0
  301.         End If
  302.         If terjump1 = True Then
  303.             terjump1 = False
  304.             terbit = Convert.ToString(sjump)
  305.             sjump = sjump + 0.1
  306.             teraunce = New Bitmap("teraunce" + terbit + "u1.bmp")
  307.             dly = ((16 * (sjump ^ 2)) - (50 * sjump)) * -1
  308.             mat_jump = New Matrix(0, 1, 1, 0, 0, -dy)
  309.             'sccanvb.MultiplyTransform(mat_jump)
  310.         ElseIf terjump2 = True Then
  311.             terjump1 = False
  312.             terbit = Convert.ToString(Sjump2)
  313.             Sjump2 = Sjump2 + 0.1
  314.             teraunce = New Bitmap("teraunce" + terbit + "u2.bmp")
  315.             dly = ((16 * (Sjump2 ^ 2)) - (50 * Sjump2)) * -1
  316.             mat_jump = New Matrix(0, 1, 1, 0, 0, -dy)
  317.             'sccanvb.MultiplyTransform(mat_jump)
  318.         Else
  319.             If terright = True Then
  320.                 terglideright()
  321.             Else
  322.                 terglideleft()
  323.             End If
  324.         End If
  325.     End Function
  326.  
  327.     Function terjumpright()
  328.         terjump1 = False
  329.     End Function
  330.     Function terjumpleft()
  331.         terjump1 = False
  332.     End Function
  333.  
  334.     Function terglideright()
  335.  
  336.     End Function
  337.     Function terglideleft()
  338.  
  339.     End Function
  340.     Function terlevel()
  341.         leveln = Convert.ToString(lvln)
  342.         level = New Bitmap("level" + leveln + ".bmp")
  343.  
  344.     End Function
  345.     Function leveldo()
  346.         If lvln = 0.0 Then
  347.             'lvly = lvly
  348.             If run = False Then
  349.                 sccanvb.DrawImage(level, lvlx, lvly)
  350.                 run = True
  351.             ElseIf run = True Then
  352.                 Thread.Sleep(1)
  353.             End If
  354.         ElseIf lvln = 0.1 Then
  355.             If run = False Then
  356.                 sccanvb.DrawImage(level, lvlx, lvly)
  357.                 run = True
  358.             ElseIf run = True Then
  359.  
  360.             End If
  361.         Else
  362.             If run = False Then
  363.                 sccanvb.DrawImage(level, lvlx, lvly)
  364.                 run = True
  365.             Else
  366.  
  367.             End If
  368.         End If
  369.     End Function
  370.  
  371.     Private Sub closebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closebtn.Click
  372.         If quit = False Then
  373.             quit = True
  374.             startbtn.Enabled = True
  375.             levelselect.Enabled = True
  376.             run = False
  377.         Else
  378.             Close()
  379.         End If
  380.     End Sub
  381.  
  382.     Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  383.         If e.KeyCode = Keys.NumPad8 Then
  384.             terup = True
  385.             If terjump1 = False Then
  386.                 terjump1 = True
  387.                 terjumpup()
  388.             ElseIf terjump2 = False Then
  389.                 terjump2 = True
  390.                 terjumpup()
  391.             Else
  392.                 If terright = True Then
  393.                     terglideright()
  394.                 Else
  395.                     terglideleft()
  396.                 End If
  397.             End If
  398.         ElseIf e.KeyCode = Keys.NumPad9 Then
  399.             terright = True
  400.             If terjump1 = False Then
  401.                 terjump1 = True
  402.                 terjumpright()
  403.             ElseIf terjump2 = False Then
  404.                 terjump2 = True
  405.                 terjumpright()
  406.             Else
  407.                 If terright = True Then
  408.                     terglideright()
  409.                 Else
  410.                     terglideleft()
  411.                 End If
  412.             End If
  413.         ElseIf e.KeyCode = Keys.NumPad7 Then
  414.             terright = False
  415.             If terjump1 = False Then
  416.                 terjump1 = True
  417.                 terjumpleft()
  418.             ElseIf terjump2 = False Then
  419.                 terjump2 = True
  420.                 terjumpleft()
  421.             Else
  422.                 If terright = True Then
  423.                     terglideright()
  424.                 Else
  425.                     terglideleft()
  426.                 End If
  427.             End If
  428.         ElseIf e.KeyCode = Keys.End Then
  429.             closebtn_Click(sender, e)
  430.         ElseIf e.KeyCode = Keys.NumPad4 Then
  431.             terup = False
  432.             dlx = dlx + 3
  433.             terright = False
  434.         ElseIf e.KeyCode = Keys.NumPad6 Then
  435.             terup = False
  436.             terright = True
  437.             dlx = dlx - 3
  438.         ElseIf e.KeyCode = Keys.ControlKey Then
  439.             If arrows > 0 Then
  440.                 If fired = False Then
  441.                     dax = 0
  442.                     day = 0
  443.                     arrowrect = New Rectangle(terx, tery, bitArrow.Width, bitArrow.Height)
  444.                     If terright = True Then
  445.                         bitArrow = New Bitmap("arrowr.bmp")
  446.                     Else
  447.                         bitArrow = New Bitmap("arrowl.bmp")
  448.                     End If
  449.                     bitArrow.MakeTransparent(Color.Blue)
  450.                     sccanva.DrawImage(bitArrow, arrowrect)
  451.                     dax = 0
  452.                     day = 0
  453.                     fired = True
  454.                     arrows = arrows - 1
  455.                     NumArrowLbl.Text = arrows
  456.                 Else
  457.                     tempstring = New String("Wait!")
  458.                     NumArrowLbl.Text = tempstring
  459.                 End If
  460.             Else
  461.                 tempstring = New String("Empty")
  462.                 NumArrowLbl.Text = tempstring
  463.             End If
  464.         End If
  465.     End Sub
  466.  
  467.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  468.  
  469.     End Sub
  470.  
  471.     Private Sub HPcurLbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HPcurLbl.Click
  472.  
  473.     End Sub
  474.  
  475.     Private Sub HPmaxLbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HPmaxLbl.Click
  476.  
  477.     End Sub
  478.  
  479.     Private Sub LvlCurLbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LvlCurLbl.Click
  480.  
  481.     End Sub
  482.  
  483.     Private Sub MPcurLbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MPcurLbl.Click
  484.  
  485.     End Sub
  486.  
  487.     Private Sub MPmaxLbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MPmaxLbl.Click
  488.  
  489.     End Sub
  490.  
  491.     Private Sub XPcurLbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XPcurLbl.Click
  492.  
  493.     End Sub
  494.  
  495.     Private Sub NextLvlLbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextLvlLbl.Click
  496.  
  497.     End Sub
  498.  
  499.     Private Sub NumArrowLbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumArrowLbl.Click
  500.  
  501.     End Sub
  502. End Class
  503.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement