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

2019/5/25

Can't work out what number I need to put for the game to detect me touching the right side of the world

AmyIsBadAtCoding AmyIsBadAtCoding

2019/5/25

#
I have no errors or anything, I just can't work out what number I need to put in the code for it to change world when my actor collides into the right side. I need to change '-0' on line 43 to something.
import greenfoot.*;

/**
 * Write a description of class Plane here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Plane extends Actor
{
    /**
     * Act - do whatever the Plane wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     * if (isAtEdge())
    {
        Greenfoot.setWorld(new SkyEnemy()); or Greenfoot.setWorld(new SkyEnemyTwo()); or Greenfoot.setWorld(new SkyEnemyThree());
    }
     */
    
    public Plane()
{
    GreenfootImage image = getImage();
    image.scale(image.getWidth() - 80, image.getHeight() - 80);
    setImage(image);
}
    
    public void act() 
    {
    {
            setRotation(0);
            move(2);
    }    
        if (Greenfoot.isKeyDown("Up"))
    {
            setRotation(-20);
            move(2);
    }
    if (Greenfoot.isKeyDown("Down"))
    {
        setRotation(50);
            move(2);
        }
    if (getY() == getWorld().getHeight()-0)
    {
        if (Greenfoot.getRandomNumber(3)==0)
        {
            Greenfoot.setWorld(new SkyEnemy());
    }
       if (Greenfoot.getRandomNumber(3)==1)
       {
           Greenfoot.setWorld(new SkyEnemyTwo());
        }
        if (Greenfoot.getRandomNumber(3)==2)
        {
            Greenfoot.setWorld(new SkyEnemyThree());
        }
    }
    }
}
Super_Hippo Super_Hippo

2019/5/25

#
You probably want to use the X coordinate and the width of the world instead of the Y coordinate and its height when you want to check if it is at the right side.
AmyIsBadAtCoding AmyIsBadAtCoding

2019/5/25

#
Ahh yes silly me, thanks a bunch
You need to login to post a reply.