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

2020/6/14

Trying to spawn actors at different times

1
2
3
4
kirajim kirajim

2020/6/17

#
I encountered a new problem every time i put the "if (isTouching(Coin.class)) removeTouching(Coin.class);" code the coins stop appearing. I think it is because i placed the coins in the same column as the bird. But thats how its suppose to be so the bird can be able to collect them, is there a way where i can make the coins appear in the same column as the bird without them disappering unless i make the bird touch them.
kirajim kirajim

2020/6/17

#
I just tried even when i change where the coins appear they are disappeared until i take out the bird. So i am not sure why thats happening do you think there is a solution
danpost danpost

2020/6/17

#
kirajim wrote...
I just tried even when i change where the coins appear they are disappeared until i take out the bird. So i am not sure why thats happening do you think there is a solution
Of course. Show your bird class codes.
kirajim kirajim

2020/6/17

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * Write a description of class FlappyBird here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class FlappyBird extends Actor
{
    double dy = 0;
    double g = 1.3;
    double BOOST_SPEED = -6.5;
    /*public FlappyBird(){
     GreenfootImage image = getImage();  
     image.scale(100, 100);
     setImage(image);
    }*/
   
    /**
     * Act - do whatever the FlappyBird wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        
        setLocation( getX(), (int) (getY() + dy) );
       
        // If we are touching a pipe, then Game Over!
        if (getOneIntersectingObject(bottom_pipe.class)!= null) {
            displayGameOver();
        }
        if (getOneIntersectingObject (top_pipe.class)!= null) {
            displayGameOver();
        }
        if (getOneIntersectingObject(Coin.class)!= null) {
            removeTouching(Coin.class);
        }
       
       // If used presses up arrows, launch Flappy Bird upward
        if (Greenfoot.isKeyDown("up") == true) {
           dy = BOOST_SPEED;
           Greenfoot.playSound("sfx_wing.wav");
        }
    
       
        // If FlappyBird drops out of the world, Game over!
        if (getY() > getWorld().getHeight())  {  
          displayGameOver();  
        }
       
        dy = dy + g;
        
        
       
    }  
    
    
    
    private void displayGameOver() {
        GameOver gameOver = new GameOver();
        getWorld().addObject(gameOver, getWorld().getWidth()/2, getWorld().getHeight()/2);
        Greenfoot.stop();
    }
    
}
danpost danpost

2020/6/17

#
Oh, sorry. I assumed the problem was there as you said the coins disappeared until the bird is taken out. However, I do not see the problem here. Show current world and coin classes.
kirajim kirajim

2020/6/17

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.ArrayList;
/**
 * Write a description of class Flappy_Bird_Background here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class FlappyWorld extends World
{
    int counter = 0;
    boolean hasPrinted = false;
    int pipeCounter = 0;
    int FIRST_PIPE = 240;
    int PIPE_SPACE = 60;
    int NextLevel = 0;
    int LevelUp = 10;
    int WhenToLevelUp = 9;
    int RN = 0;
    private int spawnTimer;
    Score scoreObj = null;
    Coin[] coins;

    ArrayList<top_pipe> topPipes = new ArrayList<>();
    /**
     * Constructor for objects of class FlappyWorld.
     *
     */
    public FlappyWorld()        
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1, false);
       
        // Create a Flappy bird object
        FlappyBird flappy = new FlappyBird();
       
        // Add flappy to our world
        addObject(flappy, 100, getHeight()/2);
       
        // set paint order
        setPaintOrder(Score.class, bottom_pipe. class, top_pipe.class);
       
        // Create a Score object
        scoreObj = new Score();
       
        // Add Score to Flappy_Bird_Background
        addObject(scoreObj, 100, 100);
        prepare();
    }
 
    public void act() {
        checkForSpawning();
        for (top_pipe pipe : topPipes)
        {
            if (pipe.addscore)
               {
                   scoreObj.scoreUp();
                   pipe.addscore = false;
               }
        }
        if (scoreObj.score == 0 && hasPrinted == false) {
            System.out.println("Can you be named the Flappy Bird LEGEND?");
            hasPrinted = true;
        }
        if (scoreObj.score == 10 && hasPrinted == true) {
            System.out.println("Good Job!");
            displayLevelCompleted();
            hasPrinted = false;
        }
        if (scoreObj.score >= WhenToLevelUp) {
            PIPE_SPACE = 70;
        }
           
        if (scoreObj.score == 20 && hasPrinted == false) {
            System.out.println("So Far So Good!");
            displayLevelCompleted();
            hasPrinted = true;
        }
        if (scoreObj.score >= WhenToLevelUp + 10) {
            PIPE_SPACE = 80;
        }
           
        if (scoreObj.score == 30 && hasPrinted == true) {
            System.out.println("Are you the Flappy Bird GOAT?");
            displayLevelCompleted();
            hasPrinted = false;
        }
        if (scoreObj.score >= WhenToLevelUp + 20) {
            PIPE_SPACE = 90;
        }
           
        if (scoreObj.score == 40 && hasPrinted == false){
            System.out.println("Warning: Difficulty HALL OF FAME!");
            displayLevelCompleted();
            hasPrinted = true;
        }
        if (scoreObj.score >= WhenToLevelUp + 30) {
             PIPE_SPACE = 100;
        }
           
        if (scoreObj.score == 50 && hasPrinted == true) {
             System.out.println("Flappy Bird LEGEND!");
             displayLevelCompleted();
             hasPrinted = false;
        }
        if (scoreObj.score >= WhenToLevelUp + 40) {
             PIPE_SPACE = 110;
        }
           
        if (scoreObj.score == 51 && hasPrinted == false) {
             System.out.println("Warning: Level Impossible!");
             displayLevelCompleted();
             hasPrinted = true;
        }
       
        RN = getRandomNumber(50,100);
        pipeCounter++;
       
        if (pipeCounter % RN == 0) {
           // Create a pipe object
           bottom_pipe bpipe = new bottom_pipe();
           
           top_pipe tpipe = new top_pipe();
           
           GreenfootImage bimage = bpipe.getImage();
           GreenfootImage timage = tpipe.getImage();
           
           topPipes.add(tpipe);
           
           
           addObject(bpipe, getWidth(), getHeight()/2 + bimage.getHeight()-PIPE_SPACE);
           addObject(tpipe, getWidth(), getHeight()/2 - timage.getHeight()+PIPE_SPACE);
        }
               
        if (NextLevel == LevelUp) {
            displayLevelCompleted();
            NextLevel = 0;
        }
    }
   
    private void displayLevelCompleted() {
        System.out.println("NEXT LEVEL");
    }
   
    public int getRandomNumber(int start,int end)
    {
       int normal = Greenfoot.getRandomNumber(end-start+1);
       return normal+start;
    }
    
    private void checkForSpawning() // call from act method
{
    spawnTimer = (spawnTimer+1)%50; // repeat every 10 seconds (about)
    if (spawnTimer == 0) // at each timer reset
    {
        addObject(new Coin(), 90, Greenfoot.getRandomNumber(500));
        
    }
}

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
    }

}
kirajim kirajim

