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

2013/12/8

Change the spawn rate of enemies based on players ability and/or score

Sound Sound

2013/12/8

#
Greetings all! As the title says I have a game that is currently going quite well but the only thing I need now is a way to gradually increase the spawn rate of enemies based on either the players ability or their score. Any thoughts? Also I have three enemies that I would like to spawn randomly
danpost danpost

2013/12/8

#
Please show the declarations of the score and abilities of the player; also, any 'get' and 'set' methods for these fields; plus state which class the spawning of enemies is taking place in.
Sound Sound

2013/12/8

#
The score is actually your progress bar. A friend at school told me about it and I implemented it about a week ago. And right now the world currently spawns the enemies.
danpost danpost

2013/12/8

#
danpost wrote...
Please show the declarations of the score and abilities of the player; also, any 'get' and 'set' methods for these fields.
Still!
Sound Sound

2013/12/8

#
Ok sorry about that. Don't know what I was thinking/drinking. for the score I am using the default counter:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
 
/**
 * A Counter class that allows you to display a numerical value on screen.
 *
 * The Counter is an actor, so you will need to create it, and then add it to
 * the world in Greenfoot.  If you keep a reference to the Counter then you
 * can adjust its value.  Here's an example of a world class that
 * displays a counter with the number of act cycles that have occurred:
 *
 * <pre>
 * class CountingWorld
 * {
 *     private Counter actCounter;
 *    
 *     public CountingWorld()
 *     {
 *         super(600, 400, 1);
 *         actCounter = new Counter("Act Cycles: ");
 *         addObject(actCounter, 100, 100);
 *     }
 *    
 *     public void act()
 *     {
 *         actCounter.setValue(actCounter.getValue() + 1);
 *     }
 * }
 * </pre>
 *
 * @author Neil Brown and Michael Kölling
 * @version 1.0
 */
public class Counter extends Actor
{
    private static final Color transparent = new Color(0,0,0,0);
    private GreenfootImage background;
    private int value;
    private int target;
    private String prefix;
     
    public Counter()
    {
        this(new String());
    }
 
    /**
     * Create a new counter, initialised to 0.
     */
    public Counter(String prefix)
    {
        background = getImage();  // get image from class
        value = 0;
        target = 0;
        this.prefix = prefix;
        updateImage();
    }
     
    /**
     * Animate the display to count up (or down) to the current target value.
     */
    public void act()
    {
        if (value < target) {
            value++;
            updateImage();
        }
        else if (value > target) {
            value--;
            updateImage();
        }
    }
 
    /**
     * Add a new score to the current counter value.  This will animate
     * the counter over consecutive frames until it reaches the new value.
     */
    public void add(int score)
    {
        target += score;
    }
     
     
     /**
     * Subtract a new score to the current counter value.  This will animate
     * the counter over consecutive frames until it reaches the new value.
     */
    public void sub(int score)
    {
        target -= score;
    }
 
    /**
     * Return the current counter value.
     */
    public int getValue()
    {
        return target;
    }
 
    /**
     * Set a new counter value.  This will not animate the counter.
     */
    public void setValue(int newValue)
    {
        target = newValue;
        value = newValue;
        updateImage();
    }
     
    /**
     * Sets a text prefix that should be displayed before
     * the counter value (e.g. "Score: ").
     */
    public void setPrefix(String prefix)
    {
        this.prefix = prefix;
        updateImage();
    }
 
    /**
     * Update the image on screen to show the current value.
     */
    private void updateImage()
    {
        GreenfootImage image = new GreenfootImage(background);
        GreenfootImage text = new GreenfootImage(prefix + value, 22, Color.WHITE, transparent);
         
        if (text.getWidth() > image.getWidth() - 20)
        {
            image.scale(text.getWidth() + 20, image.getHeight());
        }
         
        image.drawImage(text, (image.getWidth()-text.getWidth())/2,
                        (image.getHeight()-text.getHeight())/2);
        setImage(image);
    }
}
Now that just keeps tallying the score. So basically your score is how long you survive. In my world class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public void act()
    {
        actCounter.setValue(actCounter.getValue() + 1);
         
 
 
        addEnemies(actCounter.getValue()/100);
 
         
         
         
        if (bar.getValue() == bar.getMinimumValue())
        {
            if (getObjects(GameOver.class).isEmpty()) showGameOver();
            Greenfoot.stop();
        }
    }
Right now it obviously spawn 1 enemy(s) for every 100 points which is very hard one it gets to about 6000.
You need to login to post a reply.