Help: Keeping Score: Ball > Hoop

Ok first off, HI!!! My name is Jeff Snow. You all can call me Dryst or jeff, whatever.

Ive been browsing these tutorials and message boards for a few weeks, so here I am :).


Ok heres the problem

I made this Ball+Gravity thing, and now I want to add a Hoop and have it keep score. I know about the _root.total = _root.total + 1; part of the code, but how would I go about making it only work if the ball goes through the net from the top.
And what extra code would I have to add to make the net play a little movie clip animation when the ball passes through?.

This is what I have so far http://members.cox.net/dryst17/Gravity.html

Thanks alot everyone, cya

Well if you had an mc called hop (just the top rim), you could use:

if (_root.ball.hitTest(_x, _y, true)) {
_root.score++
}

So when the ball goes through the center of the hoop (providing that’s where the registration point is) the score will increase. But you need to set it so that the score only increases upon the first contact, and not repeated contacts (otherwise the score will continue increasing as it’s going “through” the hoop) - which isn’t too difficult to do, but also have it so that the score dosn’t increase when the hit test is true if the ball bounces back up.

You can also use a hit test to make sure that the ball only register a score when it drops from the top and not just hitting the hoop sideways.

Also use !drag - drag = false - (if you use drag as a variable to set whether the balls is being dragged or not) so that you can’t cheat and just drag the ball through.

It sounds like an interesting idea and if I get a mo, I’ll try and do a fla. unless someone already has, or has better ideas.

I’ll get right on that! thanks! =)

I think the ball needs to be tagged ‘ball’ or something, I think the rest of the code is fine, its just not understanding what the ball part is in (_root.ball.hitTest ect…)

The ball is a movie clip, the movie clip is named ball. the balls code is this

onClipEvent (load) {
gravity = 2;
floor = 383;
floorx1 = 17;
floorx2 = 533;
bounce = 0.80;
speedx = 0;
speedy = 0;
}
onClipEvent (enterFrame) {
if (pressing) {
// if we are pressing
// drag the object
startDrag (this, true);
// calculate the speed
speedx = this._x-x0;
speedy = this._y-y0;
// set a new reference point
x0 = this._x;
y0 = this._y;
} else {
stopDrag ();
speedy = speedy+gravity;
this._x += speedx/7;
this._y += speedy/7;
if (this._y>floor) {
this._y = floor;
speedy *= -bounce;
}
if (this._x<floorx1) {
this._x = floorx1;
speedx *= -bounce;
}
if (this._x>floorx2) {
this._x = floorx2;
speedx *= -bounce;
}
}
}

And the hoop looks like this so far

onClipEvent (load) {
if (_root.ball.hitTest(_x, _y, true)) {
_root.total = _root.total + 1;}
}

but its not registering to the dynamic text with the var: total to raise +1 … hmm whats wrong

-Dryst

It’s easier if your post you fla, than typing out all the code! Post it if you can, if not, I’m looking at your code now, anyway.

Well first of all

onClipEvent (load) {
if (_root.ball.hitTest(_x, _y, true)) {
_root.total = _root.total + 1;}
}

should be

onClipEvent (enterFrame) {
if (_root.ball.hitTest(_x, _y, true)) {
_root.total++; // same as doing _root.total = _root.total + 1
}

You rock! that got it working, but as you predicted, the score goes up fast, as the ball is inside the hoop object.

here is the .fla

Well that’s the score problem sorted, now for the others…

I dont have MX yet bro…
cant open your file

Flash 5 format

Thank you so much!

Ok on the checklist there is:

  1. no drag cheating, this one should be easy, i wish i knew the code though lol

  2. make it so it cant score from the side (is there any way to make it bounce off the side of the rim?

  3. Im going to make a net with a movieclip animation, is there a way to trigger the nets animation when there is a score?

hmm

Possibly add a small invisible box on the outer sides of the hoop and code it to react with the ball using something similar to the bounce code on the ball?

I thought off the net alread! I’m trying little bits here and there while I drink my pepsi and munch chocolate. That part is easy.

The rim - just put a movie clip there and have it so that if the ball hits, the _x and _y are reversed so it bounces off.

The drag one needs a variable.

But you also need to either increase the size of the ball, decrease the size of the hoop, or increase the hit area, because _x, _y in the hit test works if the ball goes the centre of the hoop, but the ball is small so it still goes through - even though it’s not in the centre, and no score is registered.

Here the fla with the rim done - works ok. The zip has MX and Flash 5

And here’s the dragging prevention done. I know I should have just edited the other post, but it’s 2:10 am here - and I haven’t the energy…

Your help is Greatly appreciated. I am so thankful for everything!

No probs. As I far as I can remember, the only thing needed now is to prevent the ball from scoring if it bounces up.

I am trying to add another rim on top of the first ‘rim’ that will make it bounce up, Im trying to code it on the _y axis,

here take a look

you have helped more than enough, I have nothing but respect for you and your kindess. thanks for everthing and go to bed!

Reposted it - the other one was dodgy!

Try this one