xupaiii

hi

Oct 21st, 2021 (edited)
53
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.     ' variables
  3.     Dim score As Integer
  4.     Dim scores(9) As Integer
  5.  
  6.     ' initial load
  7.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  8.         ' defaulting variables
  9.         player.Top = 200
  10.         player.Left = 40
  11.         score = 0
  12.         player.Visible = False
  13.     End Sub
  14.  
  15.     ' game logic
  16.     Private Sub gameloop_Tick(sender As Object, e As EventArgs) Handles gameloop.Tick
  17.         ' continuous movements
  18.         player.Top += 10
  19.         For Each c As Control In Controls
  20.             If c.Tag = "pipe" Or c.Tag = "score" Then
  21.                 If c.Left < -40 Then ' checking if it's off screen, then removing it if so
  22.                     Controls.Remove(c)
  23.                 Else ' if it's on screen, just move it towards the player
  24.                     c.Left -= 10
  25.                 End If
  26.             End If
  27.             If c.Tag = "collider" Or c.Tag = "pipe" Then ' checking for collision
  28.                 If player.Bounds.IntersectsWith(c.Bounds) Then
  29.                     resetgame()
  30.                 End If
  31.             End If
  32.             If c.Tag = "score" Then ' scoring if player goes between
  33.                 If player.Bounds.IntersectsWith(c.Bounds) Then
  34.                     Controls.Remove(c)
  35.                     score += 1
  36.                     scorelabel.Text = "Score: " & score
  37.                 End If
  38.             End If
  39.         Next
  40.     End Sub
  41.  
  42.     Private Sub pipegen_Tick(sender As Object, e As EventArgs) Handles pipegen.Tick
  43.         ' randomizing
  44.         Randomize()
  45.         ' creating top and bottom of pipe
  46.         Dim top As New Control ' top pipe
  47.         Dim bottom As New Control ' bottom pipe
  48.         Dim middle As New Control ' scoring zone
  49.  
  50.         ' attributes
  51.         top.Width = 50
  52.         top.Height = Int((300 * Rnd()) + 100)
  53.         bottom.Width = 50
  54.         bottom.Height = top.Height - (top.Height - 640)
  55.         middle.Width = 50
  56.         middle.Height = 120
  57.  
  58.         top.Top = 0
  59.         top.Left = 360
  60.         bottom.Top = top.Height + 120
  61.         bottom.Left = 360
  62.         middle.Top = bottom.Top - 120
  63.         middle.Left = 360
  64.  
  65.         top.Tag = "pipe"
  66.         bottom.Tag = "pipe"
  67.         middle.Tag = "score"
  68.         bottom.BackColor = Color.DarkGreen
  69.         top.BackColor = Color.DarkGreen
  70.         middle.BackColor = Color.Pink
  71.  
  72.         ' adding to game
  73.         Controls.Add(top)
  74.         Controls.Add(bottom)
  75.         Controls.Add(middle)
  76.     End Sub
  77.  
  78.     ' keypresses
  79.     Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
  80.         Select Case e.KeyCode
  81.             Case Keys.Space
  82.                 player.Top -= 50
  83.         End Select
  84.     End Sub
  85.  
  86.     ' buttons
  87.     Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles startbutton.Click
  88.         ' hiding picturebox
  89.         startbutton.Visible = False
  90.         player.Visible = True
  91.         player.Top = 200
  92.         player.Left = 40
  93.         ' score
  94.         score = 0
  95.         scorelabel.Text = "Score: " & score
  96.         ' starting game
  97.         gameloop.Start()
  98.         pipegen.Start()
  99.     End Sub
  100.  
  101.     ' my subs
  102.     Public Sub resetgame()
  103.         ' defaulting
  104.         pipegen.Stop()
  105.         gameloop.Stop()
  106.         player.Top = 200
  107.         player.Left = 40
  108.         score = 0
  109.         scorelabel.Text = "You Died!"
  110.         startbutton.Visible = True
  111.         player.Visible = False
  112.         ' need to run it three times because otherwise certain controls get left behind...
  113.         destroy()
  114.         destroy()
  115.         destroy()
  116.     End Sub
  117.  
  118.     ' removing all pictureboxes which arent needed
  119.     Public Sub destroy()
  120.         For Each c As Control In Controls
  121.             If c.Tag = "pipe" Or c.Tag = "score" Then
  122.                 Controls.Remove(c)
  123.             End If
  124.         Next
  125.     End Sub
  126. End Class
RAW Paste Data