PDA

View Full Version : when mouse clicks on object


billeyx69
04-09-2006, 01:09 PM
hey guys, im doing a project for school and i'm having lots of trouble because i'm not very good with computers. But my project is just a simple bowling ball knocking down some pins. The problem I have is how do i get the ball to roll in the direction of what pin i click onto. I know in the events I have to have when mouse clicks under "pin" do "certain action." What classes should I be having and what parameters? please help....

lanceA
04-10-2006, 08:12 PM
I'm sure there are several ways to do this but I would create an event to handle the mouse click, as you mention, and then write an event handler method called something like pinDown (or a name of your choice):

when mouse clicked on anything
do World.pinDown clicked = object under mouse cursor

this will call your pinDown method where you can do something similar to the code below to check what object was clicked. You will need to pass your object clicked as a parameter to the method:

For all World.bowlingPins, one Obj item_from_bowlingPins at_a_time
if clicked == item_from_bowlingPins
*/ your code goes here to handle moving ball to clicked-pin
and then computing score or what ever your program is to
accomplish
/*

There is probably a better way but at least this will give you a starting point. If you are not familiar with parameters and event handling methods you may wish to review Chpt 5 in the manual. Good luck with your project.

Jeremy
04-24-2006, 08:12 PM
hey guys, im doing a project for school and i'm having lots of trouble because i'm not very good with computers. But my project is just a simple bowling ball knocking down some pins. The problem I have is how do i get the ball to roll in the direction of what pin i click onto. I know in the events I have to have when mouse clicks under "pin" do "certain action." What classes should I be having and what parameters? please help....

To understand what to do you need to know about the following:

How create a method
How to create a parameter in that method


To make things simple, I'm focusing on just getting one pin to fall down when you click on it.

The best way to be to create one World method with an Object type as parameter. Call this method hitPin with a param called whatPin.

In the method hitPin, write these commands.

bowlingBall turnToFace whatPin
bowlingBall moveTo whatPin
whatPin turn Backward 1/4


Then for each of the pin, have an event when the Mouse Is Pressed and drag hitPin method to each of these events.

And yes, if you have access to the textbook, chapter 5 has GREAT information on how to do this.

To get other pins to fall, you would want to learn about WHEN SOMETHING IS TRUE event. For example, when the distance from the ball to the pin is less than half the width of the ball, the pin should fall over.