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

2017/2/11

@danpost I need help...

Kokoro Kokoro

2017/2/11

#
I use the "Zombie Shooter Demo" So this is my last problem i encouter... if i add things from "Actor" section to the "World" well no more chasers spawn... whole "World" class look like this.. HELP ME
import greenfoot.*;
import java.awt.Color;
import java.awt.Font;

public class Lume1_1 extends Rezolutie_Joc
{
    public static int actionType, actionDistance; // the world bounds action fields for the chasers
    public static Jucator jucator; // the player

    public int score; // the score

    public Lume1_1()
    {

        Greenfoot.setSpeed(60);
        // create background texts
        GreenfootImage bg = getBackground();
        bg.setFont(new Font("SERIF", Font.BOLD, 28));
        bg.setColor(Color.white);
        bg.drawString("Executii:", 1000, 40);
        adjustScore(0);
        bg.setColor(Color.white);
        bg.setFont(new Font("SERIF", Font.BOLD, 32));
        bg.drawString("Lume 1", 50, 700);

        // create player and reset game
        jucator = new Jucator();
        setAction(0);
        prepare();
    }

    public void act()
    {
        // changing edge action
        String key = Greenfoot.getKey();
        if (key != null)
        {
            if ("e".equals(key)) setAction(actionType+1);
            if ("q".equals(key)) Greenfoot.setWorld(new TextFileViewer("QActor.txt", this));
        }
        // adding chasers to world
        // if (chased.getWorld() == null) return;
        if (numberOfObjects() >= 20+score/10) return;
        if (Greenfoot.getRandomNumber(1000) > 30+score/10) return;
        int x = Greenfoot.getRandomNumber(getWidth());
        int y = Greenfoot.getRandomNumber(getHeight());
        int rand = Greenfoot.getRandomNumber(4);
        if (rand < 2) x = (getWidth()-3+actionDistance*2)*rand+1-actionDistance;
        else y = (getHeight()-3+actionDistance*2)*(rand-2)+1-actionDistance;
        // if (Math.abs(x-chased.getX())+Math.abs(y-chased.getY()) < 200) return;
        Indian indian = new Indian();
        addObject(indian, x, y);
        indian.turnTowards(500, 500);

        if (score == 50) Greenfoot.setWorld(new Meniu_Joc());
    }

    public void adjustScore(int adjustment)
    {
        score += adjustment; // adjust score
        // adjust score display
        GreenfootImage bg = getBackground();
        bg.setColor(Color.white);
        bg.fillRect(1110, 15, 100, 30);
        bg.setColor(Color.black);
        bg.setFont(new Font("SERIF", Font.BOLD, 28));
        bg.setColor(Color.black);
        bg.drawString(""+score, 1110, 40);
    }

    private void setAction(int action)
    {
        removeObjects(getObjects(Indian.class)); // remove old chasers
        actionType = action%5; // set bound action
        int[] distances = { 0, 0, -10, 0, -15 }; // bound ranges
        actionDistance = distances[actionType]; // the range for this action

        // reset score
        score = 0;
        // ensure player is in world
        if (jucator.getWorld() == null) addObject(jucator, 600, 300);
    }

    public void getActorCounts()
    {
        java.util.List<Object> objects = getObjects(null);
        int n = 0;
        while (!objects.isEmpty())
        {
            String name = objects.get(n).getClass().getName();
            int count = 1;
            int index = 1;
            while (index < objects.size())
            {
                if (name.equals(objects.get(index).getClass().getName()))
                {
                    count++;
                    objects.remove(index);
                }
                else index++;
            }
            System.out.println(name+": "+count);
            objects.remove(0);
        }
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        cactus cactus = new cactus();
        addObject(cactus,1216,657);
        cactus cactus2 = new cactus();
        addObject(cactus2,678,649);
        cactus cactus3 = new cactus();
        addObject(cactus3,371,624);
        cactus cactus4 = new cactus();
        addObject(cactus4,113,491);
        cactus cactus5 = new cactus();
        addObject(cactus5,12,308);
        cactus cactus6 = new cactus();
        addObject(cactus6,267,66);
        cactus cactus7 = new cactus();
        addObject(cactus7,882,109);
        cactus cactus8 = new cactus();
        addObject(cactus8,1174,228);
        cactus cactus9 = new cactus();
        addObject(cactus9,1260,438);
        cactus cactus10 = new cactus();
        addObject(cactus10,969,522);
        piatra_2 piatra_2 = new piatra_2();
        addObject(piatra_2,1099,284);
        piatra_2 piatra_22 = new piatra_2();
        addObject(piatra_22,968,154);
        piatra_2 piatra_23 = new piatra_2();
        addObject(piatra_23,240,69);
        piatra_2 piatra_24 = new piatra_2();
        addObject(piatra_24,318,373);
        piatra_2 piatra_25 = new piatra_2();
        addObject(piatra_25,355,518);
        piatra_2 piatra_26 = new piatra_2();
        addObject(piatra_26,815,714);
        piatra_2 piatra_27 = new piatra_2();
        addObject(piatra_27,1110,628);
        piatra_2 piatra_28 = new piatra_2();
        addObject(piatra_28,559,534);
        piatra_2 piatra_29 = new piatra_2();
        addObject(piatra_29,100,391);
        piatra_2 piatra_210 = new piatra_2();
        addObject(piatra_210,52,198);
        piatra_1 piatra_1 = new piatra_1();
        addObject(piatra_1,820,132);
        piatra_1 piatra_12 = new piatra_1();
        addObject(piatra_12,443,59);
        piatra_1 piatra_13 = new piatra_1();
        addObject(piatra_13,363,43);
        piatra_1 piatra_14 = new piatra_1();
        addObject(piatra_14,249,456);
        piatra_1 piatra_15 = new piatra_1();
        addObject(piatra_15,233,576);
        piatra_1 piatra_16 = new piatra_1();
        addObject(piatra_16,262,647);
        piatra_1 piatra_17 = new piatra_1();
        addObject(piatra_17,707,703);
        cactus cactus11 = new cactus();
        addObject(cactus11,677,125);
        cactus cactus12 = new cactus();
        addObject(cactus12,360,185);
        cactus cactus13 = new cactus();
        addObject(cactus13,101,114);
        cactus6.setLocation(288,75);
        piatra_23.setLocation(227,145);
        piatra_17.setLocation(708,703);
        piatra_26.setLocation(875,689);
    }
}
danpost danpost

2017/2/11

#
Try changing line 43 to this:
if (getObjects(Chaser.class).size() >= 20+score/10) return;
Kokoro Kokoro

2017/2/11

#
Yeah i manged to noticed that like after i posted this :D However it worked thanks !!
You need to login to post a reply.