I am attempting to make a game similar to air hockey with both a two-player and a single-player version with a cpu. My two-player version works perfectly. However, even though the puck has the exact same code on the CPU version, it goes straight to a corner and "sticks" there. The puck is supposed to bounce off of a certain sprite (sprite 4) that makes up a border. Even though the code is the exact same thing for bouncing off of the border on the CPU version, it "sticks".
The border is "sprite 4"
The human player is "paddle right"
The computer player is "CPU"
This is the code on both the CPU and two-player versions for bouncing off of the paddles and the border. I know that I could just use "if on edge, bounce", but I would prefer to use this complex border.
when gf clicked forever if <touching [Sprite 4 v]?> turn cw (180) degrees end if <touching [CPU v]?> point in direction (90 v) turn cw (pick random (-45) to (45)) degrees end if <touching [Paddle Right v]?> point in direction (-90 v) turn cw (pick random (-45) to (45)) degrees end
Last edited by JSO (2012-03-25 05:15:46)
Offline
This is the game. For some reason, it does not work at all when you try to play it online, so please download it. One of the sprites is invisible, and the background does not show up at all!
http://scratch.mit.edu/projects/bmpatschool/2402236
The issue is on the "Puck" sprite, about 1/2 way down the page. The top row of options are the different levels of CPU, and the bottom row of options are the different levels of two-player. Like I said before, the whole bottom row works perfectly, while the top row does not.
Offline
bmpatschool wrote:
This is the game. For some reason, it does not work at all when you try to play it online, so please download it. One of the sprites is invisible, and the background does not show up at all!
http://scratch.mit.edu/projects/bmpatschool/2402236
The issue is on the "Puck" sprite, about 1/2 way down the page. The top row of options are the different levels of CPU, and the bottom row of options are the different levels of two-player. Like I said before, the whole bottom row works perfectly, while the top row does not.
When you put a link, put a "[ url ]" before it and a "[ /url ]" after it. Here's the fixed link: http://scratch.mit.edu/projects/bmpatschool/2402236
Offline
I believe New Scratchers can't post links. [/offtopic]
Offline
Hardmath123 wrote:
I believe New Scratchers can't post links. [/offtopic]
Oh, yeah. Forgot
Offline
Anyone?
Offline
You should go to the Scratch Wiki and read about Artificial Intelligence, or AI. I recommend you not start off with that because it is very difficult, but view the Scratch Wiki if you are determined to do it.
Offline
Haiming wrote:
You should go to the Scratch Wiki and read about Artificial Intelligence, or AI. I recommend you not start off with that because it is very difficult, but view the Scratch Wiki if you are determined to do it.
Thanks so much for the help!
Offline
Any ideas why it would work differently with the same code?
Offline
bmpatschool wrote:
Haiming wrote:
You should go to the Scratch Wiki and read about Artificial Intelligence, or AI. I recommend you not start off with that because it is very difficult, but view the Scratch Wiki if you are determined to do it.
Thanks so much for the help!
Your welcome. Is that sarcasm?
Offline
Haiming wrote:
Your welcome. Is that sarcasm?
No, I really meant thank you. BTW, do you know why the code would act differently when it is the same?
Offline
bmpatschool wrote:
Haiming wrote:
Your welcome. Is that sarcasm?
No, I really meant thank you. BTW, do you know why the code would act differently when it is the same?
The code might act differently because:
- the timer has increased since you last played it before
- the speed or lag of the computer is different
- the ask block might get a different input from before
Offline
Can someone give me an idea on how to get started with the AI? I know that I have to use the "if...else" blocks.
Offline
bmpatschool wrote:
when gf clicked forever if <touching (Sprite 4)> turn 180 degrees end if <touching (CPU)> point in direction 90 turn pick random -45 to 45 degrees end if <touching (Paddle Right)> point in direction -90 turn pick random -45 to 45 degrees
Why are you picking a random number from -45 to 45?
And Why automatically set direction to 90 or -90?
Offline
LiquidMetal wrote:
bmpatschool wrote:
when gf clicked forever if <touching (Sprite 4)> turn 180 degrees end if <touching (CPU)> point in direction 90 turn pick random -45 to 45 degrees end if <touching (Paddle Right)> point in direction -90 turn pick random -45 to 45 degreesWhy are you picking a random number from -45 to 45?
And Why automatically set direction to 90 or -90?
If 90 degrees is picked, then the puck just bounces up and down off of the side walls.
Offline
Click here for correct physics for if touching [whatever v] bounce. If you use it, please give credit to my account page, aside from the fact that the project is on my test account. I worked hard on it. Arc Tangent and trig in general is really hard to work with.
Offline