2020/6/17

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

/**
 * Write a description of class coin here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Coin extends Actor
{
    GifImage myGif = new GifImage ("coin-clipart-drawn-17.gif");
    
    
    /**
     * Act - do whatever the coin wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setImage( myGif.getCurrentImage());
          getImage().scale(200,200);
         
   
    }  
}
kirajim kirajim

2020/6/17

#
Ya I know its really weird because when i make the bird fly out of the screen frame where it doesnt show the coins start appearing so im guessing the problem is with the bird, but i am not sure why or where exactly
danpost danpost

2020/6/17

#
What is the height of the image of the bird:
System.out.println("Bird image height: "+getImage().getHeight());
(and width)?
kirajim kirajim

2020/6/17

#
i think its (100,100) thats the scale of the bird
kirajim kirajim

2020/6/17

#
the bird is smaller than the coins
kirajim kirajim

2020/6/17

#
height is 24 and width is 34
danpost danpost

2020/6/17

#
What is the largest size (width and height, individually) of a coin image?
kirajim kirajim

2020/6/17

#
All coins are the same size and the width and height are both 200
danpost danpost

2020/6/17

#
kirajim wrote...
All coins are the same size and the width and height are both 200
Isn't that a bit much -- taking up 1/6th the area of the world background? -- and half its height?
There are more replies on the next page.
1
2
3
4