2 Replies - 1115 Views - Last Post: 10 January 2014 - 04:57 AM Rate Topic: -----

#1 flare123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-January 14

Need help with a ball game

Posted 06 January 2014 - 12:39 AM

Hi. I am trying to make a ball game (Something like a snake game) cause I have nothing to do this holidays. But I have a problem, when i move the ball to the other ball the 1st time, it will do what i want. But i cant make it do what it is supposed to do the 2nd time. Please help me. Here are the codes

Dim UKEY As Boolean
Dim DKEY As Boolean
Dim RKEY As Boolean
Dim LKEY As Boolean

Private Sub Command1_Click()
Shape2.Visible = True

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp: UKEY = True
Case vbKeyDown: DKEY = True
Case vbKeyRight: RKEY = True
Case vbKeyLeft: LKEY = True
End Select
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp: UKEY = False
Case vbKeyDown: DKEY = False
Case vbKeyRight: RKEY = False
Case vbKeyLeft: LKEY = False
End Select
End Sub

Private Sub Timer1_Timer()
If UKEY Then Shape1.Top = Shape1.Top - 100
If DKEY Then Shape1.Top = Shape1.Top + 100
If RKEY Then Shape1.Left = Shape1.Left + 100
If LKEY Then Shape1.Left = Shape1.Left - 100

If Shape1.Top <= 0 Then Shape1.Top = 0
If Shape1.Left <= 0 Then Shape1.Left = 0
If Shape1.Left + 1655 >= Form1.Width Then Shape1.Left = Form1.Width - 1655
If Shape1.Top + 1955 >= Form1.Height Then Shape1.Top = Form1.Height - 1955

If Shape1.Left < Shape2.Left + Shape2.Width And Shape2.Left < Shape1.Left + Shape1.Width Then
If Shape1.Top < Shape2.Top + Shape2.Height And Shape2.Top < Shape1.Top + Shape1.Height Then
Shape2.Left = Rnd + 1 * 10000
Shape2.Top = Rnd + 1 * 4000
End If
End If
End Sub



Don't care about the command1_click. I forgotten to delete it >.<

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with a ball game

#2 MajorWalrus  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 115
  • Joined: 22-April 09

Re: Need help with a ball game

Posted 09 January 2014 - 01:26 PM

I'm guessing that you need to set your key variables back to false after reading them. Something like:

If UKEY Then 
   Shape1.Top = Shape1.Top - 100
   UKEY = False
End If


This post has been edited by MajorWalrus: 09 January 2014 - 01:51 PM

Was This Post Helpful? 0
  • +
  • -

#3 flare123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-January 14

Re: Need help with a ball game

Posted 10 January 2014 - 04:57 AM

View PostMajorWalrus, on 09 January 2014 - 01:26 PM, said:

I'm guessing that you need to set your key variables back to false after reading them. Something like:

If UKEY Then 
   Shape1.Top = Shape1.Top - 100
   UKEY = False
End If


well i solved it. it was with this code
Shape2.Left = Rnd + 1 * 10000
Shape2.Top = Rnd + 1 * 4000


it is supposed to be
Shape2.Left = Int(Rnd * 10000 + 1)
Shape2.Top = Int(Rnd * 4000 + 1)


Anyway, thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1