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

2012/3/11

power ups?

6
7
8
9
GamesGrinder1998 GamesGrinder1998

2014/4/22

#
danpost wrote...
Move line 38 to before line 42 (before the 'return' statement).
Super_Hippo wrote...
danpost wrote...
Move line 38 to before line 42 (before the 'return' statement).
Line 37 ;) (And same with the others.)
well i did what you both said but it nows says cannot find symbol - variable halfWorldWidth, here is the code
import greenfoot.*;  

public class Iceball extends Actor
{
    private int direction, speed;

    public Iceball(int dir)
    {
        direction = 270;
        speed = 7;
    }

    public void act() 
    {
        setRotation(direction);
        move(speed);
        disappear();
    }    

    public void disappear()
    {
        Actor BugEnemy;
        BugEnemy = getOneObjectAtOffset(0, 0, BugEnemy.class);
        Actor InsectEnemy;
        InsectEnemy = getOneObjectAtOffset(0, 0, InsectEnemy.class);
        Actor Bee;
        Bee = getOneObjectAtOffset(0, 0, Bee.class);
        Actor DarkPower;
        DarkPower = getOneObjectAtOffset(0, 0, DarkPower.class);
        if (BugEnemy != null)
        {
            World world;
            world = getWorld();
            MyGame2 mygame2= (MyGame2)world;
            Counter2 counter2 = mygame2.getCounter2();
            counter2.addScore();
            int x = Greenfoot.getRandomNumber(halfWorldWidth);  
            if (getX() >= halfWorldWidth) x += halfWorldWidth;  
            BugEnemy.setLocation(x, Greenfoot.getRandomNumber(world.getHeight()))   ;  
            world.removeObject(this);
            int halfWorldWidth = world.getWidth()/2;  
            return;
        }    

        if (InsectEnemy != null)
        {
            World world;
            world = getWorld();
            world.removeObject(InsectEnemy);
            MyGame2 mygame2 = (MyGame2)world;
            Counter2 counter2 = mygame2.getCounter2();
            counter2.addScore();
            int x = Greenfoot.getRandomNumber(halfWorldWidth);  
            if (getX() >= halfWorldWidth) x += halfWorldWidth;  
            InsectEnemy.setLocation(x, Greenfoot.getRandomNumber(world.getHeight()));
            world.removeObject(this);
            int halfWorldWidth = world.getWidth()/2;  
            return;
        } 

        if (Bee != null)
        {
            World world;
            world = getWorld();
            world.removeObject(Bee);
            MyGame2 mygame2 = (MyGame2)world;
            Counter2 counter2 = mygame2.getCounter2();
            counter2.addScore();
            int x = Greenfoot.getRandomNumber(halfWorldWidth);  
            if (getX() >= halfWorldWidth) x += halfWorldWidth;  
            Bee.setLocation(x, Greenfoot.getRandomNumber(world.getHeight()));
            world.removeObject(this);
            int halfWorldWidth = world.getWidth()/2;  
            return;
        } 

        if (DarkPower != null)
        {
            World world;
            world = getWorld();
            world.removeObject(DarkPower);
            world.removeObject(this);
            return;
        } else {
            if (getY()<=0)
            {
                getWorld().removeObject(this);
                return;
            } 
        }
    }   
}    
Super_Hippo Super_Hippo

2014/4/22

#
Put that 'int halfWorldWidth = world.getWidth()/2;' where it was before. danpost only wrote the wrong line number. It was at the correct position. Only the 'world.removeObject(this);' has to be right in front of the 'return;'.
GamesGrinder1998 GamesGrinder1998

2014/4/22

#
Super_Hippo wrote...
Put that 'int halfWorldWidth = world.getWidth()/2;' where it was before. danpost only wrote the wrong line number. It was at the correct position. Only the 'world.removeObject(this);' has to be right in front of the 'return;'.
thankyou it works now
GamesGrinder1998 GamesGrinder1998

2014/4/24

