(http://images.hugi.is/blog/61992.jpg)
As you can see this picture is from my game I am trying to work on. I am trying to make some kind of NBA hoops basket ball.
The problem is how can I let the first ball move from left and right and the second ball up and down repeatatly. I also want to know what I should do when I touch the basket ball and let it stop exactly where you pointed it on the target. If the two basketball is on the middle of the target the balltrower wil hit the target and score. And when I don't stop the ball on the middle of the target I want the thrower miss the target.
What I also want to know is how to change speed of the basketballs objects in each time a different character with different skills on hitting the hoops and if I am going to make a option for a easy and harder level.
Does anyone got my idea what I am trying to do here?
I know you have all played NBA basketball by EAsports so I think you get my point here.
Since I don't know how to do this. Can anyone help me with this? Give me some code how to do this and I will add you on the credit list if you want.
QuoteI know you have all played NBA basketball by EAsports so I think you get my point here.
I haven't, but here goes anyway...
1. Movement.
Something like this in
rep_ex (untested, so no promises):
if (oBall1.Moving == false) { // Ball1 isn't moving
if (oBall1.X == x1) oBall1.Move(x2, oBall1.Y, 3); // If it's on the left, move it to the right
else if (oBall1.X == x2) oBall1.Move(x1, oBall1.Y, 3); // If it's on the right, move it to the left
}
(Replacing x1 and x2 with the actual coords, of course.) And something similar for oBall2, checking oBall2.Y.
Another way would be to make the balls characters, and use
Character.AddWaypoint2. Stopping when clicked.
Add a check to see whether the ball has been clicked on:
// Click on oBall1
ball1clicked = 1;
// rep_ex
if (oBall1.Moving == false && ball1clicked == 0) { // Ball1 isn't moving, and hasn't been clicked
// etc ...
3. Change speed.
Again, use a variable to track speed, and put it in the
Object.Move commands (where I've put '3'). Increase/decrease the variable based on difficulty, level, etc.
4. Hit or miss.
Check whether
oBall1.X and
oBall2.Y are at the right value (or in the right range of values). If so, you made the hoop, if not, it's a miss. If you go for the range of values, you could also narrow it, as difficulty increased.
That should do it. Hopefully, I haven't missed out/misunderstood anything.
Player enter room (after fadein):
object[1].Move(109,70,1);
Repeatedly execute:
if (oBall1.Moving == false) { // Ball1 isn't moving
if (oBall1.X == 109) oBall1.Move(55, oBall1.Y, 2); // If it's on the left, move it to the right
else if (oBall1.X == 55) oBall1.Move(109, oBall1.Y, 2); // If it's on the right, move it to the left
}
This formula code worked perfect for me with the left to right.
But I have still problem with the second ball. I can't let it go from bottom to the top. It just bounce off and then it just stop.
First thing I try to do is:
Player enter room (after fadein):
object[0].Move(85,40,3);
And then in repeatedlyÃ, execute:
if (oBall2.Moving == false) { // Ball2 isn't moving
Ã, if (oBall2.Y == 97) oBall2.Move(40, oBall2.Y, 3); // If it's on the top, move it to bottom
Ã, else if (oBall2.Y == 40) oBall2.Move(97, oBall2.Y, 3); // If it's on the bottom, move it to top
}
So what is wrong here?
Thanks again for the code. I was really helpful. I will add your nickname in the credit list when the game is done Ashen.
Well, you're checking the Y coord, but when you move it, you're only changing the X coord. It should (as it is now) go to (85,40), then to (97,40) - or not depending on walkable areas - then stay there . Is that what's happening? Try this instead:
if (oBall2.Moving == false) { // Ball2 isn't moving
if (oBall2.Y == 97) oBall2.Move(oBall2.X, 40, 3); // If it's on the top, move it to bottom
else if (oBall2.Y == 40) oBall2.Move(oBall2.X, 97, 3); // If it's on the bottom, move it to top
}
Since they don't change, you can probably replace oBall1.Y and oBall2.X with the actual values, as well (I'd guess 70 and 85 respectively). I was just trying to make the code as generic as possible.
Otherwise - since object[0].Move works, and oBall2.Move doesn't seem to, are you sure Object 0 is called oBall2?
Also, try to be more consistant in how you refer to the objects - e.g. always use object[0] or always use oBall2, rather than alternating as you are now. (This probably isn't the problem, it's just a good habit and makes the code easier to read.)
check your e-mail I was sending to you. Maybe that will help. Yeah I know there is suppose to be balls moving there but instead you will just see a moving blue cups hehehe lol.
But I hope you can figure it out for me.
Use the 640x480 to see the image better.
You've got two non-blocking movements for oBall2 in 'Player enters screen (after fade-in)' which wouldn't be a problem, except the second one (Object - Move object (0,97,40,3,false)) tries to move it off the walkable area - which I think is what's causing it to 'stick'. As with the code before, you're changing it's X coord, when you want to change the Y. Correct it (Object - Move object (0,85,97,3,false)), or just delete it, and it works fine.
Hopefully, that's one hurdle out of the way, anyway.
I worked. Many thanks Ashen. I just need to adjust it just a little more with coords and it will be fine but it worked. I add your name in my credit list as a thanks gift to you.