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

2020/4/10

how would i create an openable door

1
2
3
4
5
6
danpost danpost

2020/4/27

#
Weeb.exe wrote...
the openable door class is where the door is itself also what would that boolean value be?
The "boolean open' in the door class.
Weeb.exe Weeb.exe

2020/4/27

#
ok
Weeb.exe Weeb.exe

2020/4/27

#
if im being honest i don't really understand this because how would i then able the character to open it because the character would just be able to walk through it and i don't really know how to code it so if i could get a scaffold on it im going to put my code below to show you what i have and if you notice anything that could fix it can you let me know im sorry for being a pain
//in character class
public boolean allowCollision()
    {
        if (isTouching(OpenableDoor.class) && isOpen())
        {
            OpenableDoor door = (OpenableDoor)getOneIntersectingObject(OpenableDoor.class);
            if (door.isOpen())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    

    public boolean DoorClosed()
    {
        if (allowCollision() == false)
        {
            int spriteWidth = getImage().getWidth();
            int xDistance = (int) (spriteWidth/2);

            Actor closeDoor = getOneObjectAtOffset (xDistance, 0, OpenableDoor.class);
            if (closeDoor == null)
            {
                return false;
            }
            else
            {
                stopByOpenableDoor(closeDoor);
                return true;
            }
        }
    }

    public void stopByOpenableDoor(Actor closeDoor)
    {
        int wallWidth = closeDoor.getImage().getWidth();
        int newX = closeDoor.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX , getY());
    }
then my OpenableDoor class
//in OpenableDoor class
private boolean open, eDown;
    /**
     * Act - do whatever the OpenableDoor wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (Greenfoot.isKeyDown("e") != eDown)
        {
            eDown = !eDown;
            if (isTouching(Betty.class) && eDown)
            {
                open = !open;
                setImage(open ? "OpenableDoor1.png" : "OpenableDoor2.png");
            }
        }
        if (Greenfoot.isKeyDown("e") != eDown)
        {
            eDown = !eDown;
            if (isTouching(BillyMetal.class) && eDown)
            {
                open = !open;
                setImage(open ? "OpenableDoor1.png" : "OpenableDoor2.png");
            }
        }
        if (Greenfoot.isKeyDown("e") != eDown)
        {
            eDown = !eDown;
            if (isTouching(Billy.class) && eDown)
            {
                open = !open;
                setImage(open ? "OpenableDoor1.png" : "OpenableDoor2.png");
            }
        }
    }

    public boolean isOpen()
    {
        return open;
    }
please help
danpost danpost

2020/4/27

#
Please re-post those class in their entireties. I think there might be some confusion with the relations. Also, if you can include a main charracter class as well -- that might be helpful.
Weeb.exe Weeb.exe

2020/4/28

#
this is the main character code the whole thing
/**
 * Write a description of class Betty here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Betty extends Characters
{
    private GreenfootImage Betty1= new GreenfootImage("Betty1.png"); 
    private GreenfootImage Betty2= new GreenfootImage("Betty2.png");
    private GreenfootImage BettyGun1= new GreenfootImage("Betty_Gun_1.png"); 
    private GreenfootImage BettyGun2= new GreenfootImage("Betty_Gun_2.png");
    private int animatecounter;
    private int pistolGrabbed;
    public int fireTimer = 0;
    private boolean fire = false;
    public int lives = 5;
    /**
     * Act - do whatever the Betty wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        grabPistol();
        BettyMovement();
        checkRightWalls();
        checkLeftWalls();
        platformAbove();
        platformBelow();
        if (fireTimer != 0)
        {
            fireTimer --;
        }
        else
        {
            fire = false;
        }
        if (Greenfoot.isKeyDown("e"))
        {
            OpenableDoor door = (OpenableDoor) getOneIntersectingObject(OpenableDoor.class);

        }
    }
    public void healthBar()
    {
        lives--;
    }
    public void detectBulletCollision()
    {
        if (isTouching(Bullet.class))
        {
            healthBar();
        }
    }
    public boolean allowCollision()
    {
        if (isTouching(OpenableDoor.class) && isOpen())
        {
            OpenableDoor door = (OpenableDoor)getOneIntersectingObject(OpenableDoor.class);
            if (door.isOpen())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    

    public boolean DoorClosed()
    {
        if (allowCollision() == false)
        {
            int spriteWidth = getImage().getWidth();
            int xDistance = (int) (spriteWidth/2);

            Actor closeDoor = getOneObjectAtOffset (xDistance, 0, OpenableDoor.class);
            if (closeDoor == null)
            {
                return false;
            }
            else
            {
                stopByOpenableDoor(closeDoor);
                return true;
            }
        }
    }

    public void stopByOpenableDoor(Actor closeDoor)
    {
        int wallWidth = closeDoor.getImage().getWidth();
        int newX = closeDoor.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX , getY());
    }

    public void grabPistol()
    {
        if (isTouching(Pistol.class) && Greenfoot.isKeyDown("E"))
        {
            removeTouching(Pistol.class);
            pistolGrabbed++;
        }
    }

    private void BettyMovement()  
    {
        if (Greenfoot.isKeyDown("d")) {

            setLocation(getX()+1,getY()); 
            animate();
            animateWithGun();

        }
        if (Greenfoot.isKeyDown("a")) {

            setLocation(getX()-1,getY());
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("s")) {

            setLocation(getX(),getY()+1);
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("w")) {

            setLocation(getX(),getY()-1);
            animate();
            animateWithGun();
        }
        if (Greenfoot.mouseClicked(this)) 
        {
            shoot();
        }
        if (Greenfoot.isKeyDown("d") && Greenfoot.isKeyDown("shift")  ) {

            setLocation(getX()+2,getY());
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("w") && Greenfoot.isKeyDown("shift")  ) 
        {

            setLocation(getX(),getY()-2);
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("a") && Greenfoot.isKeyDown("shift")  )
        {

            setLocation(getX()-2,getY());
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("s") && Greenfoot.isKeyDown("shift")  )
        {

            setLocation(getX(),getY()+2);
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("p") &&  isTouching(RobotEnemy.class))
        {
            removeTouching(RobotEnemy.class);
        }
    }

    public void animate() 
    {
        if (pistolGrabbed <1){
            animatecounter++;
            if (animatecounter > 5) {
                animatecounter = 0;
                if (getImage() == Betty1) {
                    setImage(Betty2);
                }
                else {
                    setImage(Betty1); }
            }
        }
    }

    public void animateWithGun() {
        if (pistolGrabbed ==1){

            animatecounter++;
            if (animatecounter > 5) {
                animatecounter = 0;
                if (getImage() == BettyGun1) {
                    setImage(BettyGun2);
                }
                else {
                    setImage(BettyGun1); }
            }
        }
    }

    public void shoot() {
        if (pistolGrabbed ==1   && fire == false)
        {
            fire();
            fire = true;
            fireTimer = 25;

        }
    }

    private void fire()
    {

        Bullet bullet = new Bullet();
        getWorld().addObject(bullet, getX(), getY());
        bullet.move(05);
    }

    public boolean checkRightWalls()
    {
        int spriteWidth = getImage().getWidth();
        int xDistance = (int) (spriteWidth/2);

        Actor rightWall = getOneObjectAtOffset (xDistance, 0, Brick.class);
        if (rightWall == null)
        {
            return false;
        }
        else
        {
            stopByRightWall(rightWall);
            return true;
        }
    }

    public void stopByRightWall(Actor rightWall)
    {
        int wallWidth = rightWall.getImage().getWidth();
        int newX = rightWall.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX , getY());
    }

    public boolean checkLeftWalls()
    {
        int spriteWidth = getImage().getWidth();
        int xDistance = (int) (spriteWidth/-2);

        Actor leftWall = getOneObjectAtOffset (xDistance, 0, Brick.class);
        if (leftWall == null)
        {
            return false;
        }
        else
        {
            stopByLeftWall(leftWall);
            return true;
        }
    }

    public void stopByLeftWall(Actor leftWall)
    {
        int wallWidth = leftWall.getImage().getWidth();
        int newX = leftWall.getX() -(wallWidth + getImage().getWidth())/-2;
        setLocation(newX , getY());
    }

    public boolean platformAbove()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int) (spriteHeight / 2 + 5);

        Actor ceiling = getOneObjectAtOffset(0, getImage().getHeight()/2, (Brick.class));
        if (ceiling == null)
        {
            return false;
        }
        else
        {
            stopByCeiling(ceiling);
            return true;
        }
    }

    public void stopByCeiling(Actor ceiling)
    {
        int ceilingHeight = ceiling.getImage().getHeight();
        int newY = ceiling.getY() + (ceilingHeight + getImage().getWidth())/2;
        setLocation(getX() , newY);
    }

    public boolean platformBelow()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int) (spriteHeight / -2);

        Actor floor = getOneObjectAtOffset(0, yDistance, (Brick.class));
        if (floor == null)
        {
            return false;
        }
        else
        {
            stopByFloor(floor);
            return true;
        }
    }

    public void stopByFloor(Actor floor)
    {
        int floorHeight = floor.getImage().getHeight();
        int newY = floor.getY() - (floorHeight + getImage().getWidth())/2;
        setLocation(getX() , newY);
    }

}
then the door
public class OpenableDoor extends Actor
{
    private boolean open, eDown;
    /**
     * Act - do whatever the OpenableDoor wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (Greenfoot.isKeyDown("e") != eDown)
        {
            eDown = !eDown;
            if (isTouching(Betty.class) && eDown)
            {
                open = !open;
                setImage(open ? "OpenableDoor1.png" : "OpenableDoor2.png");
            }
        }
        if (Greenfoot.isKeyDown("e") != eDown)
        {
            eDown = !eDown;
            if (isTouching(BillyMetal.class) && eDown)
            {
                open = !open;
                setImage(open ? "OpenableDoor1.png" : "OpenableDoor2.png");
            }
        }
        if (Greenfoot.isKeyDown("e") != eDown)
        {
            eDown = !eDown;
            if (isTouching(Billy.class) && eDown)
            {
                open = !open;
                setImage(open ? "OpenableDoor1.png" : "OpenableDoor2.png");
            }
        }
    }

    public boolean isOpen()
    {
        return open;
    }
}
think this is what you mean however if there is anything else let me know
Weeb.exe Weeb.exe

2020/4/28

#
so is there anyway to fix this or should i just remove this because it has taken a very long time to do this.
danpost danpost

2020/4/28

#
What are all your classes that extend Characters? Also, what are all those that extend OpenableDoor?
Weeb.exe Weeb.exe

2020/4/28

#
nothing extends openable door openable door is the door itself also the characters are these currently im just working on one character then ill update the other 2 this is the other 2
/**
 * Write a description of class Billy here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Billy extends Characters
{
    private GreenfootImage Billy1= new GreenfootImage("Billy1.png"); 
    private GreenfootImage Billy2= new GreenfootImage("Billy2.png");
    private GreenfootImage BillyGun1= new GreenfootImage("BillyGun1.png"); 
    private GreenfootImage BillyGun2= new GreenfootImage("BillyGun2.png");
    private int pistolGrabbed;
    private int animatecounter;
    public int fireTimer = 0;
    private boolean fire = false;
    /**
     * Act - do whatever the Billy wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        grabPistol();
        BillyMovement();
        checkRightWalls();
        checkLeftWalls();
        platformAbove();
        platformBelow();
        if (fireTimer != 0)
        {
            fireTimer --;
        }
        else
        {
            fire = false;
        }
        if (Greenfoot.isKeyDown("e"))
        {
            OpenableDoor door = (OpenableDoor) getOneIntersectingObject(OpenableDoor.class);
            
        }
    }
    public boolean DoorClosed()
    {
        if (allowCollision() == false)
        {
            int spriteWidth = getImage().getWidth();
            int xDistance = (int) (spriteWidth/2);
  
            Actor closeDoor = getOneObjectAtOffset (xDistance, 0, OpenableDoor.class);
            if (closeDoor == null)
            {
                return false;
            }
            else
            {
                stopByOpenableDoor(closeDoor);
                return true;
            }
        }
    }
    public void stopByOpenableDoor(Actor closeDoor)
    {
        int wallWidth = closeDoor.getImage().getWidth();
        int newX = closeDoor.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX , getY());
    }
    public void grabPistol()
    {
        if (isTouching(Pistol.class) && Greenfoot.isKeyDown("E"))
        {
            removeTouching(Pistol.class);
            pistolGrabbed++;
        }
    }

    private void BillyMovement()  
    {
        if (Greenfoot.isKeyDown("d")) {
            setLocation(getX()+2,getY()); 
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("a")) {
            setLocation(getX()-2,getY());
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("s")) {
            setLocation(getX(),getY()+2);
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("w")) {
            setLocation(getX(),getY()-2);
            animate();
            animateWithGun();
        }
        if (Greenfoot.mouseClicked(this))
        {
            shoot();
        }
        if (Greenfoot.isKeyDown("d") && Greenfoot.isKeyDown("shift")  ) {
            setLocation(getX()+3,getY());
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("w") && Greenfoot.isKeyDown("shift")  ) 
        {
            setLocation(getX(),getY()-3);
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("a") && Greenfoot.isKeyDown("shift")  )
        {
            setLocation(getX()-3,getY());
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("s") && Greenfoot.isKeyDown("shift")  )
        {
            setLocation(getX(),getY()+3);
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("p") &&  isTouching(RobotEnemy.class))
        {
            removeTouching(RobotEnemy.class);
        }
    }

    public void animate() {
        if (pistolGrabbed == 0){
            animatecounter++;
            if (animatecounter > 5) {
                animatecounter = 0;
                if (getImage() == Billy1) {
                    setImage(Billy2);
                }
                else {
                    setImage(Billy1); }
            }
        }
    }

    public void animateWithGun() {
        if (pistolGrabbed ==1){

            animatecounter++;
            if (animatecounter > 5) {
                animatecounter = 0;
                if (getImage() == BillyGun1) {
                    setImage(BillyGun2);
                }
                else {
                    setImage(BillyGun1); }
            }
        }
    }

    public void shoot() {
        if (pistolGrabbed ==1   && fire == false)
        {
            fire();
            fire = true;
            fireTimer = 60;

        }
    }

    private void fire()
    {
        Bullet bullet = new Bullet();
        getWorld().addObject(bullet, getX(), getY());
        bullet.move(05);
    }

    public boolean checkRightWalls()
    {
        int spriteWidth = getImage().getWidth();
        int xDistance = (int) (spriteWidth/2);

        Actor rightWall = getOneObjectAtOffset (xDistance, 0, Brick.class);
        if (rightWall == null)
        {
            return false;
        }
        else
        {
            stopByRightWall(rightWall);
            return true;
        }
    }

    public void stopByRightWall(Actor rightWall)
    {
        int wallWidth = rightWall.getImage().getWidth();
        int newX = rightWall.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX , getY());
    }

    public boolean checkLeftWalls()
    {
        int spriteWidth = getImage().getWidth();
        int xDistance = (int) (spriteWidth/-2);

        Actor leftWall = getOneObjectAtOffset (xDistance, 0, Brick.class);
        if (leftWall == null)
        {
            return false;
        }
        else
        {
            stopByLeftWall(leftWall);
            return true;
        }
    }

    public void stopByLeftWall(Actor leftWall)
    {
        int wallWidth = leftWall.getImage().getWidth();
        int newX = leftWall.getX() -(wallWidth + getImage().getWidth())/-2;
        setLocation(newX , getY());
    }

    public boolean platformAbove()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int) (spriteHeight / 2 + 5);

        Actor ceiling = getOneObjectAtOffset(0, getImage().getHeight()/2, (Brick.class));
        if (ceiling == null)
        {
            return false;
        }
        else
        {
            stopByCeiling(ceiling);
            return true;
        }
    }

    public void stopByCeiling(Actor ceiling)
    {
        int ceilingHeight = ceiling.getImage().getHeight();
        int newY = ceiling.getY() + (ceilingHeight + getImage().getWidth())/2;
        setLocation(getX() , newY);
    }

    public boolean platformBelow()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int) (spriteHeight / -2);

        Actor floor = getOneObjectAtOffset(0, yDistance, (Brick.class));
        if (floor == null)
        {
            return false;
        }
        else
        {
            stopByFloor(floor);
            return true;
        }
    }

    public void stopByFloor(Actor floor)
    {
        int floorHeight = floor.getImage().getHeight();
        int newY = floor.getY() - (floorHeight + getImage().getWidth())/2;
        setLocation(getX() , newY);
    }
}
then the other
/**
 * Write a description of class BillyMetal here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class BillyMetal extends Characters
{
    private GreenfootImage Billy1= new GreenfootImage("BillyNoHair.png"); 
    private GreenfootImage Billy2= new GreenfootImage("BillyNoHair2.png");
    private GreenfootImage BillyGun1= new GreenfootImage("BillyNoHairGun.png"); 
    private GreenfootImage BillyGun2= new GreenfootImage("BillyNoHairGun2.png");
    private int pistolGrabbed;
    private int animatecounter;
    public int fireTimer = 0;
    private boolean fire = false;
    /**
     * Act - do whatever the BillyMetal wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        grabPistol();
        BillyMovement();
        checkRightWalls();
        checkLeftWalls();
        platformAbove();
        platformBelow();
        if (fireTimer != 0)
        {
            fireTimer --;
        }
        else
        {
            fire = false;
        }
        if (Greenfoot.isKeyDown("e"))
        {
            OpenableDoor door = (OpenableDoor) getOneIntersectingObject(OpenableDoor.class);
            
        }
    }
    public boolean DoorClosed()
    {
        if (allowCollision() == false)
        {
            int spriteWidth = getImage().getWidth();
            int xDistance = (int) (spriteWidth/2);
  
            Actor closeDoor = getOneObjectAtOffset (xDistance, 0, OpenableDoor.class);
            if (closeDoor == null)
            {
                return false;
            }
            else
            {
                stopByOpenableDoor(closeDoor);
                return true;
            }
        }
    }
    public void stopByOpenableDoor(Actor closeDoor)
    {
        int wallWidth = closeDoor.getImage().getWidth();
        int newX = closeDoor.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX , getY());
    }
        public void grabPistol()
    {
        if (isTouching(Pistol.class) && Greenfoot.isKeyDown("E"))
        {
            removeTouching(Pistol.class);
            pistolGrabbed++;
        }
        
    }
    private void BillyMovement()  
    {
        if (Greenfoot.isKeyDown("d")) {
            setLocation(getX()+2,getY()); 
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("a")) {
            setLocation(getX()-2,getY());
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("s")) {
            setLocation(getX(),getY()+2);
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("w")) {
            setLocation(getX(),getY()-2);
            animate();
            animateWithGun();
        }
        if (Greenfoot.mouseClicked(this))
        {
            shoot();
        }
        if (Greenfoot.isKeyDown("d") && Greenfoot.isKeyDown("shift")  ) {
            setLocation(getX()+3,getY());
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("w") && Greenfoot.isKeyDown("shift")  ) 
        {
            setLocation(getX(),getY()-3);
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("a") && Greenfoot.isKeyDown("shift")  )
        {
            setLocation(getX()-3,getY());
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("s") && Greenfoot.isKeyDown("shift")  )
        {
            setLocation(getX(),getY()+3);
            animate();
            animateWithGun();
        }
        if (Greenfoot.isKeyDown("p") &&  isTouching(RobotEnemy.class))
        {
            removeTouching(RobotEnemy.class);
        }
    }
    public void animate() {
        if (pistolGrabbed == 0){
            animatecounter++;
        if (animatecounter > 5) {
            animatecounter = 0;
            if (getImage() == Billy1) {
                setImage(Billy2);
            }
            else {
            setImage(Billy1); }
        }
      }
    }
      
    public void animateWithGun() {
        if (pistolGrabbed ==1){
  
                animatecounter++;
        if (animatecounter > 5) {
            animatecounter = 0;
            if (getImage() == BillyGun1) {
                setImage(BillyGun2);
            }
            else {
            setImage(BillyGun1); }
        }
      }
    }
              
    
    public void shoot() {
        if (pistolGrabbed ==1 )
        {
            fire();
            
            fire = true;
            fireTimer = 60;
        }
    }
    private void fire()
    {
        Bullet bullet = new Bullet();
        getWorld().addObject(bullet, getX(), getY());
        bullet.move(05);
    }
public boolean checkRightWalls()
    {
        int spriteWidth = getImage().getWidth();
        int xDistance = (int) (spriteWidth/2);

        Actor rightWall = getOneObjectAtOffset (xDistance, 0, Brick.class);
        if (rightWall == null)
        {
            return false;
        }
        else
        {
            stopByRightWall(rightWall);
            return true;
        }
    }

    public void stopByRightWall(Actor rightWall)
    {
        int wallWidth = rightWall.getImage().getWidth();
        int newX = rightWall.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX , getY());
    }

    public boolean checkLeftWalls()
    {
        int spriteWidth = getImage().getWidth();
        int xDistance = (int) (spriteWidth/-2);

        Actor leftWall = getOneObjectAtOffset (xDistance, 0, Brick.class);
        if (leftWall == null)
        {
            return false;
        }
        else
        {
            stopByLeftWall(leftWall);
            return true;
        }
    }

    public void stopByLeftWall(Actor leftWall)
    {
        int wallWidth = leftWall.getImage().getWidth();
        int newX = leftWall.getX() -(wallWidth + getImage().getWidth())/-2;
        setLocation(newX , getY());
    }

    public boolean platformAbove()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int) (spriteHeight / 2 + 5);

        Actor ceiling = getOneObjectAtOffset(0, getImage().getHeight()/2, (Brick.class));
        if (ceiling == null)
        {
            return false;
        }
        else
        {
            stopByCeiling(ceiling);
            return true;
        }
    }

    public void stopByCeiling(Actor ceiling)
    {
        int ceilingHeight = ceiling.getImage().getHeight();
        int newY = ceiling.getY() + (ceilingHeight + getImage().getWidth())/2;
        setLocation(getX() , newY);
    }

    public boolean platformBelow()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int) (spriteHeight / -2);

        Actor floor = getOneObjectAtOffset(0, yDistance, (Brick.class));
        if (floor == null)
        {
            return false;
        }
        else
        {
            stopByFloor(floor);
            return true;
        }
    }

    public void stopByFloor(Actor floor)
    {
        int floorHeight = floor.getImage().getHeight();
        int newY = floor.getY() - (floorHeight + getImage().getWidth())/2;
        setLocation(getX() , newY);
    }
}
Weeb.exe Weeb.exe

2020/4/28

#
ok i moved the door stuff to the characters class
public class Characters extends Actor
{
    /**
     * Act - do whatever the Characters wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
    } 
    public boolean allowCollision()
    {
        if (isTouching(OpenableDoor.class) && isOpen())
        {
            OpenableDoor door = (OpenableDoor)getOneIntersectingObject(OpenableDoor.class);
            if (door.isOpen())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    

    public boolean DoorClosed()
    {
        if (allowCollision() == false)
        {
            int spriteWidth = getImage().getWidth();
            int xDistance = (int) (spriteWidth/2);

            Actor closeDoor = getOneObjectAtOffset (xDistance, 0, OpenableDoor.class);
            if (closeDoor == null)
            {
                return false;
            }
            else
            {
                stopByOpenableDoor(closeDoor);
                return true;
            }
        }
    }

    public void stopByOpenableDoor(Actor closeDoor)
    {
        int wallWidth = closeDoor.getImage().getWidth();
        int newX = closeDoor.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX , getY());
    }

}
danpost danpost

2020/4/28

#
In OpenableDoor class above, remove lines 19 to 36 and then change Billy.class on line 13 to Characters.class. Why do all Billy, BillyMetal and Betty use the same movement keys?
Weeb.exe Weeb.exe

2020/4/28

#
because you can select different characters
Weeb.exe Weeb.exe

2020/4/28

#
Ok so
public boolean allowCollision()
    {
        if (isTouching(OpenableDoor.class) && isOpen()//cant find it)
        {
            OpenableDoor door = (OpenableDoor)getOneIntersectingObject(OpenableDoor.class);
            if (door.isOpen())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
it says where i said it cant find it
cannot find symbol - method isOpen()
how would i call that since this method is in the "OpenableDoor" class
Weeb.exe Weeb.exe

2020/4/28

#
Weeb.exe wrote...
because you can select different characters
danpost wrote...
Why do all Billy, BillyMetal and Betty use the same movement keys?
basically there is a select characters screen, i might make it a 2 player game later but for now you chose the character you want to play as
Weeb.exe Weeb.exe

2020/4/28

#
anyway
Weeb.exe wrote...
Ok so
public boolean allowCollision()
    {
        if (isTouching(OpenableDoor.class) && isOpen()//cant find it)
        {
            OpenableDoor door = (OpenableDoor)getOneIntersectingObject(OpenableDoor.class);
            if (door.isOpen())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
it says where i said it cant find it
cannot find symbol - method isOpen()
how would i call that since this method is in the "OpenableDoor" class
Weeb.exe Weeb.exe

2020/4/28

#
so im basically asking how do i get this and get it to recognise that this is from a seperate class and grab the method from there
There are more replies on the next page.
1
2
3
4
5
6