Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 having a problem with my game
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wallc++




PostPosted: Wed Apr 08, 2009 9:08 pm   Post subject: having a problem with my game

program: pong
made in : vb6

the problem im having is a colision problem i think.
the picture that is attached shows the problem

thanks for the help

VisualBASIC:
'the code that I think there is a problem with is labeled problemed code
'just so you know what is what here is the different objects and what there names in the code are
'shpblocker1 = user blocker
'shpt = the top wall
'shpb = the bottom wall
'shpball = the ball
'shpblocker2 isn't in the program yet but it doesn't make a diffrence right now

Option Explicit
'code for ball
Public intleftright As Integer
Public intupdown As Integer
Public intmoveby As Integer

'key code for blocker1
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyE Then
    shpblocker1.Top = shpblocker1.Top - 50
ElseIf KeyCode = vbKeyD Then
    shpblocker1.Top = shpblocker1.Top + 50
End If
End Sub

Private Sub Form_Load()
'code for movement of ball
intleftright = 1
intupdown = 1
intmoveby = 10

End Sub

[color=crimson]'PROBLEM CODE
Private Sub Timer1_Timer()
'code for shpblocker1 collisions with walls
If shpblocker1.Top = shpt.Top + shpt.Height Then
    shpblocker1 = 0
ElseIf shpblocker1.Top + shpblocker1.Height > shpb.Top Then
    shpblocker1 = 0
End If
End Sub[/color]

Private Sub tmr1_Timer()
'code for ball to wall colisions
If (shpball.Left + shpball.Width > Form1.Left + Form1.Width) Then
    intleftright = -1
End If

If shpball.Top + shpball.Height > shpb.Top Then
    intupdown = -1
End If

If shpball.Left < shpblocker1.Left + shpblocker1.Width Then
    intleftright = 1
End If

If shpball.Top < shpt.Top + shpt.Height Then
    intupdown = 1
End If

  shpball.Left = shpball.Left + (intleftright * intmoveby)
shpball.Top = shpball.Top + (intupdown * intmoveby)

End Sub

'PROBLEM CODE
Private Sub tmr2_Timer()
'code for blocker1 to wall colisions
If shpblocker1.Top = shpt.Top + shpt.Height Then
    shpblocker1 = shpblocker1 + 1
ElseIf shpblocker1.Top + shpblocker1.Height > shpb.Top Then
    shpblocker1 -1
End If
End Sub


Mod Edit: Remember to use syntax tags! Thanks Smile
code:
[syntax="vb"]Code Here[/syntax]



pong problem.bmp
 Description:
 Filesize:  1.01 MB
 Viewed:  187 Time(s)

pong problem.bmp


Sponsor
Sponsor
Sponsor
sponsor
deathbow2134




PostPosted: Sun Apr 12, 2009 8:56 am   Post subject: Re: having a problem with my game

I find this very hard to follow without the rest of your code. If you could post all of your source code I'm sure I could help you.
wallc++




PostPosted: Sun Apr 12, 2009 7:55 pm   Post subject: Re: having a problem with my game

that is all the code i just dont know how to get something to stop when it hits something
DifinityRJ




PostPosted: Wed Apr 29, 2009 10:48 am   Post subject: Re: having a problem with my game

You could use rectangular collision to check if the ball is within the bounds of the paddle. There are so many tutorials on rectangular collision on these forums.

I would explain it, but I haven't coded in VB for a while now, and I remember the Y values worked different in VB.

Anyways the basic idea is:

if the ball is within the parameters of the paddle, then reverse the x velocity of the ball, making it bounce off of the paddle.

For example :
if the ball hit the paddle then

x_velocity_of_ball := -x_velocity_of_ball

end if

Good luck!
wallc++




PostPosted: Wed Apr 29, 2009 10:56 pm   Post subject: Re: having a problem with my game

umm well the program works fine in that aspect the ball bounces of the blocker its the blocker its self. its not stoping at the bounds of the game. in short i know how to program bounce code but i dont know how to make something stop when it hits somthing.like hiting a wall then for it to stop not bounce off.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: