|
-
Jan 10th, 2008, 09:20 AM
#1
Thread Starter
New Member
Bird Hunt VB6
Hi,
I'm fairly new to VB6 and I have started to create a Bird Hunt game (Bird flies up - you shoot it).
I have implemented a scoring system which adds your score and name to a txt file, as well as the birds movment and click events.
I would like some constructive criticism on my coding (Bear in mind it is pretty basic atm - New to the scene).
It is run on Word using two Userforms.
Userform1:
Code:
Sub go_Click()
x = 0
Start = 0
If (MsgBox("Are you ready?", 4)) = vbYes Then
PauseTime2 = 2 ' Set duration.
Start2 = Timer ' Set start time.
Do While Timer < Start2 + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
TotalTime = Finish - Start2 ' Calculate total time.
UserForm1.Flight ' Run Flight Sub
End If
End Sub
Sub Result()
If x > 0 And check = False Then ' If the score is greater than 0
bird.Visible = False ' Hide the Bird
j = (x + (i * 10) - (4 * i) + Int(bird.Top / i)) ' Calculate the score
k = k + j
response = MsgBox("Good Shot! You scored " & j & " points. Do you want to play again?", vbYesNo)
If response = vbNo Then
MsgBox ("Thanks for playing, you scored " & k & " points.")
user = InputBox("Please Enter your name")
Call UserForm2.FillVars(k, user)
UserForm1.Hide
UserForm2.Show
ElseIf response = vbYes Then
bird.Move random, 438 ' Reset the bird
shot = False
UserForm1.Flight
End If
ElseIf check = True Then ' If the bird reached the top and you didn't score
MsgBox ("It got away!")
bird.Move random, 438 ' Reset the bird
shot = False
lives = lives + 1
If lives = 1 Then
lifelbl = "1st try."
ElseIf lives = 2 Then
lifelbl = "2nd try."
ElseIf lives = 3 Then
lifelbl = "Last try!"
End If
MsgBox ("Lives Lost: " & lives)
If lives > 3 Then
MsgBox ("You ran out of lives!")
user = InputBox("Please Enter your name")
Call UserForm2.FillVars(k, user)
UserForm1.Hide
UserForm2.Show
End If
End If
End Sub
Sub bird_Click()
x = x + 1 ' Add one to the score
shot = True
End Sub
Sub Flight()
check = False
bird.Enabled = True
shot = False
random = Int((500 * Rnd) + 1)
If Int(TotalTime) = 2 Then
PauseTime = 10 ' Duration
Start = Timer
bird.Visible = True
If easy.Value = True Then
Do While Timer < Start + PauseTime
If shot = False Then
bird.Top = bird.Top - (10 / 50) ' Move the bird up by the speed / 50
UserForm1.Repaint ' Repaint the form
DoEvents
If bird.Top < 1 Then ' If the bird is < 1 pixel from the top
check = True ' Switch check to true
UserForm1.Result
Exit Do ' Exit the loop
End If
Else
i = 10
UserForm1.Result
Exit Do
End If
Loop
ElseIf medium.Value = True Then
Do While Timer < Start + PauseTime
If shot = False Then
bird.Top = bird.Top - (20 / 50) ' Move the bird up by the speed / 50
UserForm1.Repaint ' Repaint the form
DoEvents
If bird.Top < 1 Then ' If the bird is < 1 pixel from the top
check = True ' Switch check to true
UserForm1.Result
Exit Do ' Exit the loop
End If
Else
i = 20
UserForm1.Result
Exit Do
End If
Loop
ElseIf hard.Value = True Then
Do While Timer < Start + PauseTime
If shot = False Then
bird.Top = bird.Top - (30 / 50) ' Move the bird up by the speed / 50
UserForm1.Repaint ' Repaint the form
DoEvents
If bird.Top < 1 Then ' If the bird is < 1 pixel from the top
check = True ' Switch check to true
UserForm1.Result
Exit Do ' Exit the loop
End If
Else
i = 30
UserForm1.Result
Exit Do
End If
Loop
End If
End If
End Sub
Userform2:
Code:
Dim k As Integer
Dim names As String
Dim UserName As String
Dim user As String
Sub ok_Click()
ok.Enabled = False
Open "h:\users.txt" For Append As #1
Print #1, user; Tab(2); k
Close #1
Open "h:\users.txt" For Input As #1
names = Input(LOF(1), #1)
Close #1
scorelbl.Caption = (names)
End Sub
Sub FillVars(ByRef k1 As Integer, user1 As String)
k = k1
user = user1
End Sub
Sub UserForm_Initialize()
Open "h:\users.txt" For Input As #1
names = Input(LOF(1), #1)
Close #1
scorelbl.Caption = (names)
End Sub
Thanks for your input,
Loader
-
Jan 10th, 2008, 09:27 AM
#2
-
Jan 14th, 2008, 02:03 AM
#3
Hyperactive Member
Re: Bird Hunt VB6
When showing what you've made, you should post your project files in a zip, rather than copy-paste your code. Most people can't be bothered to copy your code into a new project, and even for people who can, they would still have to create all the controls and set properties etc etc. I know you wanted feedback on your actual code, but you'd be better off posting the whole game so people can comment on the product and how you did it. It's hard to comment on something if we don't even know if it works or not
metal
-
Jan 14th, 2008, 07:34 PM
#4
Addicted Member
Re: Bird Hunt VB6
Looking at your code, i would say it is fairly neat, indentation could be a little better and i am very glad to see you using comments, alot of new programmers forget that bit, the code looks like it will execute fairly fast.
on a whole i would say great little first game..
If you are looking forward to your next project i would recommend looking into api calls.
here are a few
gettickcount
getkeystate
i you run a google search on them both you should see the great benefits of them..
good luck with future projects
-
Jan 15th, 2008, 12:45 AM
#5
Hyperactive Member
Re: Bird Hunt VB6
 Originally Posted by makster246
Looking at your code, i would say it is fairly neat, indentation could be a little better and i am very glad to see you using comments, alot of new programmers forget that bit, the code looks like it will execute fairly fast.
on a whole i would say great little first game..
If you are looking forward to your next project i would recommend looking into api calls.
here are a few
gettickcount
getkeystate
i you run a google search on them both you should see the great benefits of them..
good luck with future projects
You can spend ages searching google to find something decent. Look no further than the VBF Games & Graphics FAQ. It's stickied at the top of the forum. I would also recommend Bitblt. Personally, I don't use getkeystate. I prefer to use keydown and keyup, as it's just as fast and easier to do event-based stuff with it. For gettickcount, see the Game Loop tutorials, and keystate or keydown/up stuff is in NoteMe's keyboard tutorial, forget what it's called. The best bitblt tutorial is this one.
metal
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|