?
Solved

make objects disapear when hit

Posted on 2001-06-19
4
Medium Priority
?
157 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 200 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

801 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