
Visual
Basic Game V 1.0
Introduction
This
is a very simple but complete 2D game application developed using
Visual Basic 6. It have total 3 screen.
1)
Start
2) Options
3) The Game
Technolgies
Used
I
have used Visual Basic 6 for development of this application and
develop without using any 3rd party controls or components.
Main
compnents used are following
1)
Timer Control
2) Picture Control
3) Label Control
4) Windows Media ocx (But its not used in this version so code is
commented)
Game
Play
Run
game using main .exe file it will show a window with three options
1)
Play Game
2) Options
3) Exit
Here
user can select Play Game to start the Game and after that control
the game using arrow keys and spacebar.
And
thats it.
Sample
Code
Here
is some sample code from this project
Option
Explicit
Dim u, d, l, r, showm As Boolean
Dim x, y As Integer
Dim mx, my As Integer
Dim ex, ey As Integer
Dim score As Long
Dim fuel As Integer
Dim es As Integer
________________________________________________________________________
Private Sub Form_Load()'MediaPlayer1.playerApplication = App.Path
& "\sfx\fire.wav"
'MediaPlayer2.FileName = App.Path & "\sfx\Explosion.wav"
'MediaPlayer3.FileName = App.Path & "\sfx\mainsound.mp3"lblScore.Caption
= "0"x = 0
y = 0ex = -100
ex = -100es = 10fuel = 1
End Sub
________________________________________________________________________
Private Sub Form_Paint()
shooter.SetFocus
End Sub
________________________________________________________________________
Private Sub shooter_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 49 Then speed = speed - 1
If speed <= 0 Then speed = 0
If speed > 30 Then speed = 30
If KeyCode = 50 Then speed = speed + 1
If KeyCode = vbKeyLeft Then l = True
If KeyCode = vbKeyRight Then r = True
If KeyCode = vbKeyUp Then u = True
If KeyCode = vbKeyDown Then d = True
If KeyCode = vbKeySpace Then
If Not showm Then
fireit
End If
End If
If KeyCode = vbKeyEscape Then Unload Me: End
End Sub
________________________________________________________________________
Private Sub shooter_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyLeft Then l = False
If KeyCode = vbKeyRight Then r = False
If KeyCode = vbKeyUp Then u = False
If KeyCode = vbKeyDown Then d = False
End Sub
________________________________________________________________________
Private Sub Timer1_Timer()Static ch As Boolean
ch = Not chIf ch Then
shooter.Picture = Picture2.Picture
Else
shooter.Picture = Picture3.Picture
End If
End Sub
________________________________________________________________________
Private Sub
Timer2_Timer()
If l Then
x = x - speed
If x < 0 Then x = 0
End If
If r Then
x = x + speed
If x >= Me.ScaleWidth - 100 Then x = Me.ScaleWidth - 100
End If
If u Then
y = y - speed
If y < 0 Then y = 0
End If
If d Then
y = y + speed
If y >= Me.ScaleHeight - 100 Then y = Me.ScaleHeight - 100
End If
Label5.Caption = "X = " & x
Label6.Caption = "Y = " & y
shooter.Left = x
shooter.Top = y
Label3.Caption = CStr(speed)
If showm Then
mx = mx + 20
If mx > Me.ScaleWidth Then
showm = False
fire.Visible = False
End If
fire.Left = mx
fire.Top = my
If (my > ey And my < ey + 60) And (mx > ex) Then
score = score + 10
showm = False
SetEn
End If
Else
fire.Visible = False
End If
ex = ex - es
en.Left = ex
If ex < -200 Then
SetEn
en.Top = ey
End If
lblScore = CStr(score)
Label8.Caption = "EX = " & ex
Label7.Caption = "EY = " & ey
If (y > ey - 40 And y < ey + 30) And (x > ex And x
< ex + 100) Then
fuel = fuel + 1
'If fuel > 1 Then MediaPlayer2.Play
Picture1.BackColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
SetEn Select Case fuel
Case 2
Image1.Picture = LoadPicture(App.Path & "\data\fuel50.gif")
Case 3
Image1.Picture = LoadPicture(App.Path & "\data\fuel20.gif")
Case 4
Image1.Picture = LoadPicture(App.Path & "\data\game-over.gif")
End Select
If fuel = 4 Then
MsgBox "Game Over", vbCritical, "Shooter"
Unload Me
Form2.Show
End If
End If
End Sub
________________________________________________________________________
Private Sub fireit()
'MediaPlayer1.Play
showm = Truemx = shooter.Left + 100
my = shooter.Top + 50
fire.Visible = True
End Sub
________________________________________________________________________
Public Sub SetEn()
ey = Int(Rnd * Me.ScaleHeight) - 100
ex = Me.ScaleWidth
en.Left = ex
en.Top = ey
End Sub
________________________________________________________________________
Private Sub Timer3_Timer()
es = es + 5
End Sub |
Click
here to Download the
Project
|