Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

make objects disapear when hit

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

596 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