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

2019/1/10

Health Doesnt Go Down Decrease The Number

ErnieBoi ErnieBoi

2019/1/10

#

Health doesnt go down when monster touch champion man battle boi

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

/**
 * Generates the actual game.
 * 
 * @author () 
 * @version (v.1.0)
 */
public class PlayArea extends World
{
    Counter counter;
    Score score;
    // Gets music to play
    //GreenfootSound backgroundMusic = new GreenfootSound("untitled.mp3");
    /**
     * Constructor for objects of class PlayArea.
     * 
     */
    public PlayArea()
    {    
        // Create a new world with 800x800 cells with a cell size of 1x1 pixels.
        super(600, 600, 1);
        // Plays music
        //backgroundMusic.playLoop();
        prepare();
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        Champion champion = new Champion();
        addObject(champion,308,313);
        Klorb klorb = new Klorb();
        addObject(klorb,75,55);
        Klorb klorb2 = new Klorb();
        addObject(klorb2,478,107);

        klorb2.setLocation(530,94);

        klorb2.setLocation(557,562);
        klorb2.setLocation(758,759);

        Blerko blerko = new Blerko();
        addObject(blerko,60,759);
        Blerko blerko2 = new Blerko();
        addObject(blerko2,748,69);
        blerko2.setLocation(751,54);
        klorb.setLocation(56,45);
        counter = new Counter();
        addObject(counter,330,17);
        counter.sethealth(100);
        score = new Score();
        addObject(score,432,21);
        score.setLocation(428,18);

        blerko2.setLocation(549,58);
        counter.setLocation(230,16);
        score.setLocation(321,15);
        score.setLocation(329,15);
        counter.setLocation(238,15);
        klorb2.setLocation(568,569);
        blerko.setLocation(32,570);
        klorb.setLocation(30,28);
        blerko2.setLocation(567,30);
        champion.setLocation(301,306);
        blerko.setLocation(136,427);
        blerko2.setLocation(508,113);
        klorb2.setLocation(447,275);
        klorb.setLocation(161,114);
        klorb.setLocation(121,163);
        blerko2.setLocation(521,145);
        klorb2.setLocation(492,384);
        blerko.setLocation(124,441);
        Blerko blerko3 = new Blerko();
        addObject(blerko3,358,530);
        Klorb klorb3 = new Klorb();
        addObject(klorb3,324,157);
        removeObject(blerko3);
        removeObject(klorb3);
        klorb.setLocation(30,25);
        blerko2.setLocation(577,24);
        klorb2.setLocation(577,575);
        blerko.setLocation(24,580);

        addObject(klorb,578,297);

        addObject(blerko,26,324);
        Klorb klorb4 = new Klorb();
        addObject(klorb4,580,283);
        Blerko blerko4 = new Blerko();
        addObject(blerko4,32,290);

        addObject(klorb,305,580);

        addObject(blerko,286,41);
        blerko.setLocation(286,49);
        Blerko blerko5 = new Blerko();
        addObject(blerko5,32,577);
        Klorb klorb5 = new Klorb();
        addObject(klorb5,303,576);
        Klorb klorb6 = new Klorb();
        addObject(klorb6,29,454);
        Klorb klorb7 = new Klorb();
        addObject(klorb7,578,148);
        Blerko blerko6 = new Blerko();
        addObject(blerko6,580,447);
        Blerko blerko7 = new Blerko();
        addObject(blerko7,27,152);

        removeObject(klorb5);
        removeObject(blerko5);
        removeObject(klorb6);
        removeObject(blerko4);
        removeObject(blerko7);
        removeObject(klorb);
        removeObject(blerko);
        removeObject(blerko2);
        removeObject(klorb7);
        removeObject(klorb4);

        removeObject(blerko6);
        removeObject(klorb2);
        champion.setLocation(50,557);
        BossMan bossman = new BossMan();
        addObject(bossman,462,182);
        removeObject(bossman);
        Klorb klorb8 = new Klorb();
        addObject(klorb8,48,65);
        Klorb klorb9 = new Klorb();
        addObject(klorb9,54,216);
        Klorb klorb10 = new Klorb();
        addObject(klorb10,55,423);
        Klorb klorb11 = new Klorb();
        addObject(klorb11,573,512);
        Klorb klorb12 = new Klorb();
        addObject(klorb12,577,300);
        Klorb klorb13 = new Klorb();
        addObject(klorb13,576,111);
        Blerko blerko8 = new Blerko();
        addObject(blerko8,138,40);
        Blerko blerko9 = new Blerko();
        addObject(blerko9,494,34);
        Blerko blerko10 = new Blerko();
        addObject(blerko10,487,569);
        Blerko blerko11 = new Blerko();
        addObject(blerko11,166,576);
        champion.setLocation(300,293);
        removeObject(counter);
        Counter counter2 = new Counter();
        addObject(counter2,240,17);
        counter2.setLocation(240,15);
        removeObject(counter2);
        Counter counter3 = new Counter();
        addObject(counter3,242,16);
    }

