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

2018/5/15

raising speed by score

intanmuliawati intanmuliawati

2018/5/15

#
I have a counter class to calculate the score. How to increase the number of enemy when the score reaches a multiple of 15?
public class counter extends Actor
{
    public int total = 0;
    public counter() 
    {
        setImage(new GreenfootImage("SCORE = 0",20,Color.GREEN,Color.WHITE));
    }    
    
    public int Count(int amount)
    {
    total+=amount;
    setImage(new GreenfootImage("SCORE = "+total,20,Color.GREEN,Color.WHITE));
    return total;
    }
  
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class Taman extends World
{
    int enemyCount = 0,coinCount = 0;
    counter count = new counter();
    Human human = new Human();
    Live[] liveArray ={new Live(),new Live(),new Live()};
    int i=0,n=0;
    public Taman()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(700, 495, 1);
        addObject(new Tali2(),335,getHeight()-195);
        addObject(human,335,getHeight()-125);
        setPaintOrder(Tali.class,Human.class);
        addObject(new count(),57,30);
        addObject (count,53,33);
        addObject(new teman2(),488,298);
        addObject(new teman1(),167,304);
       
        for (int i = 0; i< 3; i++)
        {
            addObject(liveArray[i],(550+(57*i)), 43);
        }
        
    }
    
    
    public void act(){
        enemyCount++;
        coinCount++;
        if(enemyCount>150){
            getEnemy();
            enemyCount=0;
        }
        if(coinCount>200){
            getCoin();
            coinCount=0;
        }
            
       }
   
    public void getEnemy(){
        
        addObject(new daun(),200+Greenfoot.getRandomNumber(300),0);
       
    }
    public void getCoin(){
        
        addObject(new coin(),200+Greenfoot.getRandomNumber(300),0);
       
    }
   

    public int getCounter(int i)
    {
        int n =count.Count(i);
        return n;
        
    }
    
    public void getTouch(){
        human.touch();
    }
    
    public void removeLive(int r){
        removeObject(liveArray[i]);
        i=i+r;
        if(i==3){
        Greenfoot.stop();
        gameover gm = new gameover();
        Greenfoot.delay(12);
        addObject(gm,350,250);
        setPaintOrder(gameover.class,Human.class);
        }
    }

   
    
    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        Live live = new Live();
        addObject(live,666,41);
        Live live2 = new Live();
        addObject(live2,611,47);
        live2.setLocation(607,43);
        Live live3 = new Live();
        addObject(live3,554,52);
        live3.setLocation(550,43);
    }
}
danpost danpost

2018/5/15

#
intanmuliawati wrote...
I have a counter class to calculate the score. How to increase the number of enemy when the score reaches a multiple of 15?
Currently, you are creating an enemy after every 150 act steps. To increase the spawn rate, you would lower that number. If the score is to be what determines how much to lower that number, then you would need to subtract some expression of the score from it. You would need to consider what multiple of (score/15) to lessen it by. What value you choose will effect the game duration as well as what possible maximum score may be achieved.
You need to login to post a reply.