This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-03-16 15:28:28

bmpatschool
New Scratcher
Registered: 2012-02-22
Posts: 9

Air Hockey Game Issues......

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

 

#2 2012-03-16 15:32:21

itsmomito
Scratcher
Registered: 2008-03-28
Posts: 100+

Re: Air Hockey Game Issues......

Could you please upload the project so that I can take a look? Thanks

Offline

 

#3 2012-03-16 21:06:40

bmpatschool
New Scratcher
Registered: 2012-02-22
Posts: 9

Re: Air Hockey Game Issues......

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

 

#4 2012-03-16 22:41:47

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: Air Hockey Game Issues......

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

 

#5 2012-03-17 05:12:25

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Air Hockey Game Issues......

I believe New Scratchers can't post links.  wink  [/offtopic]


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#6 2012-03-17 17:09:33

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: Air Hockey Game Issues......

Hardmath123 wrote:

I believe New Scratchers can't post links.  wink  [/offtopic]

Oh, yeah. Forgot  neutral

Offline

 

#7 2012-03-18 18:01:00

bmpatschool
New Scratcher
Registered: 2012-02-22
Posts: 9

Re: Air Hockey Game Issues......

Anyone?

Offline

 

#8 2012-03-18 18:49:09

Haiming
Scratcher
Registered: 2011-08-20
Posts: 1000+

Re: Air Hockey Game Issues......

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.  smile

Offline

 

#9 2012-03-18 19:28:17

bmpatschool
New Scratcher
Registered: 2012-02-22
Posts: 9

Re: Air Hockey Game Issues......

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.  smile

Thanks so much for the help!

Offline

 

#10 2012-03-20 14:00:10

bmpatschool
New Scratcher
Registered: 2012-02-22
Posts: 9

Re: Air Hockey Game Issues......

Any ideas why it would work differently with the same code?

Offline

 

#11 2012-03-20 20:09:28

Haiming
Scratcher
Registered: 2011-08-20
Posts: 1000+

Re: Air Hockey Game Issues......

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.  smile

Thanks so much for the help!

Your welcome. Is that sarcasm?  tongue

Offline

 

#12 2012-03-21 14:00:17

bmpatschool
New Scratcher
Registered: 2012-02-22
Posts: 9

Re: Air Hockey Game Issues......

Haiming wrote:

Your welcome. Is that sarcasm?  tongue

No, I really meant thank you. BTW, do you know why the code would act differently when it is the same?

Offline

 

#13 2012-03-21 14:28:31

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Air Hockey Game Issues......

bmpatschool wrote:

Haiming wrote:

Your welcome. Is that sarcasm?  tongue

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

 

#14 2012-03-23 14:01:10

bmpatschool
New Scratcher
Registered: 2012-02-22
Posts: 9

Re: Air Hockey Game Issues......

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

 

#15 2012-03-23 14:28:00

LiquidMetal
Scratcher
Registered: 2011-06-15
Posts: 500+

Re: Air Hockey Game Issues......

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

 

#16 2012-03-24 19:49:09

bmpatschool
New Scratcher
Registered: 2012-02-22
Posts: 9

Re: Air Hockey Game Issues......

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 degrees

Why 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

 

#17 2012-03-24 20:10:16

imnotbob
Scratcher
Registered: 2010-12-11
Posts: 1000+

Re: Air Hockey Game Issues......

Hardmath123 wrote:

I believe New Scratchers can't post links.  wink  [/offtopic]

They can, if the link is Scratch.


PesterChum Handle: annoyingAnchorman
durp yo terezi sup sup gotta beat john gotta beat john

Offline

 

#18 2012-03-31 12:11:24

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: Air Hockey Game Issues......

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

 

Board footer