    public void removeHealth()//this is used to remove health 
    {
        counter.add(-2);

    }


    public int getHealth()//this allows classes get 
    {
        int x = counter.gethealth();
        return x;
    }

    public void addScore()
    {
        score.add(2); 
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Movers here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Movers extends Actor
{
    /**
     * Test if we are close to one of the edges of the world. Return true is we are.
     */
    public boolean atWorldEdge()
    {
        if(getX() < 10 || getX() > getWorld().getWidth() - 10)
            return true;
        if(getY() < 10 || getY() > getWorld().getHeight() - 10)
            return true;
        else
            return false;
    }

    /**
     * Return true if we can see an object of class 'clss' right where we are. 
     * False if there is no such object here.
     */
    public boolean canSee(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        return actor != null;        
    }

    /**
     * Try to eat an object of class 'clss'. This is only successful if there
     * is such an object where we currently are. Otherwise this method does
     * nothing.
     */
    public void eat(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        if(actor != null) {
            getWorld().removeObject(actor);
        }
    }

    public void deadChampion()
    {
        if (this.getWorld() != null && this.getWorld().getClass() == PlayArea.class)
        {
            PlayArea world = getWorldOfType(PlayArea.class);
            if(world.getHealth()<=0)
            {
                getWorld().removeObject(this);
                Greenfoot.setWorld(new GameOver());
            }
        }
    }

    public void deadChampion2()
    {
        if (this.getWorld() != null && this.getWorld().getClass() == BossBattle.class)
        {
            BossBattle world = getWorldOfType(BossBattle.class);
            if(world.getHealth()<=0)
            {
                getWorld().removeObject(this);
                Greenfoot.setWorld(new GameOver());
            }
        }
    }

    public void removeHealth()
    {
        if (this.getWorld().getClass() == PlayArea.class)
        {
            if(this.isTouching(Monsters.class))
            {
                PlayArea world = getWorldOfType(PlayArea.class);
                world.removeHealth();//removes players health

            }
        }
    }

    public void removeHealth2()
    {
        if (this.getWorld().getClass() == BossBattle.class)
        {
            if(this.canSee(Monsters.class))
            {
                BossBattle world = getWorldOfType(BossBattle.class);
                world.removeHealth2();//removes players health

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

/**
 * Write a description of class Champion here.
 * 
 * 
 * @author 
 * @version v.1.0
 */
public class Champion extends People
{
    public int health = 100;
    int x;
    int y;
    int firecount;

    public void act()
    {
        checkKeys();
        firecount++;
        if(firecount > 5)
            if(Greenfoot.isKeyDown("space"))
            {
                getWorld().addObject(new Bullet(getRotation()), getX(), getY());
                firecount = 4;
            }
        removeHealth();
        removeHealth2();
        deadChampion();
        deadChampion2();

    }

    /**
     * Check whether the control keys are being pressed, and turn
     * if they are.
     */
    public void checkKeys()
    {
        //these events make this program an event driven application.
        if ( Greenfoot.isKeyDown("up") )//trigger function
        {
            move(8);//event handler
        }
        if ( Greenfoot.isKeyDown("down") )//trigger function
        {
            move(-5);//event handler
        }
        if ( Greenfoot.isKeyDown("left") )//trigger function
        {
            turn(-5);//event handler
        }
        if ( Greenfoot.isKeyDown("right") )//trigger function
        {
            turn(5);//event handler
        }
    }

    
}
danpost danpost

2019/1/10

#
ErnieBoi wrote...
Health doesnt go down when monster touch champion man battle boi << Code Omitted >>
Try to "Find" the variable name "health" among your classes, where it refers to the health of your champion. Let us know where it is found, anywhere except line 12 in the Champion class.
You need to login to post a reply.