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

2013/5/16

Good bounce and direction

welleid welleid

2013/5/16

#
Hey I have another question. I'm sorry for always asking, but as it is a school project, with a nice small mark, i want it to be good. I'm upgrading my breakout game , with a new system. I have actually (thanks to Danpost and Davmac) a world that loads some blocks in a circular way (the blocks are arranged in a circle shape), and are moving (turning as a wheel) around the center of the world. I also have a plate that moves with the keyboard keys and that turns around the world. Now, my problem is the ball's bounce. When the ball hits a bloc, it's supposed to bounce in the right direction. So if my bloc is with a rotation of 92, i need my ball to bounce the good way, but when it is with a rotation of -107, i also need a good bounce. Before, i used this :
Bloc bloc = (Bloc)getOneIntersectingObject(Bloc.class);
        
        if(bloc != null) 
        {
            Greenfoot.playSound("plop.wav");
            
            if (getX() >= bloc.getX()-bloc.getImage().getWidth()/2 && getX() <= bloc.getX()+bloc.getImage().getWidth()/2)
            {
                moveY = -moveY;
            }
            
            else if (getY() >= bloc.getY()-bloc.getImage().getHeight()/2 && getY() <= bloc.getY()+bloc.getImage().getHeight()/2)
            {
                moveX = -moveX;
            }
            
            else
            {
                moveX = - (moveX + Greenfoot.getRandomNumber(3) );
            }
}
It worked when the blocs were not moving, and when their rotation was always the same, arranged in line. Now that it's moving, it doesn't work anymore. So i tried with some
setRotation( -bloc.getRotation() );
while using a simple move(3); for my ball, but doesn't work. And i'd like to keep this method for my ball :
setLocation(getX() + moveX, getY() + moveY);
//moveX and moveY are defined above
so i can create some cool bonus that could alter that and other stuff. Thanks a lot !
danpost danpost

2013/5/16

#
If the 'wheel' of blocks has no breaks between them (there is no space between them), then the wheel on a whole can be treated as a large ball that the pong ball will bounce off of. The rotation of the block contacted should give the actual angle between the two centers (within reason). The calculation for the bounce should be fairly straight-forward.
You need to login to post a reply.