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

2021/6/4

how to wai

hackeplayz124 hackeplayz124

2021/6/4

#
hi i want a this command to start after the 2 seconds from when the game starts
 spawnTimer = (spawnTimer+1)%720;
    if (spawnTimer%60 == 0){ thisGame.Score++;}
danpost danpost

2021/6/4

#
Initialize spawnTimer to -121. Change 0 in line 2 to 719.
hackeplayz124 hackeplayz124

2021/6/4

#
you understood me wrong
hackeplayz124 hackeplayz124

2021/6/4

#
spawnTimer = (spawnTimer+1)%720;
   if (spawnTimer%60 == 0){ thisGame.Score++;}
i want this code to start after two seconds so my score will start going up after 2 seconds
hackeplayz124 hackeplayz124

2021/6/4

#
danpost wrote...
Initialize spawnTimer to -121. Change 0 in line 2 to 719.
i also tried that on this but it does not work the score does not go up
danpost danpost

2021/6/4

#
hackeplayz124 wrote...
you understood me wrong
I don't think so. Show your updated attempt at my suggestion (show entire class).
hackeplayz124 hackeplayz124

2021/6/5

#
import greenfoot.*;

/**
 * Write a description of class bird here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class bird extends Actor
{
    /**
     * Act - do whatever the bird wants to do. This method is called whenever
     *the 'Act' or 'Run' button gets pressed in the environment.      
     */
     flappyworld thisGame; 
     private int spawnTimer;
    public void act() 
    {
        jump_and_fall();
        death();
        s_core();
    }    
    void jump_and_fall(){
          if(Greenfoot.isKeyDown("space")){  if (Greenfoot.isKeyDown("space"))setLocation(getX(), getY() -9);
        }
        setLocation(getX(), getY() +5);
    }
    void death(){ if(isAtEdge()){
                               this.getWorld().removeObject(this);       }                           
                  Actor bird = getOneIntersectingObject(bird.class);
    if(bird != null){
    getWorld().removeObject(bird);}
                       
    }

    void s_core(){
        //i want the code bellow to start after 2 seconds 
       
        spawnTimer = (spawnTimer+1)%720;
    if (spawnTimer%60 == 0){ thisGame.Score++;}
    
    
    }



}


hackeplayz124 hackeplayz124

2021/6/5

#
this is the not updated version
hackeplayz124 hackeplayz124

2021/6/5

#
danpost wrote...
Initialize spawnTimer to -121. Change 0 in line 2 to 719.
dont get what you mean by intilze timer and replace the zero i need this code to start after 2 seconds
  //i want the code bellow to start after 2 seconds 
       
        spawnTimer = (spawnTimer+1)%720;
    if (spawnTimer%60 == 0){ thisGame.Score++;}
NRupert NRupert

2021/6/5

#
Hi! If you make another count variable that is active in the act method, it will gain 60 per second. If you make an if statement that it will only code after 120, it should start after 2 seconds. IE: int counter = 0; public void act(){ counter++; if(counter>= 120) { *Your code* } Hope this helped!
danpost danpost

2021/6/5

#
hackeplayz124 wrote...
dont get what you mean by intilze timer
Change line 16 of bird class to:
private int spawnTimer = -121;
replace the zero
Use:
if (spawnTimerr%60 == 50) thisGame.Score++;
I apologize for suggesting 719 before. I see no reason for timer to go to 720 when 60 is sufficient.
hackeplayz124 hackeplayz124

2021/6/5

#
thx for helping me
danpost danpost

2021/6/5

#
hackeplayz124 wrote...
thx for helping me
And then, there are the typos. I meant, use:
if (spawnTimer%60 == 59) thisGame.Score++;
You need to login to post a reply.