What am I doing wrong?
This is my ball, most the code is in here.
import greenfoot.*; import java.util.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Ball here. * * @author (your name) * @version (a version number or a date) */ public class Ball extends Bar { boolean start = true; Random r = new Random(); int num = r.nextInt(2); Bar bar; public int X(){ return getX(); } public int Y(){ return getY(); } public void act() { if (start == true && Greenfoot.isKeyDown("space")){ if (num == 1){ turn(0); turn(315); } else{ turn(0); turn (225); } start=false; } if (start==false){ move(1); } if (start == true && Greenfoot.isKeyDown("left")){ move(-2); } if (start == true && Greenfoot.isKeyDown("right")){ move(2); } endX(); endY(); bounceBar(); bounceBrick(); } public void endX(){//for left and right if (X()== 749){ if (getRotation() == 315){ turn(-90); } if (getRotation() == 45){ turn(90); } } if (X()== 0){ if (getRotation() == 225){ turn(90); } if (getRotation() == 135){ turn(-90); } } } public void endY(){ //for up and down if (Y()== 0){ if (getRotation() == 315){ turn(90); } if (getRotation() == 225){ turn(-90); } } if (Y()== 659){ System.out.println("You lose"); Greenfoot.stop(); } } public void bounceBar(){ if (isTouching(Bar.class)){ if (getRotation() == 315){ turn(90); } if (getRotation() == 225){ turn(-90); } if (getRotation() == 135){ turn(90); } if (getRotation() == 45){ turn(-90); } } } public void bounceBrick(){ if(isTouching(Brick.class)){ if (getRotation() == 315){ turn(90); removeTouching(Brick.class); } if (getRotation() == 225){ turn(-90); removeTouching(Brick.class); } if (getRotation() == 135){ turn(90); removeTouching(Brick.class); } if (getRotation() == 45){ turn(-90); removeTouching(Brick.class); } } } }