 |
 |
|

10-05-2001, 04:40 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
speed control
|
Once more iam here with a new question, my last question was neatly and perfectly explained by Ad1, thanx buddy.
I got two questions this time
1. Speed control. This is the code that iam using to control the speed of my car in other words if the user keeps the up key pressed for a specific time, the speed increases. The speed increamented is shown with the effect of the middle line on the road moving down. If the key is pressed for long it will increase the speed of the lines coming down. My car will stay at the base, such that the final simulation will make it look like the car is moving. (iam using a ghost car as a flag and it moves up the screen and when it reaches the top, the speed of the lines is increamented and the position of the ghost car is reset to the base and it goes on. Visibility of the ghost car is set to false
this code is under the function keydown
dim counter as integer
dim flag as integer
flag = 8
if keycode = vbkeyup then ghostcar.top = ghostcar.top - 8
if keycode = vbkeyup and ghostcar.top + ghostcar.height < 0 then
while counter < 12 (i have 12 middle lines)
middleline(counter) = middleline(counter) + flag
counter = counter + 1
wend
ghostcar.top = 750 (750 is the base value of the form)
flag = flag + 8
end if
the above code will only function if i remove the line where i code ghostcar.top = 750 and that means speed is increamented only once. if the line is there, then there is no effect to the speed, can i know the possible error in this matter? or any other solution for the speed increamented which can be easier then mine?
2. Collision detection. Can u help me in this matter as iam completely blur on how to do it, i have an idea but it is very complicated and i have tried it more then ten times!!
|
__________________
asrar
|

10-05-2001, 05:00 AM
|
|
Senior Contributor
Retired Moderator * Expert *
|
|
Join Date: Feb 2001
Location: UK
Posts: 1,287
|
|
Re: speed control
|
not really sure what's going on in your code, maybe you could attatch it to a post
anyway if you want to do acceleration then instead of saying - 8 use an integer - intSpeed and alter intspeed's value to adjust the acceleration
as for collision detection there are several ways to do this (try searching this forum), the easiest is probably to check if one object is within the edges of another ie
<pre><font color=blue>If</font color=blue> picCar.Left < picObject.Left + picObject.Width <font color=blue>And</font color=blue> picCar.Left + picCar.Width > picObject.Left <font color=blue>Then</font color=blue>
<font color=blue>If</font color=blue> picCar.Top < picObject.Top + picObject.Height <font color=blue>And</font color=blue> picCar.Top + picCar.Height > picObject.Top <font color=blue>Then</font color=blue>
MsgBox "crash"
<font color=blue>End If</font color=blue>
<font color=blue>End If</font color=blue></pre>
|
|

10-07-2001, 09:08 PM
|
 |
Contributor
|
|
Join Date: Jul 2001
Location: Pennsylvania
Posts: 481
|
|
Re: speed control
Your game sounds interesting, could I get a copy sometime, my e-mail is jollyrogers3@yahoo.com, just send an exe of it. I'll see if I can help with the code at all, too
|
__________________
Not sure what the new signature is going to be.
|

10-10-2001, 12:43 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
Re: speed control
|
Thanx Ad1, the collision script is working but the only problem is that once it collides, the car position is set to the end of the direction it is moving in, i did not have my code here with me so i couldnt attach it with this post but in my next post i will surely attach it for you to have a look, thanx anyway for helping, i appreciate it !
Fear is in the eye of the beholder, dont let it be you!!
|
__________________
asrar
|

10-13-2001, 10:18 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
Re: speed control
|
hey Ad1 , here is my code, and iam also attaching an exe file of the game for your ref
Dim speed As Integer
Private Declare Function sndPlaySound Lib "WINMM.DLL" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As _
Long) As Long
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Const SND_LOOP = &H8
Const SND_NOSTOP = &H10
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then Timer1.Enabled = True
If KeyCode = vbKeyLeft Then Timer2.Enabled = True
If KeyCode = vbKeyRight Then Timer3.Enabled = True
collision
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim counter As Integer
Dim counter1 As Integer
If KeyCode = vbKeyUp Then Timer1.Enabled = False
If KeyCode = vbKeyLeft Then Timer2.Enabled = False
If KeyCode = vbKeyRight Then Timer3.Enabled = False
While counter < 3
If KeyCode = vbKeyUp And traffic(counter).Top + traffic(counter).Height > 850 Then traffic(counter).Top = 1066
counter = counter + 1
Wend
End Sub
Private Sub Form_Load()
SoundName$ = "E:\myfiles\cs\Project\Lost In Space.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
opptime.Interval = 10
oppchecker.Interval = 10
Timer1.Interval = 10
Timer2.Interval = 10
Timer3.Interval = 10
End Sub
Private Sub oppchecker_Timer()
Dim counter As Integer
Dim middlecounter As Integer
Dim counter2 As Integer
Dim oppcounter As Integer
Dim lightcounter As Integer
While counter < 3
If traffic(counter).Top + traffic(counter).Height < 0 Then
traffic(counter).Top = 850
End If
counter = counter + 1
Wend
While oppcounter < 3
If oppcar(oppcounter).Top + oppcar(oppcounter).Height > 850 Then
oppcar(oppcounter).Top = 0
End If
oppcounter = oppcounter + 1
Wend
While middlecounter < 12
If middleline(middlecounter).Top + middleline(middlecounter).Height > 850 Then
middleline(middlecounter).Top = 0
End If
middlecounter = middlecounter + 1
Wend
While lightcounter < 5
If light(lightcounter).Top + light(lightcounter).Height > 850 Then
light(lightcounter).Top = 0
End If
lightcounter = lightcounter + 1
Wend
collision
While counter2 < 6
If oppositecar(counter2).Top + oppositecar(counter2).Height > 850 Then
oppositecar(counter2).Top = 0
End If
counter2 = counter2 + 1
Wend
End Sub
Private Sub opptime_Timer()
Dim counter As Integer
Dim oppspeed As Integer
Dim oppspeed1 As Integer
Dim counter1 As Integer
While counter < 3
oppspeed = 1 + Int(2 * Rnd())
traffic(counter).Top = traffic(counter).Top - oppspeed - 2
oppcar(counter).Top = oppcar(counter).Top - oppspeed - 2
counter = counter + 1
Wend
While counter1 < 6
oppspeed1 = 1 + Int(5 * Rnd())
oppositecar(counter1).Top = oppositecar(counter1).Top + oppspeed + 5
counter1 = counter1 + 1
Wend
End Sub
Private Sub Timer1_Timer()
Dim counter As Integer
Dim counter1 As Integer
Dim lightcounter As Integer
Dim counter2 As Integer
While counter < 3
traffic(counter).Top = traffic(counter).Top + 8
counter = counter + 1
Wend
While counter2 < 3
oppcar(counter2).Top = oppcar(counter2).Top + 8
counter2 = counter2 + 1
Wend
speed = 8
'If speed < 100 Then
While counter1 < 12
middleline(counter1).Top = middleline(counter1).Top + speed
counter1 = counter1 + 1
'speed = speed + 2
Wend
'End If
While lightcounter < 5
light(lightcounter).Top = light(lightcounter).Top + speed
lightcounter = lightcounter + 1
Wend
counter = 0
counter1 = 0
counter2 = 0
lightcounter = 0
End Sub
Private Sub Timer2_Timer()
maincar.Left = maincar.Left - 5
leftcollision
End Sub
Private Sub Timer3_Timer()
maincar.Left = maincar.Left + 5
rightcollision
End Sub
Sub leftcollision()
If maincar.Left - sideline(0).Left < 0 Then maincar.Left = 304
End Sub
Sub rightcollision()
If maincar.Left - sideline(1).Left > 0 Then maincar.Left = 690
End Sub
Sub collision()
Dim lightcounter As Integer
Dim middlecounter As Integer
While lightcounter < 5
If maincar.Left < light(lightcounter).Left + light(lightcounter).Width And maincar.Left + maincar.Width > light(lightcounter).Left Then
If maincar.Top < light(lightcounter).Top + light(lightcounter).Height And maincar.Top + maincar.Height > light(lightcounter).Top Then
maincar.Left = 592
'MsgBox "crash"
End If
End If
lightcounter = lightcounter + 1
Wend
End Sub
Dim speed As Integer
Private Declare Function sndPlaySound Lib "WINMM.DLL" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As _
Long) As Long
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Const SND_LOOP = &H8
Const SND_NOSTOP = &H10
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then Timer1.Enabled = True
If KeyCode = vbKeyLeft Then Timer2.Enabled = True
If KeyCode = vbKeyRight Then Timer3.Enabled = True
collision
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim counter As Integer
Dim counter1 As Integer
If KeyCode = vbKeyUp Then Timer1.Enabled = False
If KeyCode = vbKeyLeft Then Timer2.Enabled = False
If KeyCode = vbKeyRight Then Timer3.Enabled = False
While counter < 3
If KeyCode = vbKeyUp And traffic(counter).Top + traffic(counter).Height > 850 Then traffic(counter).Top = 1066
counter = counter + 1
Wend
End Sub
Private Sub Form_Load()
SoundName$ = "E:\myfiles\cs\Project\Lost In Space.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundName$, wFlags%)
opptime.Interval = 10
oppchecker.Interval = 10
Timer1.Interval = 10
Timer2.Interval = 10
Timer3.Interval = 10
End Sub
Private Sub oppchecker_Timer()
Dim counter As Integer
Dim middlecounter As Integer
Dim counter2 As Integer
Dim oppcounter As Integer
Dim lightcounter As Integer
While counter < 3
If traffic(counter).Top + traffic(counter).Height < 0 Then
traffic(counter).Top = 850
End If
counter = counter + 1
Wend
While oppcounter < 3
If oppcar(oppcounter).Top + oppcar(oppcounter).Height > 850 Then
oppcar(oppcounter).Top = 0
End If
oppcounter = oppcounter + 1
Wend
While middlecounter < 12
If middleline(middlecounter).Top + middleline(middlecounter).Height > 850 Then
middleline(middlecounter).Top = 0
End If
middlecounter = middlecounter + 1
Wend
While lightcounter < 5
If light(lightcounter).Top + light(lightcounter).Height > 850 Then
light(lightcounter).Top = 0
End If
lightcounter = lightcounter + 1
Wend
collision
While counter2 < 6
If oppositecar(counter2).Top + oppositecar(counter2).Height > 850 Then
oppositecar(counter2).Top = 0
End If
counter2 = counter2 + 1
Wend
End Sub
Private Sub opptime_Timer()
Dim counter As Integer
Dim oppspeed As Integer
Dim oppspeed1 As Integer
Dim counter1 As Integer
While counter < 3
oppspeed = 1 + Int(2 * Rnd())
traffic(counter).Top = traffic(counter).Top - oppspeed - 2
oppcar(counter).Top = oppcar(counter).Top - oppspeed - 2
counter = counter + 1
Wend
While counter1 < 6
oppspeed1 = 1 + Int(5 * Rnd())
oppositecar(counter1).Top = oppositecar(counter1).Top + oppspeed + 5
counter1 = counter1 + 1
Wend
End Sub
Private Sub Timer1_Timer()
Dim counter As Integer
Dim counter1 As Integer
Dim lightcounter As Integer
Dim counter2 As Integer
While counter < 3
traffic(counter).Top = traffic(counter).Top + 8
counter = counter + 1
Wend
While counter2 < 3
oppcar(counter2).Top = oppcar(counter2).Top + 8
counter2 = counter2 + 1
Wend
speed = 8
'If speed < 100 Then
While counter1 < 12
middleline(counter1).Top = middleline(counter1).Top + speed
counter1 = counter1 + 1
'speed = speed + 2
Wend
'End If
While lightcounter < 5
light(lightcounter).Top = light(lightcounter).Top + speed
lightcounter = lightcounter + 1
Wend
counter = 0
counter1 = 0
counter2 = 0
lightcounter = 0
End Sub
Private Sub Timer2_Timer()
maincar.Left = maincar.Left - 5
leftcollision
End Sub
Private Sub Timer3_Timer()
maincar.Left = maincar.Left + 5
rightcollision
End Sub
Sub leftcollision()
If maincar.Left - sideline(0).Left < 0 Then maincar.Left = 304
End Sub
Sub rightcollision()
If maincar.Left - sideline(1).Left > 0 Then maincar.Left = 690
End Sub
Sub collision()
Dim lightcounter As Integer
Dim middlecounter As Integer
While lightcounter < 5
If maincar.Left < light(lightcounter).Left + light(lightcounter).Width And maincar.Left + maincar.Width > light(lightcounter).Left Then
If maincar.Top < light(lightcounter).Top + light(lightcounter).Height And maincar.Top + maincar.Height > light(lightcounter).Top Then
maincar.Left = 592
'MsgBox "crash"
End If
End If
lightcounter = lightcounter + 1
Wend
End Sub
|
__________________
asrar
|

