Solved

make objects disapear when hit

Posted on 2001-06-19
4
154 Views
Last Modified: 2010-05-02
I am having trouble with Visual basic 6 I have a ball that bounces around the screen, but i want the ball to hit an object and i want that object to disapear and rebound the ball.  How do you do this and is it possible to e-mail me the code on how to do this.  Thank you
0
Comment
Question by:eniray
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Expert Comment

by:kingkev
ID: 6208146
Use the set visible to false property of the object you wish to hide. You need to know the x y corrdinates of the objects that are avaiable.
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 50 total points
ID: 6211309
If you use a square, it's a lot easier to have it "bounce" because the boundaries are linear instead of arched.

If the object being hit is at rectangle (0,0)-(100,100) and the "ball" is at (200,200)-(210,210) traveling at a 45-degree up and left one pixel at a time, then 100 pixels later it will be at (100,100)-(110,110).

Assuming that your ball is a picturebox, the above properties will be defined as:

ball.left=100
ball.top=100
ball.width=11
ball.height=11
BallRight=ball.left+ball.width-1
BallBottom=ball.top+ball.height-1

Similarly, if the other objcet is a picturebox, its properties will be:

wall.left=0
wall.top=0
wall.width=101
wall.height=101
wallRight=wall.left+wall.width-1
wallBottom=wall.top+wall.height-1

After each move of either object (or before, depending on how you want to code it), check to see if the perimeter of one has crossed the perimeter of the other:

if (ball.left > wall.left and ball.left < wallRight)
or (ballRight > wall.left and ballRight < wallRight) then
  ' the horizontal coordinates overlaps; check vertical
  if (ball.top > wall.top and ball.top < wallBottom)
  or (ballBottom > wall.top and ballBottom < wallBottom) then
    msgbox "We have a collision!"
    wall.visible = false
  endif
endif

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139540
Hi eniray,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept rspahitz's comment(s) as an answer.

eniray, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7173292
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question