Hi. I'm looking for a formula to use to change the trajectory of a hockey player bouncing and sliding around a rectangle through use of the inbuild move method.
This method seems to work perfectly, but sometimes the player manages to get stuck beyond the boundaries.
The object rotates left and right with keypresses. It moves in the direction in is facing. Maybe it's to do with turning the object while bouncing off a wall?
Anyway, here is the link to observe what I mean: http://www.greenfoot.org/scenarios/7181
I'm looking for criticism of my method and advice to solve my problem of moving beyond boundaries. Thanks
As an additional question: I want to be able to shoot the puck and give it the current rotation of the hockey player. This allows the puck to move that direction. I have some code already for this, but there are glitches. I will post more details at request. All the code is visible in the link.
private void checkWalls() { if((getY()<topWall && (getRotation()<0 || getRotation()>180))) setRotation(-getRotation()); if((getY()>bottomWall && (getRotation()<180 || getRotation()>0))) setRotation(-getRotation()); if(getX()<leftWall && (getRotation()>90 || getRotation()<270)) setRotation(-getRotation()-180); if(getX()>rightWall &&(getRotation()>270 || getRotation()<90)) setRotation(-getRotation()+180);