10-13-2001, 10:33 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
Re: speed control *DELETED* *DELETED*
|
Post deleted by wild wolf
|
__________________
asrar
|

10-13-2001, 10:39 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
Re: speed control *DELETED*
|
Post deleted by wild wolf
|
__________________
asrar
|

10-13-2001, 10:52 AM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
Re: speed control
|
It is against the posting guidelines to attach EXEs. Just attach source code.
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

10-13-2001, 11:20 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Re: speed control
|
Yeah, I was gonna say that too, but thought against it, as you probably wanted to allow only Ad1 to see the source and not anyone who cares to d/l it...... but in essence, if you read the posting guidelines, EXEs and OCXs are generally frowned upon, EXEs more so........
|
|

10-13-2001, 11:31 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
Re: speed control
|
iam really sorry for that,is there anyway i can withdraw the attachment?
|
__________________
asrar
|

10-15-2001, 02:32 AM
|
|
Senior Contributor
Retired Moderator * Expert *
|
|
Join Date: Feb 2001
Location: UK
Posts: 1,287
|
|
Re: speed control
|
hi wild wolf, attach your project and I will take a look,
like has been mentioned exe's are no good, 1)due to paranoia of downloading and 2)you can't debug and step through an exe
|
|

10-15-2001, 04:03 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
Re: speed control
|
ok ill attach the whole project, zipped ( i hope i can attach zip files)
|
__________________
asrar
|

