This site requires JavaScript, please enable it in your browser!
Greenfoot back
Yurey
Yurey wrote ...

2015/4/26

I have more problems than thought ^^'

1
2
Yurey Yurey

2015/4/26

#
private void getDamage()
    {
        if (getOneIntersectingObject(Teufelfireball.class))
        {
            hp-20+Greenfoot.getRandomNumber(5);
            getWorld().removeObject(Teufelfireball);
        }
    }
error report: not a statement (line 5) the hp variable:
private int hp;
  protected void addedToWorld(World world)
    {
        hp = ((Healthbar)world.getObjects(Healthbar.class).get(0)).hp;
    }
Super_Hippo Super_Hippo

2015/4/26

#
Maybe it should be this instead?
hp -= 20+Greenfoot.getRandomNumber(5);
danpost danpost

2015/4/26

#
Use 'removeTouching(Teufelfireball.class)'.
Yurey Yurey

2015/4/26

#
ahh ty now i get a error report in line 3:
private void getDamage()
    {
        if (getOneIntersectingObject(Teufelfireball.class))
        {
           hp -= 15+Greenfoot.getRandomNumber(5);
            getWorld().removeObject(Teufelfireball);
        }
    }
error report: incompatibel types
Super_Hippo Super_Hippo

2015/4/26

#
You could use this:
    private void getDamage()
    {
        if (isTouching(Teufelfireball.class))
        {
            hp -= 15+Greenfoot.getRandomNumber(5);
            removeTouching(Teufelfireball.class);
        }
    }
Yurey Yurey

2015/4/26

#
so the variable hp dont react i think it dont work :/ another idea ?
Yurey Yurey

2015/4/26

#
one more problem to solve:
private int dmgCount=0;
    private boolean loseLife=false;
    public void act() 
    {
        searchTargetEngel();
        getDamage();
        die();
    }  
    public void searchTargetEngel()
    {
       if (!getWorld().getObjects(Teufelfireball.class).isEmpty())return;
       for (Object obj :  getObjectsInRange(10, Engel.class))
       {
          Actor Engel = (Actor) obj;
          Teufelfireball b = new Teufelfireball();
          getWorld().addObject(b, getX(), getY());
          b.turnTowards(Engel.getX(),Engel.getY());
          b.move(1);
       }
    }
       private void getDamage()
    {
        if (isTouching(Engelfireball.class) && loseLife == true)
        {  
           removeTouching(Teufelfireball.class);
           dmgCount++;
           loseLife=false;
        }
    }
    private void die()
    {
        if(dmgCount==5)
        {
             getWorld().removeObject(this);
        }
    }
where can i place a methode to set the boolean from loseLife true ?
danpost danpost

2015/4/27

#
Yurey wrote...
where can i place a methode to set the boolean from loseLife true ?
I could say "in the class that contains the boolean field"; but, I have a feeling that is not quite what you meant. Please be specific and show what you tried. Explain when you want the field to be set to true (what condition should be met). Maybe it should be true to start as well.
Yurey Yurey

2015/4/27

#
ok at the moment the problem is that 1 fireball is added more than 5 times to the dmgCount variable he seems to touch the Teufel.class oftener than just 1 time. But i like to increase the dmgCount for 1 if 1 fireball touches the Teufel. thats why i wanted to use the boolean loseLife lose Life should mean the time in witch the fireball can increase the dmgCount. i hope u know what i mean :D
danpost danpost

2015/4/27

#
I think I understand -- you want a 'lifeLoseReset' method to be called before 'getDamage' in the 'act' method.
Yurey Yurey

2015/4/27

#
yes but i dont know what to use... Is it possibale to increase the dmgCount from the script of the Engelfireball.class ? if yes how can i use it...
danpost danpost

2015/4/27

#
Do you have code in the Teufelfireball class that check for intersection with the object of this class as well?
Yurey Yurey

2015/4/27

#
no my code for the fireball is:
public boolean atWorldEdge()
    {
        if(getX() <=0 || getX() >= 78)
            return true;
        if(getY() <=0 || getY() >= 58)
            return true;
        else
            return false;
    }
    public void act() 
    {
        // Add your action code here.
        move(1);
        atEdge();
    } 
    private void atEdge()
    {
        if (atWorldEdge()==true)
        {
            getWorld().removeObject(this);
        }
    }
and the code of the actor which shoots the Engelfireball:
 public void searchTargetTeufel()
    {
       if (!getWorld().getObjects(Engelfireball.class).isEmpty()) return;
       for (Object obj :  getObjectsInRange(10, Teufel.class))
       {
          Actor Teufel = (Actor) obj;
          Engelfireball a = new Engelfireball();
          getWorld().addObject(a, getX(), getY());
          a.turnTowards(Teufel.getX(),Teufel.getY());
          a.move(2);
       }
    }
danpost danpost

2015/4/27

#
Shouldn't the Teufel class be removing an object of the Engelfireball class in the 'getDamage' method? After fixing that you can remove the 'loseLife' field from the class code.
Yurey Yurey

2015/4/27

#
no it should because the engel would shot faster if the fireball get removed wait i will try to code something..
There are more replies on the next page.
1
2