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

2017/5/16

Why it didn't remove the Boss1???

Timon Timon

2017/5/16

#
I didn't know why it didn't remove the Boss1 Object. This is the code of the Mans:
import greenfoot.*;
public class Mans extends Actor
{
    public int ySpeed;
    public int groundLevel=489;
    private boolean pressed;
    public void act()
    {
        boolean onGround = false;
        ySpeed++;
        setLocation(getX(), getY()+ySpeed);
        // at ground level
        if (getY() > groundLevel)
        {
            ySpeed = 0;
            setLocation(getX(), groundLevel);
            onGround = true;
        }
        // hitting box
        Actor object = getOneIntersectingObject(Objects.class);
        if (object != null)
        {
            int yDir = (int)Math.signum(ySpeed);
            setLocation(getX(), object.getY()-yDir*((object.getImage().getHeight()+getImage().getHeight())/2+1));
            ySpeed = 0;
            if (yDir > 0) onGround = true;
        }
        // jumping
        if (onGround && Greenfoot.isKeyDown("up"))
        {
            ySpeed = -15;
        }
        // firing weapon       
        if (pressed == Greenfoot.isKeyDown("space"))
        {
            pressed = !pressed;
            if (pressed) getWorld().addObject(new Weapons(), getX()+80, getY()-25); 
        } 
        //die
        if (this.isAtEdge())
        {   this.removeTouching(Objects.class);
            this.setImage("Mans3.png");
            this.setLocation(400, 400);
            Greenfoot.playSound("game-over.wav");
            Greenfoot.stop();
            MyWorld m = (MyWorld) getWorld();
            m.GameOver();
        }
        //get a Coin
        if(this.isTouching(Coin.class))
        {
            this.removeTouching(Coin.class);  
            this.setLocation(400, 350);
            Greenfoot.playSound("pop.wav");
        }
        //start Boss Battle
        if(Greenfoot.isKeyDown("enter"))
        {
            this.removeTouching(Boss1.class);
            MyWorld m = (MyWorld) getWorld();
            m.Bos1();
            
        }
        
        
    }
}

this is the code of myWorld:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


public class MyWorld extends World
{
    int started=0;
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1); 
        prepare();
        spawnObjects();
        spawnBoxes();
 
    }
    
    public void start()
    {

        started=1;
        addObject(new spawner(), 0, 0);
        addObject(new Score(), 400, 100);

    }

    public void Game1()
    {
       
        
        started = 0;
        addObject(new Boss1(), 400, 300);
        
    }

    public void Bos1()
    {
        addObject(new Thief1(), 750, 489); 
        
    }
    
    public void GameOver()
    {
        End end = new End();
        addObject(end,400,250);   

    }

    private void prepare()
    {

        Line line = new Line();
        addObject(line,352,596);
        line.setLocation(352,589);
        Mans mans = new Mans();
        addObject(mans,155,496);
        mans.setLocation(400,489);

    }

    public void spawnObjects()
    {
        addObject(new Toutorial(), 400, 100);
    }
    int x;
    public void spawnBoxes()
    {   
        if (started==1)
        {
            x = Greenfoot.getRandomNumber(30);
            if (x==0)
            {
                addObject(new Boxes(), 550, 550);
                addObject(new Walls(), 650, 532);  
                addObject(new Walls(), 750, 532);
            }
            if (x==1)
            {
                addObject(new Boxes(), 750, 550);
            }
            if (x==2)
            {
                addObject(new Boxes(), 650, 550);
                addObject(new Walls(), 750, 532);
            }
            if (x==3)
            {
                addObject(new BadBoxes(), 750, 550);
            }
            if (x==4)
            {
                addObject(new Boxes(), 550, 550);
                addObject(new BadWalls(), 650, 532);  
                addObject(new BadWalls(), 750, 532);
            }
            if (x==5)
            {
                addObject(new BadBoxes(), 550, 550);
                addObject(new BadWalls(), 650, 532);  
                addObject(new BadWalls(), 750, 532);
            }
            if (x==6)
            {
                addObject(new BadBoxes(), 550, 550);
                addObject(new Walls(), 650, 532);  
                addObject(new Walls(), 750, 532);
            }
            if (x==7)
            {
                addObject(new BadBoxes(), 550, 550);
                addObject(new BadWalls(), 650, 532);  
                addObject(new Walls(), 750, 532);
            }
            if (x==8)
            {
                addObject(new BadBoxes(), 550, 550);
                addObject(new Walls(), 650, 532);  
                addObject(new BadWalls(), 750, 532);
            }
            if (x==9)
            {
                addObject(new Boxes(), 550, 550);
                addObject(new BadWalls(), 650, 532);  
                addObject(new Walls(), 750, 532);
            }
            if (x==10)
            {
                addObject(new Boxes(), 550, 550);
                addObject(new Walls(), 650, 532);  
                addObject(new BadWalls(), 750, 532);
            }
            if (x==11)
            {
                addObject(new BadBoxes(), 650, 550);
                addObject(new BadWalls(), 750, 532);
            }
            if (x==12)
            {
                addObject(new BadBoxes(), 650, 550);
                addObject(new Walls(), 750, 532);
            }
            if (x==13)
            {
                addObject(new Boxes(), 650, 550);
                addObject(new BadWalls(), 750, 532);
            }
            if (x==14)
            {
                addObject(new Boxes(), 650, 550);
                addObject(new Boxes(), 750, 550);
            }
            if (x==15)
            {
                addObject(new BadBoxes(), 650, 550);
                addObject(new BadBoxes(), 750, 550);
            }
            if (x==16)
            {
                addObject(new BadBoxes(), 650, 550);
                addObject(new Boxes(), 750, 550);
            }
            if (x==17)
            {
                addObject(new Boxes(), 650, 550);
                addObject(new BadBoxes(), 750, 550);
            }
            if (x==18)
            {
                addObject(new Coin(), 750, 325);
            }
            if (x==19)
            {
                addObject(new Barrels(), 716,487);
            }
            if (x==20)
            {
                addObject(new Barrels(), 716,487);
                addObject(new Barrels(), 716,319);
            }
            if (x==21)
            {
                addObject(new Barrels(), 714,490);
                addObject(new Barrels(), 586,490);
                addObject(new Barrels(), 619,322);
            }
        }
    }
}
In Boss1 I didn't write anything. The Boss1 is an Object which says "Boss1". Thief1 is the real Boss. Mans is the Person you can move. I hope you can help me.
danpost danpost

