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

2018/11/26

I need to communicate two clases

SuperAmigo300 SuperAmigo300

2018/11/26

#
Hi, I'm doing a Space game, I have basic actors like, the player, player bullets, boss, healthbar and boss bullets. I have health values of the boss in Healthbar class, And I have the phases in the Boss class, I need to communicate the health value to the boss class for doing conditionals to switch between phases.
danpost danpost

2018/11/26

#
SuperAmigo300 wrote...
I have health values of the boss in Healthbar class, And I have the phases in the Boss class, I need to communicate the health value to the boss class for doing conditionals to switch between phases.
We would need to see your world, boss and health bar class codes.
SuperAmigo300 SuperAmigo300

2018/11/26

#
World code
    import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
    
    /**
     * Write a description of class nivel1 here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class nivel1 extends World
    {
        private int BossBulletSpawnTimer;
        HealthBar healthbar = new HealthBar();
        static GreenfootSound musica2 = new GreenfootSound("level1song.mp3");
        /**
         * Constructor for objects of class nivel1.
         * 
         */
        public nivel1()
        {    
            super(208, 272, 1, false); 
            drawMainShip(); 
            BossAppears();
            musica2.play();
            quitarVida();
    }
    
    public HealthBar getHeathBar(){
        return healthbar;
    }
    
    

    public void act(){

            


    }

    public void drawMainShip(){
        playerShip jugador = new playerShip();
        addObject(jugador, getWidth()/2, getHeight()/2+100);
    }
    
    public void BossAppears(){
        BossPro jefe = new BossPro();
        addObject(jefe, getWidth()/2, getHeight()-375);
        jefe.setRotation(90);
        baseBar cose1 = new baseBar();
        addObject(cose1, getWidth()/2, getHeight()/2-110);
        
    }

    public void quitarVida(){
        addObject(healthbar, getWidth()/2, getHeight()/2-110);
    }
    
    
    

 
/*  

        private void runBossBossBulletSpawnTimer()
    {
        BossBulletSpawnTimer = (BossBulletSpawnTimer+1)%150; // adjust '300' as desired
        if (BossBulletSpawnTimer == 0) spawnBossBullets();
    }
 
    private void spawnBossBullets()
    {
        BossPro jefe = new BossPro();
        addObject(jefe, getWidth()/2, getHeight()/2-85);

    }

*/

}
boss
    import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
    
    /**
     * Write a description of class nivel1 here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class nivel1 extends World
    {
        private int BossBulletSpawnTimer;
        HealthBar healthbar = new HealthBar();
        static GreenfootSound musica2 = new GreenfootSound("level1song.mp3");
        /**
         * Constructor for objects of class nivel1.
         * 
         */
        public nivel1()
        {    
            super(208, 272, 1, false); 
            drawMainShip(); 
            BossAppears();
            musica2.play();
            quitarVida();
    }
    
    public HealthBar getHeathBar(){
        return healthbar;
    }
    
    

    public void act(){

            


    }

    public void drawMainShip(){
        playerShip jugador = new playerShip();
        addObject(jugador, getWidth()/2, getHeight()/2+100);
    }
    
    public void BossAppears(){
        BossPro jefe = new BossPro();
        addObject(jefe, getWidth()/2, getHeight()-375);
        jefe.setRotation(90);
        baseBar cose1 = new baseBar();
        addObject(cose1, getWidth()/2, getHeight()/2-110);
        
    }

    public void quitarVida(){
        addObject(healthbar, getWidth()/2, getHeight()/2-110);
    }
    
    
    

 
/*  

        private void runBossBossBulletSpawnTimer()
    {
        BossBulletSpawnTimer = (BossBulletSpawnTimer+1)%150; // adjust '300' as desired
        if (BossBulletSpawnTimer == 0) spawnBossBullets();
    }
 
    private void spawnBossBullets()
    {
        BossPro jefe = new BossPro();
        addObject(jefe, getWidth()/2, getHeight()/2-85);

    }

*/

}
Healthbar
 import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and Mou seInfo)

/**
 * Write a description of class HealthBar here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class HealthBar extends actores
{

    int health = 4000;
    int healthBarWidth = 160;
    int healthBarHeight = 3;
    int healthPointsPerPixel = health/healthBarWidth;
    
    /**
     * Act - do whatever the HealthBar wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */

    
    
    
    
    
    
    
    public HealthBar(){
        health = 4000;
        update();
    }

    public int getHealth() {
        return health;
    }

    public void setHealth(int health) {
        this.health = health;
    }

    public void act()
    {
        update();
        
    }
    
    
    
    
    
    
    
    
    
    public void update(){
        
        setImage(new GreenfootImage(healthBarWidth, healthBarHeight));
        GreenfootImage healthbarim = getImage();
        healthbarim.setColor(Color.RED);    
        healthbarim.fillRect(0, 0, health / healthPointsPerPixel, healthBarHeight);
    }
    
    public void loseHealth(){
        health -=1;
    }
    

    
}
SuperAmigo300 SuperAmigo300

2018/11/26

#
danpost wrote...
SuperAmigo300 wrote...
I have health values of the boss in Healthbar class, And I have the phases in the Boss class, I need to communicate the health value to the boss class for doing conditionals to switch between phases.
We would need to see your world, boss and health bar class codes.
The codes are above.
danpost danpost

2018/11/26

#
SuperAmigo300 wrote...
The codes are above.
You gave your world class codes twice and omitted your Boss class codes.
You need to login to post a reply.