This site requires JavaScript, please enable it in your browser!
Greenfoot back
CHERNANDEZ95
CHERNANDEZ95 wrote ...

2013/2/18

Can't get Orb to bounce off of paddle...

CHERNANDEZ95 CHERNANDEZ95

2013/2/18

#
Help please. I am not really sure what I am doing wrong. Here is the code for the paddle: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; public class Paddlet extends Actor { public void act() { handlePaddleCollision(); topPaddleKeys(); } public void topPaddleKeys() { if(Greenfoot.isKeyDown("a")) { move(2); } if(Greenfoot.isKeyDown("s")) { move(-2); } } public void handlePaddleCollision() { Orb orb = (Orb) getOneIntersectingObject(Orb.class); if (orb != null) { orb.reverseY(); } } }
ajamesc97 ajamesc97

2013/2/19

#
I would add this method to your Paddlet class:
public boolean canSee(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        return actor != null;        
    }
Then assuming the code for your reverseY method is correct, change the code within your handlePaddleCollision method to:
public void handlePaddleCollision()
{      
      if(canSee(Orb.class))
      {
            orb.reverseY();
      }
}
CHERNANDEZ95 CHERNANDEZ95

2013/2/19

#
Thanks for the help. Gonna go ahead and try it out.
You need to login to post a reply.