How to create a game [vb 2008]
Posted: Sun Oct 17, 2010 5:04 pm
Hello, this tutorial will teach you the basics of making a game in visual basic 2008.
Moving the player with key arrows:
You need:
1 Picturebox (named: Player)
1 Timer
Codes:
Under: Public Class Form1:
Player meets wall:
You need:
Picturebox (named Wall)
Bullet:
This will show you how to make a bullet
You need:
Picturebox (named: Bullet)
Timer1
Timer2
Under: Public Class Form1:
Bullet goes up:
Get points:
You need:
Picturebox (named: coins)
label (named: score) (score.text = "0")
Now you can create a game, i might add more soon ^^
-RunarM
Moving the player with key arrows:
You need:
1 Picturebox (named: Player)
1 Timer
Codes:
Under: Public Class Form1:
Code: Select all
Form1_Keydown code:
Dim playerx As Integer = 0
Dim playery As Integer = 0
Code: Select all
Form_keyup code:
'This will move the player when you click right, left etc.. arrow
If e.KeyCode = Keys.Right Then
playerx = 5
ElseIf e.KeyCode = Keys.Left Then
playerx = -5
ElseIf e.KeyCode = Keys.Up Then
playery = -5
ElseIf e.KeyCode = Keys.Down Then
playery = 5
End If
Code: Select all
Form_Load code:
'This will stop the player when you doesn't press keys anymore..
If e.KeyCode = Keys.Right Or e.KeyCode = Keys.Left Or e.KeyCode = Keys.Up Or e.KeyCode = Keys.Down Then
playerx = 0
playery = 0
End If
Code: Select all
Timer1_Tick code:
KeyPreview = True
Timer1.Enabled = true
Timer1.Interval = 1
Code: Select all
'This will move the player
Me.Player.Left = Me.Player.Left + playerx
Me.Player.Top = Me.Player.Top + playery
Player meets wall:
You need:
Picturebox (named Wall)
Code: Select all
'When player meets then something happens...
If Player.Bounds.IntersectsWith(wall.Bounds) Then
'what should happen?
End If
Bullet:
This will show you how to make a bullet
You need:
Picturebox (named: Bullet)
Timer1
Timer2
Under: Public Class Form1:
Code: Select all
Timer1_Tick:Dim bulletspeed As Integer = 0
Bullet goes up:
Code: Select all
Timer2_Tick:
Me.Bullet.Top = Me.Bullet.Top + bulletspeed
Code: Select all
Form1_KeyDown:
textx.Text = Player.Location.X
texty.Text = Player.Location.Y
Code: Select all
'When you press space the bullet will go to a location.
If e.KeyCode = Keys.Space Then
Bullet.Location = New Point(textx.Text, texty.Text)
End If
Get points:
You need:
Picturebox (named: coins)
label (named: score) (score.text = "0")
Code: Select all
If Player.Bounds.IntersectsWith(coins.Bounds) Then
coins.visible = false
score.text += 1
End If
Now you can create a game, i might add more soon ^^
-RunarM