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

2015/10/27

How can I stop the bird from falling

1
2
3
4
sanderbakker sanderbakker

2015/11/4

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.*;
import java.util.List;
/**
 * Write a description of class Ball here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bird extends Animate
{
    private static GreenfootImage[] images =
    {
        new GreenfootImage("redBird.png"),
        new GreenfootImage("greenBird.png"),
        new GreenfootImage("orangeBird.png"),
        new GreenfootImage("blueBird.png"),
        new GreenfootImage("blackBird.png"),
        new GreenfootImage("yellowbird.png"),
        new GreenfootImage("chuck.png"),
      
    };
    
    
    
    float velocityY = 0;
    float velocityX = 0;
    float speed = 0;
    boolean roll = false;
    Bird bird;
    int counter = 0;
    /**
     * Act - do whatever the RedBird wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (!active && getX() == 157 && getY() == 365) active = true;
        if (!active) return;
        {
            velocityY += .1;
            speed += .1;
        }
        if(getY() >= 377)
            velocityX = velocityX*.9f;
        if(getY() <= 470&&roll == false){
            
            setLocation(getX()+(int)Math.round(velocityX),getY()+(int)Math.round(velocityY));
            impartForce();
        }
        // bepaald de start positie van het afschieten en tot hoe laag de vogel kan gaan op de Y-as - Sander
        if(roll = true){
            setLocation(getX() + (int)Math.round(velocityX),getY());
            impartForce();
            
        }
        // bepaald tot hoelaag de vogel kan zakken op de Y-as , 470 in dit geval, dit is ook de start positie van de vogel ( geen idee waarom) - Sander 
        
        checkBottom();
        counter++;
        removeRedBird();
       
    }  
    public void removeRedBird()
       {
           if (counter == 350) 
            {
       getWorld().removeObject(this);
    }}
    private boolean active;
    private static int birdNumber;
    public Bird()
    {
        setImage(images[birdNumber]);
        birdNumber = (birdNumber+1)%images.length;
        
      
        
   
        // maakt de afbeelding van de rode vogel 75 keer zo klein - Sander
        
        
        turn(-12);
        
        // draait de vogel met -12 graden - Sander
        
       
       
      
    }
    public void checkBottom()
    {
        List<Block> targets = getIntersectingObjects(Block.class);
        boolean verdict = false;
        for(int i = 0;i<targets.size();i++){
            if(getY() < targets.get(i).getY()-9&&getX() > targets.get(i).getX()+9)
            {
                verdict = true;
            }
        // bepaald hoelang de vogel in de lucht blijft & bepaald wat het doel is van de vogel - Sander
        }
        if(verdict == true)
        {
            roll = true;
        }
        else roll = false;
    }
    public void impartForce()
    {
        List<Animate> targets = getIntersectingObjects(Animate.class);
        for(int i = 0;i<targets.size();i++){
           
            {
                float whatever =  (targets.get(i)).getX()/(targets.get(i)).getY();
                float newX = velocityX*Math.abs(1-whatever/(velocityX/velocityY));
                float newY = velocityY*Math.abs(1-whatever/(velocityX/velocityY));
                (targets.get(i)).transferVelocity(velocityX/2, 0);
                velocityY = velocityY;//-newY;
                velocityX = velocityX/2;//2-newX;
            }
        }
        // zorgt dat de blokken als target gezien worden, waardoor de vogel niet letterlijk door de blokken heen vliegt - Sander 
    }
}
You also told me to add active states for the quence behind the catapult but this doesn't work. Can you help me fix this? because this is very annoying. Thank you for helping me
danpost danpost

2015/11/4

#
sanderbakker wrote...
< Code Omitted > i've made this to move to the next level but it says that int can not be converted to bolean. What can I do about this
You can remove lines 6 through 8. You can also remove line 4. The counting should be done in the World subclass after the actor is removed. No counting can be done in the class of the removed object as the act method will no longer be called for an actor that is not in the world. For the queue, what code do you have for moving the actors along it? (this should also be coded in the world class). You can probably use the number of Bird objects in the world to determine when to move them along the queue and also when to move to the next level. In the Bird class, you may be able to just use the x-coordinate of the location of a bird to determine when it can be catapulted or not.
sanderbakker sanderbakker

2015/11/5

#
import greenfoot.*;
import java.awt.Color;
/**
 * Write a description of class Level1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Level1 extends World
{
    Bird bird;
    Block block;
    Pig pig; 
    Ground1 ground1;
    
    /**
     * Constructor for objects of class Level1.
     * 
     */
    public Level1()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(950, 600, 1); 
        
        addObject(new TNT(),170,464);
        addObject(new Katapult(),161,406);
        addObject(new Bird(), 30,470);
        addObject(new Bird(), 80,470);
        bird = new Bird();
        addObject(bird, 120,470);
        block = new Block();
        addObject(block, 600,475);
        block = new Block();
        addObject(block, 627,475);
        block = new Block();
        addObject(block, 654,475);
        block = new Block();
        addObject(block, 681,475);
        block = new Block();
        addObject(block, 708,475);
        block = new Block();
        addObject(block, 735,475);
        block = new Block();
        addObject(block, 762,475);
        block = new Block();
        addObject(block, 789,475);
        block = new Block();
        addObject(block, 816,475);
        block = new Block();
        addObject(block, 843,475);
        block = new Block();
        addObject(block, 870,475);
        block = new Block();
        addObject(block, 627,448);
        block = new Block();
        addObject(block, 654,448);
        block = new Block();
        addObject(block, 681,448);
        block = new Block();
        addObject(block, 708,448);
        block = new Block();
        addObject(block, 735,448);
        block = new Block();
        addObject(block, 762,448);
        block = new Block();
        addObject(block, 789,448);
        block = new Block();
        addObject(block, 816,448);
        block = new Block();
        addObject(block, 843,448);
        block = new Block();
        addObject(block, 654,421);
        block = new Block();
        addObject(block, 681,421);
        block = new Block();
        addObject(block, 708,421);
        block = new Block();
        addObject(block, 735,421);
        block = new Block();
        addObject(block, 762,421);
        block = new Block();
        addObject(block, 789,421);
        block = new Block();
        addObject(block, 816,421);
        block = new Block();
        addObject(block, 681,394);
        block = new Block();
        addObject(block, 708,394);
        block = new Block();
        addObject(block, 735,394);
        block = new Block();
        addObject(block, 762,394);
        block = new Block();
        addObject(block, 789,394);
        
        block = new Block();
        addObject(block, 708,367);
        block = new Block();
        addObject(block, 735,367);
        block = new Block();
        addObject(block, 762,367);
        block = new Block();
        addObject(block, 735,340);
        pig = new Pig();
        addObject(pig, 735,301); 
        ground1 = new Ground1();
        addObject(ground1, 729,495);
       
       
    }
    
    public void act ()
    {
    if(Greenfoot.mouseClicked(null)){
            MouseInfo mouse = Greenfoot.getMouseInfo();
            if(mouse.getButton() <2)
            {
                removeObject(bird);
                bird = new Bird();
                addObject(bird,157,365);
                if(365-mouse.getY() > -150)
                    bird.velocityY = (365-mouse.getY())/10;
                else
                    bird.velocityY = -5;
                if(157-mouse.getX() < 125)
                    bird.velocityX = (157-mouse.getX())/10;
                else
                    bird.velocityX = 10;
                }   
       }
        
        
        // Laat de vogel vanaf een bepaald x en y punt starten, en laat de vogel tot een bepaald punt vliegen, hoe lager de waarde hoe minder ver de vogel komt - Sander
    
    }
}
This si the code for my world for now.
sanderbakker sanderbakker

