Solved

make objects disapear when hit

Posted on 2001-06-19
4
151 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
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now