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

2018/11/30

How do I add a Object (Boss) after a time?

pleasetroll pleasetroll

2018/11/30

#
Hi, I am working on a project in which Mario must collect coins. He can die from goombas and can shoot fireballs. BUT I got a problem... I want to add a Boss (Bowser) after a time to the game!!! HOW can I make this? This is my code for the World:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * The bloodstream is the setting for our White Blood Cell scenario. 
 * It's a place where blood cells, bacteria and viruses float around.
 * 
 * @author Brennan Eppinger
 * @version 10/30/2017
 */
public class Bloodstream extends World
{
    private int score;
    private int time;
    private static final String bgImageName = "background.png";
    private static final double scrollSpeed = 2.5;
    private static final int picWidth = (new GreenfootImage(bgImageName)).getWidth();
    private GreenfootImage bgImage, bgBase;
    private int scrollPosition = 0;
    GreenfootSound bgMusic = new GreenfootSound("ground-music.mp3");
    /**
     * Constructor: Set up the staring objects.
     */
    public Bloodstream()
    {    
        super(780, 360, 1); 
        prepare();
        score = 0;
        time = 7000;
        showScore();
        showTime();
        setBackground(bgImageName);
        bgImage = new GreenfootImage(getBackground());
        bgBase = new GreenfootImage(picWidth, getHeight());
        bgBase.drawImage(bgImage, 0, 0);

        
    }
    public void started()
    {
    bgMusic.playLoop();
    }
    public void stopped()
    {
    bgMusic.pause();
    }
    public void act()
    {
        if (Greenfoot.getRandomNumber(100) < 1)
        {
            addObject(new Coin(), 779, Greenfoot.getRandomNumber(360));
        }
        
          if (Greenfoot.getRandomNumber(1000) < 6)
        {
            addObject(new Virus(), 779, Greenfoot.getRandomNumber(360));
        }
        
          
        
        started();
        countTime ();
        scrollPosition -= scrollSpeed;
        while(scrollSpeed > 0 && scrollPosition < -picWidth) scrollPosition += picWidth;
        while(scrollSpeed < 0 && scrollPosition > 0) scrollPosition -= picWidth;
        paint(scrollPosition);
    }
    private void paint(int position)
    {
        GreenfootImage bg = getBackground();
        bg.drawImage(bgBase, position, 0);
        bg.drawImage(bgImage, position + picWidth, 0);
    }
    public void addScore(int points)
    {
        score = score + points;
        showScore();
        if (score < 0) 
        {
            Greenfoot.playSound("game-over.wav");
            Greenfoot.stop();
        }
    }
    private void showScore()
    {
        showText("Score: " + score, 80, 25);
         score = score + 20;
    }
    private void countTime()
    {
        time--;
        showTime();
        if (time == 0)
        {
            showEndMessage();
            Greenfoot.stop();
        }
         showText("Zeit: " + time, 700, 25);
    }
    
    private void showTime()
    {
        showText("Zeit: " + time, 700, 25);
    }
    private void showEndMessage()
    {
        Greenfoot.playSound("win.mp3");
        showText("Die Zeit ist um!", 390, 150);
        showText("Dein Score: " + score + " points", 390, 170);
    }
    
    private void prepare()
    {
        Mario mario = new Mario();
        addObject(mario, 97, 179);
    }
}
danpost danpost

2018/12/1

#
pleasetroll wrote...
I want to add a Boss (Bowser) after a time to the game!!!
You already have a time field and should not how to add an object into a world and construct a conditional if structure. The only other thing is determining/knowing where to put the code.
pleasetroll pleasetroll

2018/12/2

#
Can you maybe tell me where the mistake is?
danpost danpost

2018/12/2

#
pleasetroll wrote...
Can you maybe tell me where the mistake is?
I did not say there was a mistake. I believe you have yet to add the code for it. Oh, maybe my typo through you. "not", in my last post, should have been "know".
pleasetroll pleasetroll

2018/12/5

#
danpost wrote...
pleasetroll wrote...
Can you maybe tell me where the mistake is?
I did not say there was a mistake. I believe you have yet to add the code for it. Oh, maybe my typo through you. "not", in my last post, should have been "know".
I got it thanks! But I have another Question... How can I make a Healthbar for Bowser (If Mario hits Bowser with a Fireball, he should lose life)?? (Btw. Thank you very much danpost that you are answering!)
danpost danpost

2018/12/5

#
pleasetrollHow can I make a Healthbar for Bowser (If Mario hits Bowser with a Fireball, he should lose life)?[/quote wrote...
What have you tried? Which part of giving Bowser a health bar are you having difficulties with?
pleasetroll pleasetroll

2018/12/5

#
danpost wrote...
pleasetrollHow can I make a Healthbar for Bowser (If Mario hits Bowser with a Fireball, he should lose life)?[/quote wrote...
What have you tried? Which part of giving Bowser a health bar are you having difficulties with?
Oh now I got it again:D But thank you. Another Question: How can Bowser shoot randomly?
danpost danpost

2018/12/5

#
pleasetroll wrote...
How can Bowser shoot randomly?
Generate random numbers for the different states of the shooting process (delay, direction, chance, whatever).
pleasetroll pleasetroll

2018/12/5

#
danpost wrote...
pleasetroll wrote...
How can Bowser shoot randomly?
Generate random numbers for the different states of the shooting process (delay, direction, chance, whatever).
Ok Thank you for your help.
You need to login to post a reply.