#
Super_Hippo wrote...
Put that 'int halfWorldWidth = world.getWidth()/2;' where it was before. danpost only wrote the wrong line number. It was at the correct position. Only the 'world.removeObject(this);' has to be right in front of the 'return;'.
why isn't my other starfighter 1 not working in multiplayer mode, here is the code for the other fireball...
import greenfoot.*;  

public class Fireball2 extends Actor
{
    private int direction, speed;

    public Fireball2(int dir)
    {
        direction = 270;
        speed = 7;
    }

    public void act() 
    {
        setRotation(direction);
        move(speed);
        disappear();
    }    

    public void disappear()
    {
        Actor BugEnemy;
        BugEnemy = getOneObjectAtOffset(0, 0, BugEnemy.class);
        Actor InsectEnemy;
        InsectEnemy = getOneObjectAtOffset(0, 0, InsectEnemy.class);
        Actor Bee;
        Bee = getOneObjectAtOffset(0, 0, Bee.class);
        Actor DarkPower;
        DarkPower = getOneObjectAtOffset(0, 0, DarkPower.class);
        if (BugEnemy != null)
        {
            World world;
            world = getWorld();
            world.removeObject(BugEnemy);
            MyGame2 mygame2 = (MyGame2)world;
            Counter counter = mygame2.getCounter();
            counter.addScore();
            int halfWorldWidth = world.getWidth()/2;  
            int x = Greenfoot.getRandomNumber(halfWorldWidth);  
            if (getX() >= halfWorldWidth) x += halfWorldWidth;  
            BugEnemy.setLocation(x, Greenfoot.getRandomNumber(world.getHeight()));  
            world.removeObject(this);
            return;
        }    

        if (InsectEnemy != null)
        {
            World world;
            world = getWorld();
            world.removeObject(InsectEnemy);
            MyGame2 mygame2 = (MyGame2)world;
            Counter counter = mygame2.getCounter();
            counter.addScore();
            int halfWorldWidth = world.getWidth()/2;  
            int x = Greenfoot.getRandomNumber(halfWorldWidth);  
            if (getX() >= halfWorldWidth) x += halfWorldWidth;  
            InsectEnemy.setLocation(x, Greenfoot.getRandomNumber(world.getHeight()));  
            world.removeObject(this);
            return;
        } 
       
        if (Bee != null)
        {
            World world;
            world = getWorld();
            world.removeObject(Bee);
            MyGame2 mygame2 = (MyGame2)world;
            Counter counter = mygame2.getCounter();
            counter.addScore();
            int halfWorldWidth = world.getWidth()/2;  
            int x = Greenfoot.getRandomNumber(halfWorldWidth);  
            if (getX() >= halfWorldWidth) x += halfWorldWidth;  
            Bee.setLocation(x, Greenfoot.getRandomNumber(world.getHeight()));  
            world.removeObject(this);
            return;
        } 
        
        if (DarkPower != null)
        {
            World world;
            world = getWorld();
            world.removeObject(DarkPower);
            world.removeObject(this);
            return;
        } else {
            if (getY()<=0)
            {
                getWorld().removeObject(this);
                return;
            } 
        }
    }   
}    
Super_Hippo Super_Hippo

2014/4/24

#
What excatly isn't working?
GamesGrinder1998 GamesGrinder1998

2014/4/25

#
Super_Hippo wrote...
What excatly isn't working?
the enemy isn't respawning in the players 1 box
danpost danpost

2014/4/26

#
Which class of Actor is this enemy that isn't respawning in the players 1 box ? and, is it not spawning at all or spawning in the players 2 box?
GamesGrinder1998 GamesGrinder1998

2014/4/26

#
danpost wrote...
Which class of Actor is this enemy that isn't respawning in the players 1 box ? and, is it not spawning at all or spawning in the players 2 box?
it's spawning in the players 2 box when my starfighter 2 shoots an enemy but when my starfighter1 shoots it, it doesn't respawn
You need to login to post a reply.
6
7
8
9