Solved

make objects disapear when hit

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

785 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