2015/11/5

#
And it is still not working I really don't know what to do
danpost danpost

2015/11/6

#
I only see code in your world class act method to initiate a shot of one bird in the queue. There does not appear to be any to move the others up in the queue. If you want help with that, explain what actions they should take and when and show your attempted code.
sanderbakker sanderbakker

2015/11/6

#
I want the world to detect the birds which are standing behind the catapult. Then after the first bird is shooted i want the world to remove it after a few second and the shoot the next bird in line. So after 3 times of shooting there is no bird left behind the catapult
danpost danpost

2015/11/6

#
sanderbakker wrote...
I want the world to detect the birds which are standing behind the catapult. Then after the first bird is shooted i want the world to remove it after a few second and the shoot the next bird in line. So after 3 times of shooting there is no bird left behind the catapult
Again, the birds can remove themselves from the world; the world can check for changing levels. Of the other parts, which one are you currently having problems with and what have you tried? You need to be specific and work on one detail at a time.
sanderbakker sanderbakker

2015/11/6

#
I have tried nothing because I don't know where to start. I have a made a code which removes the bird after a few seconds after it is shooted. That is what I have for now. After this happend I want to shoot the next bird. Is this specific enough?
danpost danpost

2015/11/6

#
sanderbakker wrote...
After this happend I want to shoot the next bird. Is this specific enough?
Not really. There are steps involved between the removal of one bird and the shooting of the next. How is the next bird in line to behave in getting to the catapult? (it is not spawned at the catapult like the first one was) It could gradually move to the catapult or instantly teleport. Looking at your world class act method, I must ask myself why you are removing the bird and adding a new bird when the mouse is clicked. You should just change the velocity of the one already in the world (the one you are catapulting). Also, there should not be a reference to a specific bird in the world class (your 'bird' field) unless you change it to the next bird as they are removed from the world. I really do not think the field is needed at all. As long as a bird is at the catapult (the location coordinates of the bird at the catapult should be of known values), you should be able to determine when to shot a bird and which bird to shoot (change the velocity of).
sanderbakker sanderbakker

2015/11/6

#
And how do I do this. Because if I change the velocity of the bird the first one in the catapult will move to another location. I remove the bird because I want it to disapear after it is shooted like the real angry birds. Also how do I make a reference to a specific bird within the bird class. Because the only thing changing is the image of the bird.
danpost danpost

2015/11/6

#
If the bird is being shot from the location (120, 470), then the following checks should be performed first: * are there any Bird objects in the world (if not, go to next level or end game) * was the mouse clicked using the left button; and is there a Bird object at the shooting location (at the catapult) If the last set of conditions are found to be true, then:
Bird bird = (Bird)getObjectsAt(120, 470, Bird.class).get(0);
will get a reference to the Bird object being shot.
BearCarlson25 BearCarlson25

2015/11/6

#
this nerd doesn't know anything
sanderbakker sanderbakker

2015/11/7

#
So I need to add that code you gave me in the world.class?
danpost danpost

2015/11/7

#
sanderbakker wrote...
So I need to add that code you gave me in the world.class?
Of course. That is the only place the line will compile in (because it uses the 'getObjectsAt' method of the World class).
sanderbakker sanderbakker

2015/11/7

#
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at Level1.act(Level1.java:132) at greenfoot.core.Simulation.actWorld(Simulation.java:600) at greenfoot.core.Simulation.runOneLoop(Simulation.java:535) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205) I got this error when I add it to the Level1 (world) class
There are more replies on the next page.
1
2
3
4