Hello, I am making a pong game and I want the scoreboard to go up by 1 evertime it bounces off the baby_1 and I also have a baby_2 as the other actor but im jsut trying to get it work on baby_1 atm, however atm it gives me this error when it tries to bounce off?
java.lang.NullPointerException at ball1.hitAnbaby_1(ball1.java:52) at ball1.act(ball1.java:29) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211) java.lang.NullPointerException at ball1.hitAnbaby_1(ball1.java:52) at ball1.act(ball1.java:29) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ball1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
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 void act()
{ move(5);
if (getX() <= 5 || getX() >= getWorld().getWidth() - 5)
{move(5);
turn(Greenfoot.getRandomNumber(100)-90);}
if (getY() <= 5 || getY() >= getWorld().getHeight() - 5)
{ move(5);
turn(Greenfoot.getRandomNumber(100)-5);}
Actor baby_1 = getOneIntersectingObject(baby1.class);
if (baby_1!=null)
{ turn(180);
hitAnbaby_1();
}
Actor baby_2 = getOneIntersectingObject(baby2.class);
if (baby_2!=null)
{turn(180);}
Actor baby_3 = getOneIntersectingObject(baby3.class);
if (baby_3!=null)
{ turn(180);}
Actor baby_4 = getOneIntersectingObject(baby4.class);
if (baby_4!=null)
{turn(180);}
}
private void hitAnbaby_1()
{
MyWorld World = (MyWorld) getWorld();
Counter counter = World.getCounter();
counter.bumpCount(1);
}
}