Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Public enemyList As New List(Of PictureBox)
- Public fortressList As New List(Of PictureBox)
- Public moveAmt As Integer
- Public score As Integer
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Call initGame()
- End Sub
- Public Sub initGame()
- moveAmt = 2
- score = 0
- lblScore.Text = score
- picBullet.Visible = False
- enemyList.Add(picEnemy1)
- enemyList.Add(picEnemy2)
- enemyList.Add(picEnemy3)
- enemyList.Add(picEnemy4)
- enemyList.Add(picEnemy5)
- enemyList.Add(picEnemy6)
- enemyList.Add(picEnemy7)
- enemyList.Add(picEnemy8)
- enemyList.Add(picEnemy9)
- enemyList.Add(picEnemy10)
- enemyList.Add(picEnemy11)
- enemyList.Add(picEnemy12)
- enemyList.Add(picEnemy13)
- enemyList.Add(picEnemy14)
- enemyList.Add(picEnemy15)
- enemyList.Add(picEnemy16)
- fortressList.Add(picFort1)
- fortressList.Add(picFort2)
- fortressList.Add(picFort3)
- fortressList.Add(picFort4)
- End Sub
- Private Sub picBullet_Click(sender As Object, e As EventArgs) Handles picBullet.Click
- End Sub
- Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
- 'move ship
- If e.KeyCode = Keys.Left Then
- picShip.Left = picShip.Left - 3
- ElseIf e.KeyCode = Keys.Right Then
- picShip.Left = picShip.Left + 3
- End If
- 'dont refire the same bullet
- If picBullet.Visible = True Then
- Exit Sub
- End If
- 'fire bubble
- If e.KeyCode = Keys.Space Then
- picBullet.Visible = True
- picBullet.Top = picShip.Top
- picBullet.Left = picShip.Left + picShip.Width / 2 - picBullet.Width / 2
- End If
- End Sub
- Private Sub tmrMoveBullet_Tick(sender As Object, e As EventArgs) Handles tmrMoveBullet.Tick
- 'move bullet
- If picBullet.Visible = True Then
- picBullet.Top = picBullet.Top - 5
- End If
- 'hide bullet is missed
- If picBullet.Top <= 0 Then
- picBullet.Visible = False
- End If
- End Sub
- Public Function detectHits(p1 As PictureBox, p2 As PictureBox) As Boolean
- If ((p1.Left + p1.Width > p2.Left) And
- (p1.Left < p2.Left + p2.Width) And
- (p1.Top + p1.Height > p2.Top) And
- (p1.Top < p2.Top + p2.Height)) Then
- Return True
- Else
- Return False
- End If
- End Function
- Private Sub tmrCollision_Tick(sender As Object, e As EventArgs) Handles tmrCollision.Tick
- Dim p As PictureBox
- If picBullet.Visible = False Then
- Exit Sub
- End If
- For Each p In enemyList
- If p.Visible = True Then
- If detectHits(picBullet, p) Then
- picBullet.Visible = False
- p.Visible = False
- score = score + 1
- lblscore.text = score
- 'CHECK IF ROUND OVER
- If levelOver() = True Then
- Call nextLevel
- End If
- End If
- End If
- Next
- For Each p In fortressList
- If detectHits(picBullet, p) Then
- picBullet.Visible = False
- End If
- Next
- End Sub
- Private Sub tmrMoveEnemies_Tick(sender As Object, e As EventArgs) Handles tmrMoveEnemies.Tick
- Dim p As PictureBox
- Dim edge As Boolean
- edge = False
- For Each p In enemyList
- 'move enemy
- p.Left = p.Left + moveAmt
- 'check edge bounce on both sides
- If p.Visible = True Then
- If (p.Left + p.Width > Me.Width) Or (p.Left <= 0) Then
- edge = True
- End If
- End If
- Next
- If edge = True Then
- 'reverse direction
- moveAmt = -moveAmt
- 'move them down
- For Each p In enemyList
- p.Top = p.Top + 20
- Next
- If gameOver() = True Then
- tmrMoveEnemies.Enabled = False
- MsgBox("Game over")
- End If
- End If
- End Sub
- Public Function gameOver() As Boolean
- Dim p As PictureBox
- Dim done As Boolean
- done = False
- For Each p In enemyList
- If p.Visible = True Then
- If p.Top + p.Height > picShip.Top Then
- done = True
- End If
- End If
- Next
- Return done
- End Function
- Public Function levelOver() As Boolean
- Dim p As PictureBox
- Dim done As Boolean
- done = True
- For Each p In enemyList
- If p.Visible = True Then
- done = False
- End If
- Next
- Return done
- End Function
- Public Sub nextlevel()
- Dim p As PictureBox
- Dim x As Integer
- Dim y As Integer
- For Each p In enemyList
- p.Visible = True
- If enemyList.IndexOf(p) < 4 Then
- p.Top = 50
- ElseIf enemyList.IndexOf(p) < 8 Then
- p.Top = 100
- ElseIf enemyList.IndexOf(p) < 12 Then
- p.Top = 150
- Else
- p.Top = 200
- End If
- Next
- moveAmt = moveAmt * 2
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment