Results 1 to 6 of 6

Thread: Ball Getting Stuck!

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    In my air hockey game (i guess you can call it pong) I got the puck to bounce around the screen, but I can't get it to bounce off of an object. Something always goes wrong. Here is what I used:

    'Bounces Puck Around Screen
    Image1.Move Image1.Left + DeltaX, Image1.Top + DeltaY
    If Image1.Left < Picture1.Left Then DeltaX = 100
    If Image1.Left + Image1.Width > Picture1.Width + Picture1.Left Then
    DeltaX = -100
    End If
    If Image1.Top < Picture1.Top Then DeltaY = 100
    If Image1.Top + Image1.Height > Picture1.Height + Picture1.Top Then
    DeltaY = -100
    End If

    'Bounces Off Of Paddle
    If Image1.Left < Image2.Left Then DeltaX = 100
    If Image1.Left + Image1.Width > Image2.Left + Image2.Width Then
    DeltaX = -100
    End If

    Please Help (Please do not send new code, I am comfortable with this for now, please just fix it.)
    Thanx.

    Steve

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    what's deltax and deltay?


    ------------------
    DiGiTaIErRoR

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    Sorry, These are there also:
    Desclarations:
    Dim DeltaX, DeltaY As Integer
    FormLoad:
    Private Sub Form_Load()
    DeltaX = 100
    DeltaY = 100
    End Sub

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Try this for your DeltaX. BTW I assume that Image2 is to the left of Picture1.
    Code:
    If DeltaX = -100 Then ' Going left
        If Image1.Left + Image1.Width > Image2.Left + Image2.Width Then
            DeltaX = -100
        Else
            DeltaX = 100
        End If
    ElseIf Image1.Left + Image1.Width > Picture1.Width + Picture1.Left Then ' Going right
            DeltaX = -100
        Else
            DeltaX = 100
    End If
    
    Image1.Move Image1.Left + DeltaX, Image1.Top + DeltaY
    ------------------
    Marty

    [This message has been edited by MartinLiss (edited 12-03-1999).]

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Post

    The picture box is what this is all in, it is the "arena". Image2 is the paddle, and image1 is the ball. Sorry if I confused you.

    Steve

    [This message has been edited by SteveCRM (edited 12-03-1999).]

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    if you want to send me a zip of your project, I'll take a look at it.

    ------------------
    Marty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width