Page 1 of 1

How to create a game [vb 2008]

Posted: Sun Oct 17, 2010 5:04 pm
by RunarM
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:
Code: Select all
    Dim playerx As Integer = 0
    Dim playery As Integer = 0
Form1_Keydown code:
Code: Select all
      
'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
Form_keyup code:
Code: Select all
'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
Form_Load code:
Code: Select all
KeyPreview = True
Timer1.Enabled = true
Timer1.Interval = 1
Timer1_Tick code:
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
Dim bulletspeed As Integer = 0
Timer1_Tick:
Bullet goes up:
Code: Select all
 Me.Bullet.Top = Me.Bullet.Top + bulletspeed
Timer2_Tick:
Code: Select all
textx.Text = Player.Location.X
        texty.Text = Player.Location.Y
Form1_KeyDown:
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

Re: How to create a game [vb 2008]

Posted: Sun Oct 17, 2010 5:08 pm
by RunarM
Here are some examples.

This pack includes:
*I hate snow
*A new game i'm working on ;)


Image (viewtopic.php?f=70&t=3431)
Image


The files is copyrighted © to RunarM 2010, so you may NOT post it any other places.

Re: How to create a game [vb 2008]

Posted: Sun Oct 17, 2010 7:13 pm
by XTechVB
this is basic but very useful for those who want to make more advanced games in .Net
Thanks RunarM

Re: How to create a game [vb 2008]

Posted: Tue Oct 19, 2010 5:12 pm
by DarkyKnife
Great tutorial, i always wanted to know how to make collision

Re: How to create a game [vb 2008]

Posted: Tue Oct 19, 2010 11:39 pm
by zachman61
ooh collisions!!!!!

Re: How to create a game [vb 2008]

Posted: Thu Oct 21, 2010 5:18 am
by MrBrockWalker
Very nice tutorial, I might have a crack at making a simple game using this :D I'll give you credits if I do make it