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

3
4
5
6
Weeb.exe Weeb.exe

2020/4/30

#
I don't understand sorry, do you mean how big it is?
danpost danpost

2020/4/30

#
Weeb.exe wrote...
I don't understand sorry, do you mean how big it is?
No. In the frame class, you have: public class frame extends ?????????????? What do you have for the question markss? ("frame", by me, may not be named properly)
Weeb.exe Weeb.exe

2020/4/30

#
oh ok
public class OpenableDoor extends Actor
danpost danpost

2020/5/1

#
Weeb.exe wrote...
oh ok
public class OpenableDoor extends Actor
If by "frame" you are referring to part of the OpenableDoor object, then "e" should work when you get halted. If not, stop the scenario, right-click on the door and select Delete. Then start it back up and see in you can make further progress toward where the door was.
Weeb2.exe Weeb2.exe

2020/5/1

#
ok so this is my second account i couldn't post or anything it told me that a post i tried to send was selected for review blah blah so i'm just letting you know
Weeb2.exe Weeb2.exe

2020/5/1

#
i think its because I tried to send a link (youtube) then it told me that it was selected for review
Weeb2.exe Weeb2.exe

2020/5/6

#
ill test that theory now Greenfoot Help Youtube
Weeb2.exe Weeb2.exe

2020/5/8

#
ok so now my seccond account can post again can you have a look at the video that i sent because it helps out a fair bit if you can answer it thank you basically cant go through door keeps throwing me backwards
danpost danpost

2020/5/8

#
Please show most recent Characters class codes. Also, it that another Characters object to the right of the door?
Weeb2.exe Weeb2.exe

2020/5/15

#
sorry I've had a lot of technical difficulties lately
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()
    {
        OpenableDoor door = (OpenableDoor)getOneIntersectingObject(OpenableDoor.class);
        if (door != null && !door.isOpen()) stopByOpenableDoor(door);
    }

    public void stopByOpenableDoor(Actor closeDoor)
    {
        int wallWidth = closeDoor.getImage().getWidth();
        int newX = closeDoor.getX() -(wallWidth + getImage().getWidth()) -10;
        setLocation(newX , getY());
    }
}
characters ^ I think you mean the character on screen so here
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();
        super.act();
        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 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(06);
    }

    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);
    }

}
danpost danpost

2020/5/15

#
Try the folllowing for line 16 in Characters class code given above:
int newX = closeDoor.getX()-(wallWidth+getImage().getWidth())/2+1;
Weeb2.exe Weeb2.exe

2020/5/16

#
Oh My God! IT WORKED YESSSSSS THANK YOU SO MUCH you are awesome dan thank you so much for helping
You need to login to post a reply.
3
4
5
6