10-15-2001, 04:29 AM
|
|
Senior Contributor
Retired Moderator * Expert *
|
|
Join Date: Feb 2001
Location: UK
Posts: 1,287
|
|
Re: speed control
|
your game looks nice, but what do you want it to do when you collide ?, at the moment you set it to a particular position "maincar.Left = 592",
you could change that to "maincar.Left = maincar.Left +/- 50" to give the effect of bouncing, or you could have a loop/timer which fires and runs a crash sequence ie the car spins and stops and they have to start again
|
|

10-15-2001, 09:32 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
Re: speed control
|
hey thats a good idea of sending the car spining, actually my initail idea was to set speed to 0 again once u collide, but i think spining the car will be a great, but do u have any idea on how that will be done? the sound i wan to use DirectX. i have updated the progam, and tomorow i will upload the updated version in which speed has also been controlled.
|
__________________
asrar
|

10-15-2001, 09:48 AM
|
|
Senior Contributor
Retired Moderator * Expert *
|
|
Join Date: Feb 2001
Location: UK
Posts: 1,287
|
|
Re: speed control
|
I don't know anything about DirectX, but you should be able to knock up a decent enough animation just using vb, I've attatched a simple demo of how to do the animation, just replace the frames with frames of your car spinning
|
|

10-15-2001, 11:48 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
Re: speed control
|
that code is quite decent, i never thought of it, its good and i am gonna use it for the collision. One thing i want u to notice in my code is, when the car collides with the middlelight, the code only works when it collides on the side, but when the car collides from the bottom of the light it goes through, what do u think - as per the code - is the problem?
|
__________________
asrar
|

