Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Is collision detect slow or something?


Reply
 
Thread Tools Display Modes
  #1  
Old 02-18-2004, 03:42 PM
rasheemo rasheemo is offline
Freshman
 
Join Date: Dec 2003
Posts: 29
Default Is collision detect slow or something?


I made it so that if the square runs into the small circle, the circle disappears, but somehow when i execute it it takes a few tries of pressing left and right to get the circle to go away. The timers are obviously used to make the swuare move at a constant rate.


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim intP1Counter As Integer
Dim intP2Counter As Integer

Select Case KeyCode

''''''''''''''''''''''''''''''''''''''''''''''''''''''''' P1 Pacman
Case vbKeyUp
timUp.Enabled = True
timDown.Enabled = False
timLeft.Enabled = False
timRight.Enabled = False

Case vbKeyDown
timDown.Enabled = True
timUp.Enabled = False
timLeft.Enabled = False
timRight.Enabled = False

Case vbKeyRight
timUp.Enabled = False
timDown.Enabled = False
timLeft.Enabled = False
timRight.Enabled = True

Case vbKeyLeft
timUp.Enabled = False
timDown.Enabled = False
timLeft.Enabled = True
timRight.Enabled = False
''''''''''''''''''''''''''''''''''''''''''''''''''''''''' P2 Pacman
Case vbKeyW
timA.Enabled = False
timS.Enabled = False
timW.Enabled = True
timD.Enabled = False

Case vbKeyS
timA.Enabled = False
timS.Enabled = True
timW.Enabled = False
timD.Enabled = False

Case vbKeyD
timA.Enabled = False
timS.Enabled = False
timW.Enabled = False
timD.Enabled = True

Case vbKeyA
timA.Enabled = True
timS.Enabled = False
timW.Enabled = False
timD.Enabled = False
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''

End Select

If shpPacman1.Left < shpTarget.Left + shpTarget.Width And shpTarget.Left < shpPacman1.Left + shpPacman1.Width Then
If shpPacman1.Top < shpTarget.Top + shpTarget.Height And shpTarget.Top < shpPacman1.Top + shpPacman1.Height Then
shpTarget.Visible = False
intP1Counter = intP1Counter + 1
lblScore1.Caption = intP1Counter
End If
End If

If shpPacman2.Left < shpTarget.Left + shpTarget.Width And shpTarget.Left < shpPacman2.Left + shpPacman2.Width Then
If shpPacman2.Top < shpTarget.Top + shpTarget.Height And shpTarget.Top < shpPacman2.Top + shpPacman2.Height Then
shpTarget.Visible = False
intP2Counter = intP2Counter + 1
lblScore2.Caption = intP2Counter
End If
End If

End Sub
Reply With Quote
  #2  
Old 02-18-2004, 03:59 PM
jumentous's Avatar
jumentous jumentous is offline
Contributor
 
Join Date: Sep 2003
Location: Australia
Posts: 612
Default

put the collision detect code into a sub and then call it from the timers because your keydown event isn't actually moving either pacman, all its doing is telling the timers to start moving the pacmans, this code will only be triggered when you actually press the key and so if it runs into the square when moving on its own it wont detect the collision, this is why it works when you click a key again while the pacmans are overlapped.


BTW, you may like to stay how it is but investigate using just 1 timer and having boolean values to see which way it is moving, if for no other reason than the timers wont all trigger at the same time


Edit: And use [vb][/vb] tags
__________________
"In The Land of The Blind the One-Eyed Man is King."

Jumentous
Reply With Quote
  #3  
Old 02-18-2004, 08:14 PM
rasheemo rasheemo is offline
Freshman
 
Join Date: Dec 2003
Posts: 29
Default ooo

oooOOOoo thanks a lot! i never would have guessed!

What do you mean putting it as a boolean expression? DO you mean i should put the key selects in a timer or something?
Reply With Quote
  #4  
Old 02-18-2004, 08:23 PM
rasheemo rasheemo is offline
Freshman
 
Join Date: Dec 2003
Posts: 29
Default k

nm i got it! thanks
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
pics collision yhaim Game Programming 6 07-24-2003 07:05 AM
Problem with Pixel perfect collision... I really need help Kamochan DirectX 4 07-22-2003 07:40 AM
I need some expert help. Twan Game Programming 3 03-01-2003 08:02 PM
How to detect collision detection here?? toughcoder Game Programming 2 02-16-2003 09:35 AM
Possible solution to collision detection. . . MFCTC Game Programming 3 05-13-2002 08:47 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->