A Quick Game
To make this you will need the following on your form:
Public Class Form1
'This keeps score of your game
'its made public so it can be used in any sub
Public score = 0
Private Sub PictureBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
score += 10
Label3.Text = score
'This is the image shown when you hit the ghost
PictureBox1.Image = My.Resources.Animation1
PictureBox1.Enabled = False
Timer1.Interval = 500
Timer1.Enabled = True
'Plays the sound file when hitting the ghost
'Used Audioplaymode.background to run smooth and prevent game stalling
My.Computer.Audio.Play(My.Resources.squeak, AudioPlayMode.Background)
'If your score reaches 200 you win the game - you can change it
If score = 200 Then
winner()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Moves ghost to a random location when the timer runs out
Timer1.Interval = 5000
PictureBox1.Enabled = True
Dim generator As New Random
Dim randomValue As Integer
Dim randomValueb As Integer
Timer1.Enabled = True
randomValue = generator.Next(10, 400)
randomValueb = generator.Next(10, 500)
PictureBox1.Location = New Point(randomValue, randomValueb)
PictureBox1.Image = My.Resources.cartoonghost
End Sub
Private Sub winner()
'Displays the WINNER!!! sign when you get top score and ends the game
Timer1.Enabled = False
Label2.Visible = True
PictureBox1.Visible = False
End Sub
End Class
- 3 Labels
- Timer
- PictureBox
- Use the background image for your form
- Place the character gif, hit image and sound file into your resources
- Character gif should go into the PictureBox
- Now set all the controls background to Transparant
- Make label2 Visible = false
- Label1 should be called 'Score'
- Label3 is used to display the score amount
Public Class Form1
'This keeps score of your game
'its made public so it can be used in any sub
Public score = 0
Private Sub PictureBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
score += 10
Label3.Text = score
'This is the image shown when you hit the ghost
PictureBox1.Image = My.Resources.Animation1
PictureBox1.Enabled = False
Timer1.Interval = 500
Timer1.Enabled = True
'Plays the sound file when hitting the ghost
'Used Audioplaymode.background to run smooth and prevent game stalling
My.Computer.Audio.Play(My.Resources.squeak, AudioPlayMode.Background)
'If your score reaches 200 you win the game - you can change it
If score = 200 Then
winner()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Moves ghost to a random location when the timer runs out
Timer1.Interval = 5000
PictureBox1.Enabled = True
Dim generator As New Random
Dim randomValue As Integer
Dim randomValueb As Integer
Timer1.Enabled = True
randomValue = generator.Next(10, 400)
randomValueb = generator.Next(10, 500)
PictureBox1.Location = New Point(randomValue, randomValueb)
PictureBox1.Image = My.Resources.cartoonghost
End Sub
Private Sub winner()
'Displays the WINNER!!! sign when you get top score and ends the game
Timer1.Enabled = False
Label2.Visible = True
PictureBox1.Visible = False
End Sub
End Class