Hi, I have a problem with my score counter. The "Blasterschuss" class is a laser class. When firing the laser there is an error when it leaves the world. I don't know what the error is, just where it is. Please help me!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Blasterschuss here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Blasterschuss extends Actor
{
/**
* Act - do whatever the Blasterschuss wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int BlasterschussSpeed = 10;
private boolean removed = false;
static boolean TieKilled = false;
boolean BlasterschussKilled = false;
public void act()
{
setLocation(getX(), getY()-BlasterschussSpeed);
removed = true;
if(getY() < 2) {
getWorld().removeObject(this);
removed = true;
}
/*
if (!removed && canSee(Tie.class)); {
eat(Tie.class); //der tie wird bereits in der Tie-Klasse removed. da der tie nicht 2 mal removed werden kann, bekommst du hier den error.
} */
if(!TieKilled) {
if (canSee (Tie.class)){
eat1(Tie.class);
}
}
if(Tie.class != null)
{
Hintergrund1 hintergrund1 = (Hintergrund1)getWorld();
Counter counter = hintergrund1.getCounter(); - '{' - Here is something wrong
counter.addScore();
}
}
public void eat(Class clss) {
Actor Tie = getOneObjectAtOffset(0, 0, clss);
if(Tie != null) {
getWorld().removeObject(Tie);
}
}
public boolean canSee(Class clss) {
if(this!=null) {
return false;
} else {
return getOneObjectAtOffset(0, 0, clss) != null;
}
}
public void eat1(Class clss) {
Actor xWing = getOneObjectAtOffset(0, 0, clss);
if(xWing != null) {
getWorld().removeObject(xWing);
}
}
private void die()
{
Greenfoot.playSound("au.wav");
getWorld().removeObject(this);
}
}