Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- ' variables
- Dim score As Integer
- Dim scores(9) As Integer
- ' initial load
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- ' defaulting variables
- player.Top = 200
- player.Left = 40
- score = 0
- player.Visible = False
- End Sub
- ' game logic
- Private Sub gameloop_Tick(sender As Object, e As EventArgs) Handles gameloop.Tick
- ' continuous movements
- player.Top += 10
- For Each c As Control In Controls
- If c.Tag = "pipe" Or c.Tag = "score" Then
- If c.Left < -40 Then ' checking if it's off screen, then removing it if so
- Controls.Remove(c)
- Else ' if it's on screen, just move it towards the player
- c.Left -= 10
- End If
- End If
- If c.Tag = "collider" Or c.Tag = "pipe" Then ' checking for collision
- If player.Bounds.IntersectsWith(c.Bounds) Then
- resetgame()
- End If
- End If
- If c.Tag = "score" Then ' scoring if player goes between
- If player.Bounds.IntersectsWith(c.Bounds) Then
- Controls.Remove(c)
- score += 1
- scorelabel.Text = "Score: " & score
- End If
- End If
- Next
- End Sub
- Private Sub pipegen_Tick(sender As Object, e As EventArgs) Handles pipegen.Tick
- ' randomizing
- Randomize()
- ' creating top and bottom of pipe
- Dim top As New Control ' top pipe
- Dim bottom As New Control ' bottom pipe
- Dim middle As New Control ' scoring zone
- ' attributes
- top.Width = 50
- top.Height = Int((300 * Rnd()) + 100)
- bottom.Width = 50
- bottom.Height = top.Height - (top.Height - 640)
- middle.Width = 50
- middle.Height = 120
- top.Top = 0
- top.Left = 360
- bottom.Top = top.Height + 120
- bottom.Left = 360
- middle.Top = bottom.Top - 120
- middle.Left = 360
- top.Tag = "pipe"
- bottom.Tag = "pipe"
- middle.Tag = "score"
- bottom.BackColor = Color.DarkGreen
- top.BackColor = Color.DarkGreen
- middle.BackColor = Color.Pink
- ' adding to game
- Controls.Add(top)
- Controls.Add(bottom)
- Controls.Add(middle)
- End Sub
- ' keypresses
- Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
- Select Case e.KeyCode
- Case Keys.Space
- player.Top -= 50
- End Select
- End Sub
- ' buttons
- Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles startbutton.Click
- ' hiding picturebox
- startbutton.Visible = False
- player.Visible = True
- player.Top = 200
- player.Left = 40
- ' score
- score = 0
- scorelabel.Text = "Score: " & score
- ' starting game
- gameloop.Start()
- pipegen.Start()
- End Sub
- ' my subs
- Public Sub resetgame()
- ' defaulting
- pipegen.Stop()
- gameloop.Stop()
- player.Top = 200
- player.Left = 40
- score = 0
- scorelabel.Text = "You Died!"
- startbutton.Visible = True
- player.Visible = False
- ' need to run it three times because otherwise certain controls get left behind...
- destroy()
- destroy()
- destroy()
- End Sub
- ' removing all pictureboxes which arent needed
- Public Sub destroy()
- For Each c As Control In Controls
- If c.Tag = "pipe" Or c.Tag = "score" Then
- Controls.Remove(c)
- End If
- Next
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement