|
-
Aug 5th, 2001, 12:00 PM
#1
Thread Starter
Addicted Member
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...
-
Aug 6th, 2001, 01:33 PM
#2
Addicted Member
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.
-
Aug 7th, 2001, 12:36 PM
#3
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|