top of page

Alien Game

Public Class Form1

    Dim Score As Integer

    Private Sub butMoveAlien_Click(sender As Object, e As EventArgs) Handles butMoveAlien.Click
        StartnFinish.Visible = False
        butMoveAlien.Enabled = False
        butMoveAlien.Visible = False
        MoveTimer.Enabled = True
        Xpos.Visible = False
        Ypos.Visible = False
        DownAdd.Visible = False
        RightAdd.Visible = False
        labMessage.Visible = False
        Alien1.Image = Image.FromFile("AlienUpBig.png")
        Dim Score As Integer

        Xpos.Text += CInt(RightAdd.Text)
        Ypos.Text += CInt(DownAdd.Text)

        If Xpos.Text > 200 Then RightAdd.Text = -20
        If Xpos.Text > 200 Then Ypos.Text += 20
        If Xpos.Text < 0 Then RightAdd.Text = 20
        If Xpos.Text < 0 Then Ypos.Text += 20
        Dim Remainder = Xpos.Text Mod 40
        'Location Start'
        Alien1.Location = New Point(Xpos.Text, Ypos.Text)
        Alien2.Location = New Point(Xpos.Text + 120, Ypos.Text)
        Alien3.Location = New Point(Xpos.Text + 240, Ypos.Text)
        Alien4.Location = New Point(Xpos.Text + 360, Ypos.Text)
        Alien5.Location = New Point(Xpos.Text + 480, Ypos.Text)

        'Animation'
        If Remainder = 20 Then Alien1.Image = Image.FromFile("AlienUpBig.png")
        If Remainder = 0 Then Alien1.Image = Image.FromFile("AlienDownBig.png")

        If Remainder = 20 Then Alien2.Image = Image.FromFile("AlienUpBig.png")
        If Remainder = 0 Then Alien2.Image = Image.FromFile("AlienDownBig.png")

        If Remainder = 20 Then Alien3.Image = Image.FromFile("AlienUpBig.png")
        If Remainder = 0 Then Alien3.Image = Image.FromFile("AlienDownBig.png")

        If Remainder = 20 Then Alien4.Image = Image.FromFile("AlienUpBig.png")
        If Remainder = 0 Then Alien4.Image = Image.FromFile("AlienDownBig.png")

        If Remainder = 20 Then Alien5.Image = Image.FromFile("AlienUpBig.png")
        If Remainder = 0 Then Alien5.Image = Image.FromFile("AlienDownBig.png")
        'Dectection'

        If Bullet1.Location.Y > Alien1.Location.Y And Bullet1.Location.Y <= Alien1.Location.Y + 100 And Bullet1.Location.X > Alien1.Location.X And Bullet1.Location.X <= Alien1.Location.X + 100 Then
            Alien1.Visible = False
            Score = Score + 1
        End If

        If Bullet1.Location.Y > Alien2.Location.Y And Bullet1.Location.Y <= Alien2.Location.Y + 100 And Bullet1.Location.X > Alien2.Location.X And Bullet1.Location.X <= Alien2.Location.X + 100 Then
            Alien2.Visible = False
        End If

        If Bullet1.Location.Y > Alien3.Location.Y And Bullet1.Location.Y <= Alien3.Location.Y + 100 And Bullet1.Location.X > Alien3.Location.X And Bullet1.Location.X <= Alien3.Location.X + 100 Then
            Alien3.Visible = False

        End If

        If Bullet1.Location.Y > Alien4.Location.Y And Bullet1.Location.Y <= Alien4.Location.Y + 100 And Bullet1.Location.X > Alien4.Location.X And Bullet1.Location.X <= Alien4.Location.X + 100 Then
            Alien4.Visible = False
        End If

        If Bullet1.Location.Y > Alien5.Location.Y And Bullet1.Location.Y <= Alien5.Location.Y + 100 And Bullet1.Location.X > Alien5.Location.X And Bullet1.Location.X <= Alien5.Location.X + 100 Then
            Alien5.Visible = False

        End If
        If Alien1.Visible = False Then Score += 1
        If Alien2.Visible = False Then Score += 1
        If Alien3.Visible = False Then Score += 1
        If Alien4.Visible = False Then Score += 1
        If Alien5.Visible = False Then Score += 1
        'Once every alien is killed'
        If Alien1.Visible = False And Alien2.Visible = False And Alien3.Visible = False And Alien4.Visible = False And Alien5.Visible = False Then
            MoveTimer.Enabled = False
            StartnFinish.Visible = True
            StartnFinish.Image = Image.FromFile("Win.png")
            Call MsgBox("Your Score: " & Score, 0, "Good Job!")
            End
        End If
        'If Aliens Reach Earth'
        If Alien1.Location.Y = 500 Or Alien2.Location.Y = 500 Or Alien3.Location.Y = 520 Or Alien4.Location.Y = 520 Or Alien5.Location.Y = 500 Then
            MoveTimer.Enabled = False
            StartnFinish.Visible = True
            StartnFinish.Image = Image.FromFile("Lose.png")
            Call MsgBox("You Killed: " & Score & " but they reached earth!", 0, "You didnt save us !")
            End
        End If
    End Sub
    Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
        'Moves Gun to the Right'
        If e.KeyCode = Keys.Right Then
            labMessage.Text = "Right"
            Gun.Location = New Point(Gun.Location.X + 10, Gun.Location.Y)
        End If
        'Moves the gun left'
        If e.KeyCode = Keys.Left Then
            labMessage.Text = "Left"
            Gun.Location = New Point(Gun.Location.X - 10, Gun.Location.Y)
        End If
        'shoots the bullet'
        If e.KeyCode = Keys.Space Then
            labMessage.Text = "Shoot"
            FireTimer.Enabled = True
            If Bullet1.Location.Y <= 0 Then Bullet1.Location = Gun.Location
        End If
        'Stops the gun from leaving the area'
        If Gun.Location.X >= 700 Then Gun.Location = New Point(Gun.Location.X - 10, Gun.Location.Y)
        If Gun.Location.X <= 0 Then Gun.Location = New Point(Gun.Location.X + 10, Gun.Location.Y)
    End Sub
    Private Sub FireTimer_Tick(sender As Object, e As EventArgs) Handles FireTimer.Tick
        Bullet1.Location = New Point(Bullet1.Location.X, Bullet1.Location.Y - 50)

    End Sub
    Private Sub MoveTimer_Tick(sender As Object, e As EventArgs) Handles MoveTimer.Tick
        butMoveAlien_Click(sender, e)
    End Sub
    Private Sub BulletfollowTimer_Tick(sender As Object, e As EventArgs) Handles BulletfollowTimer.Tick
        If FireTimer.Enabled = False Then Bullet1.Location = New Point(Gun.Location.X + 30, Gun.Location.Y)
        'Follow Timer'
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Gun.Location = New Point(350, 600)
        Bullet1.Location = New Point(385, 600)
        Me.BackgroundImage = Image.FromFile("Background.jpg")
        StartnFinish.Image = Image.FromFile("Start.png")
    End Sub

End Class
 

bottom of page