Results 1 to 3 of 3

Thread: Can you help me for my first game ?

  1. #1

    Thread Starter
    Addicted Member oktay's Avatar
    Join Date
    Mar 2001
    Location
    Istanbul-TURKEY
    Posts
    158

    Question Can you help me for my first game ?

    Hello,

    I try to making my first game in VB , for doing it I need a little app that have one form and two textbox and every textbox have a different key controls ( for moving textboxes ) . My problem is when controls moving , I don’t want to go out the controls from the form and texboxes can hit to each other not to come over other textbox.Can you help me for provide these rules ? Thanks...

  2. #2
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    Mm, good old collision detection. Start with the borders for the sides of the form. The code you already have that moves the box to the left probably looks like this:

    Code:
    text1.left = text1.left - 1
    Before you execute that code, you wanna check to see if it CAN move left. In other words, see if the left side of the box is past the border. If it's not, then it can move.

    Code:
    If text1.left > 0 Then text1.left = text1.left - 1
    The top and left borders are similar, you just change .left to .top. For right/bottom, you'd have something like this:

    Code:
    If text1.left + text1.width < form1.width Then text1.left = text1.left + 1
    
    If text1.top + text1.height < form1.height Then text1.top = text1.top + 1
    The difference is you have to add the width or height so that yer comparing from the opposite side of the box.

    Then for the 2nd text box, it's exactly the same thing. You just compare the 1st box to the position of the 2nd:

    Moving right:

    Code:
    If text1.left + text1.width < text2.left And text1.left > text2.left + text2.width Then text1.left = text1.left + 1
    To understand recursion, one must first understand the concept of recursion.

  3. #3

    Thread Starter
    Addicted Member oktay's Avatar
    Join Date
    Mar 2001
    Location
    Istanbul-TURKEY
    Posts
    158
    Thanks,your answer give me an idea ...

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