10-15-2001, 12:48 PM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Re: speed control
|
wild wolf - I just wanna congratualte you on such a great looking project. Its looking very promising. I suggest to speed up the animation by using more API, or DirectX, but otherwise way cool..... keep it up!
|
|

10-16-2001, 01:26 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
Re: speed control
|
thanx squirm, thats gonna keep up my spirits and goona boost up my moral. I am going to convert all the animations and sounds using DirectX, iam still learning on it, (hope it does not take long as i got only 1 more month to complete this game)
|
__________________
asrar
|

10-16-2001, 01:42 AM
|
 |
Contributor
|
|
Join Date: Aug 2001
Location: Mombasa Island
Posts: 499
|
|
Re: speed control
|
hey yes i forgot 1 thing, this game is based on a server - client, meaning its a multiplayer game, so, Ad1 adn Squirm, u have seen my code, do u think i need to declare all my varialbes globally or leave them the way they r? coz i fear i will have problems sending and receiving data
|
__________________
asrar
|

10-16-2001, 02:25 AM
|
|
Senior Contributor
Retired Moderator * Expert *
|
|
Join Date: Feb 2001
Location: UK
Posts: 1,287
|
|
Re: speed control
|
well in the code I've got from your attatchment you need to call Sub collision() from timer1, and you will also need to uncomment the code in Sub collision() and then it should work
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|