2017/5/16

#
The player has to be touching the boss when you press "enter" for the boss to disappear and a thief to appear.
Timon Timon

2017/5/18

#
It is touching it, but it didn't work.
danpost danpost

2017/5/18

#
For starters, change line 57 to this:
if (this.isTouching(Boss1.class) && Greenfoot.isKeyDown("enter"))
Then, indicate what class the Boss1 class extends.
Timon Timon

2017/5/23

#
What do mean??
Super_Hippo Super_Hippo

2017/5/23

#
The Boss1 class code should start with this.
//imports...

public class Boss1 extends ****
The question is what **** is in this case and if it is not Actor, the other ones too, so for example: Actor -- Boss -- -- Boss1
Timon Timon

2017/5/24

#
They are both Actors.
danpost danpost

2017/5/24

#
I do not see where two methods are called from -- the 'start' method and the 'Game1' method (both in the MyWorld class). Please enlighten me.
Timon Timon

2017/6/1

#
Ou. ok .sorry
Timon Timon

2017/6/1

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


public class Score extends Actor
{
    /**
     * Act - do whatever the Score wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        this.countScore();
    } 
    public int score=0;
    public int start=1;
     public void countScore()
    {
        if (start==1)
        {
           score++;
        }
        setImage(new GreenfootImage("Score: " + score, 48, Color.WHITE, Color.BLACK));
        if(score==2000)
        {
            MyWorld m = (MyWorld) getWorld();
            m.Game1();
            start=0;
        }
    }
}
This is my score code.
Timon Timon

2017/6/1

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Toutorial here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Toutorial extends Actor
{
    /**
     * Act - do whatever the Toutorial wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        MyWorld m = (MyWorld) getWorld();
        this.setImage("Text4.png");
        if (Greenfoot.isKeyDown("up"))
        {
            getWorld().removeObject(this);
            m.start();
        }
    }  

}
This is my Toutorial code
danpost danpost

2017/6/1

#
The problem is that you are continuously replacing the Boss1 object into the world. Change line 23 in the Score class to this:
if (start == 1 && score == 2000)
to have only one spawn after the score stops at 2000.
Timon Timon

2017/6/4

#
ou.ok. Thank you very much;)
You need to login to post a reply.