If "void" is what you named a class, rename it. Remove lines 28 thru 30 in ball1 class.
// this if (getX() == 0 && r > 90 && r < 270) setLocation(getWorld().getWidth()-1, getY());
public void(){ int x,y; if(ball.ycoordinate>y) { setLocation(x , y + 5); } if(ball.Ycoordinate<y)[quote]actor class[/quote] { setLocation(x, y - 5); } }
public class ball1 extends Actor { /** * Act - do whatever the ball1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public int direction = 10; public void act() { move(direction); wrapEdges(); Actor player_1 = getOneIntersectingObject(player1.class); if (player_1!=null) { if(isTouching(player1.class)) { turn(90+Greenfoot.getRandomNumber(180));\ } } Actor player_2= getOneIntersectingObject(player2.class); if (player_2!=null) { if(isTouching(player2.class)) { turn(90+Greenfoot.getRandomNumber(180)); } } if(isAtEdge()){ turn(90+Greenfoot.getRandomNumber(180)); } } private void wrapEdges() { int r = getRotation(); if (Greenfoot.getRandomNumber(180) == 0) turn (Greenfoot.getRandomNumber(180)-90); if (getX() == getWorld().getWidth()-1 && (r > 270 || r < 90)) setLocation(0, getY()); if (getX() == 0 && r > 90 && r < 270) setLocation(getY(),getWorld().getWidth()-1); if (getY() == getWorld().getHeight()-1 && r < 180) setLocation(getX(), 0); if (getY() == 0 && r > 180) setLocation(getX(), getWorld().getHeight()-1); }
if (getX() == 0 && r > 90 && r < 270) setLocation(getY(),getWorld().getWidth()-1);
if (getX() == 0 && r > 90 && r < 270) setLocation(getY(),getWorld().getWidth()-1);
public class ball1 extends Actor { public void act() { move(10); wrapEdges(); bounce(); } private void wrapEdges() { boolean hitEdge = false; int r = getRotation(); if (getX() == getWorld().getWidth()-1 && (r < 90 || r > 270)) { setLocation(0, getY(); hitEdge = true; } if (getX() == 0 && r > 90 && r < 270) { setLocation(getWorld().getWidth()-1, getY()); hitEdge = true; } if (getY() == getWorld().getHeight()-1 && r > 0 && r < 180) { setLocation(getX(), 0); hitEdge = true; } if (getY() == 0 && r > 180) { setLocation(getX(), getWorld().getHeight()-1); hitEdge = true; } if (hitEdge) turn(Greenfoot.getRandomNumber(90)-45); } private void bounce() { if (isTouching(player1.class) || isTouching(player2.class)) { turn(Greenfoot.getRandomNumber(180)+90); } } }
move(-10);
import greenfoot.*; import java.util.*; public void act(){ printYouLose(); } public void printYouLose(){ UserInfo myInfo = UserInfo.getMyInfo(); Class c = Bear.class; List<Bear> lst=getObjects(c); if(lst.size()==0){ //World myWorld = getWorld(); showText(myInfo.getUserImage()+""+myInfo.getUserName() +" you have been died by a rock",getWidth()/2,getHeight()/2); Greenfoot.stop(); } }
private void bounce() { if (isTouching(player1.class) || isTouching(player2.class)) { turn(Greenfoot.getRandomNumber(180)); move(-5);// I typed -5 you can type any number of speed. //you can also type 5. } } }