Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB Expert!

Join 244,284 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,031 people online right now. Registration is fast and FREE... Join Now!




DX Ball Help Visual Basic 6

 
Reply to this topicStart new topic

DX Ball Help Visual Basic 6, I have to use Visual basic 6 because my school doesn't teach other

gabbo93
24 Oct, 2008 - 04:48 PM
Post #1

New D.I.C Head
*

Joined: 24 Oct, 2008
Posts: 1

Hello,

I am trying to make my own version of dx ball the code was written from scratch, and i'm having problems with the collision detection, it works when the ball hits the bottom of the brick, but it doesn't work with any other side, here is the code i'm using:

vb

Dim vmom As Integer
Dim hmom As Integer
Dim img1_top As Integer
Dim img1_left As Integer
Dim img1_right As Integer
Dim img1_bottom As Integer
Dim img2_top As Integer
Dim img2_left As Integer
Dim img2_right As Integer
Dim img2_bottom As Integer


Private Sub Form_Load()
vmom = 50
hmom = 50
End Sub


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
shpPlayer.Left = X - (shpPlayer.Width / 2)
End Sub


Private Sub mnuExit_Click()
End
End Sub

Private Sub mnuStart_Click()
shpBall.Top = 6100
shpBall.Left = 9200
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()

shpBall.Top = shpBall.Top - vmom
shpBall.Left = shpBall.Left - hmom

If (shpBall.Top + shpBall.Height) > shpPlayer.Top Then


If shpBall.Left + shpBall.Width >= shpPlayer.Left And shpBall.Left <= shpPlayer.Left + shpPlayer.Width Then
vmom = -vmom
End If
End If

img1_top = shpBall.Top
img1_left = shpBall.Left
img1_right = shpBall.Left + shpBall.Width
img1_bottom = shpBall.Top + shpBall.Height
img2_top = shpBrick(0).Top
img2_left = shpBrick(0).Left
img2_right = shpBrick(0).Width + shpBrick(0).Left
img2_bottom = shpBrick(0).Top + shpBrick(0).Height
If shpBrick(0).Visible = True And ((img1_top = img2_bottom And img1_left > img2_left And img1_left < img2_right) Or (img1_bottom = img2_top And img1_left > img2_left And img1_left < img2_right) Or (img1_left = img2_right And img1_top > img2_top And img1_top < img2_bottom) Or (img1_right = img2_left And img1_top > img2_top And img1_top < img2_bottom)) Then
vmom = -vmom
hmom = -hmom
shpBrick(0).Visible = False
End If

img2_top = shpBrick(1).Top
img2_bottom = shpBrick(1).Top + shpBrick(1).Height
If shpBrick(1).Visible = True And (img1_top = img2_bottom) Then
vmom = -vmom
hmom = -hmom
shpBrick(1).Visible = False
End If

If (shpBall.Left + shpBall.Width) > Form1.Width Then
shpBall.Left = Form1.Width - shpBall.Width
hmom = -hmom
ElseIf shpBall.Left < 0 Then
shpBall.Left = 0
hmom = -hmom
ElseIf shpBall.Top < 0 Then
shpBall.Top = 0
vmom = -vmom
ElseIf shpBall.Top > Form1.Height Then
MsgBox "You lost!"
Timer1.Enabled = False
End If
End Sub


Thank you in advance for your help.

Kind Regards,

Gabriel

Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif

User is offlineProfile CardPM
+Quote Post


thava
RE: DX Ball Help Visual Basic 6
24 Oct, 2008 - 05:49 PM
Post #2

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 670



Thanked: 35 times
Dream Kudos: 75
My Contributions
never check with = sign because you increment the height and top jin terms of 50

if the left or top or right or bottom of the picture might nor be in tems of 50 it might me some other values like 105 and so

so use > sign in the checking

and one more thing you just increment or decrement the both movements in the same time this will also affect this

so detect whether if you hit top or bottom just increment or decrement the Vmom seperately
and similarly
so detect whether if you hit right or left just increment or decrement the hmom seperately

hope this helps

best of luck
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 02:53PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month