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

2019/6/14

Actor randomly goes through wall

keyfive keyfive

2019/6/14

#
When the back of Zee touches a Wall or Brick, it just makes Zee go backwards, through the wall, out of the world. How can I fix this?
import greenfoot.*;
public class Zee extends Actor {
    private int timer;
    public static boolean stabbing = false;
    public boolean d = true;
    boolean death = false; 
    private static boolean tutorial;
    private int holeTimer;
    int ScaleX = 80;
    GreenfootImage zee = new GreenfootImage("newzee.png");
    GreenfootSound alertS = new GreenfootSound("mgs.mp3");
    alert alert = new alert();
    private int alertTimer = 60;
    boolean alertTimeUp = false;
    public static int zeex;
    public static int zeey;
    Laser laser = new Laser();
    World world = getWorld();
    public static void setTutorial(boolean tut) {tutorial = tut;}

    public Zee() {
        GreenfootImage image = getImage();
        image.scale(80, 80);
    }

    public void act() {
        stabbing = false;
        zeex = getX();
        zeey = getY();

        //Controls
        if (Greenfoot.isKeyDown("left") || (Greenfoot.isKeyDown("a"))){
            setRotation(180);
            move(3);
        } else if (Greenfoot.isKeyDown("up") || (Greenfoot.isKeyDown("w"))){
            setRotation(-90);
            move(3);
        } else if (Greenfoot.isKeyDown("right") || (Greenfoot.isKeyDown("d"))){
            setRotation(360);
            move(3);
        } else if (Greenfoot.isKeyDown("down") || (Greenfoot.isKeyDown("s"))) {
            setRotation(90);
            move(3);
        }

        //Stabbing
        if (Greenfoot.isKeyDown("e") || (Greenfoot.isKeyDown("shift"))){
            setImage("zeestab4.png");
            stabbing = true;
            timer = 6;
        }
        if (timer > 0 && --timer == 0) setImage("newzee.png"); 

        //Restrictions and Level Progression
        Level myWorld = (Level)getWorld();
        if (isTouching(Wall.class)) {
            move(-3);
        }
        if (isTouching(Endgame.class)) {
            Greenfoot.setWorld(new Level2());
        } 
        if (isTouching(Endgame2.class)) {
            Greenfoot.setWorld(new Level3());
        }
        if (isTouching(Endgame3.class)) {
            Greenfoot.setWorld(new Level4());
        } 
        if (isTouching(Endgame4.class)) {
            Greenfoot.setWorld(new Level5());
        }
        if (isTouching(Endgame5.class)) {
            Greenfoot.setWorld(new Final());
        } 

        //Tutorial Wall
        if(isTouching(Brick.class)) {
            move(-3);
        }

        //Laser Unlock and Score
        if (isTouching(Key.class)) {
            getWorld().removeObjects(getWorld().getObjects(Laser.class));
            removeTouching(Key.class);
        }
        if (isTouching(Coins.class)) {
            removeTouching(Coins.class);
            myWorld.increaseScore();
        }

        //Tutorial Hole Animation
        if(isTouching(Hole.class)) {
            tutorial = false;
            holeTimer = 10;
            move(0);
            setLocation(1105, 505);
            setRotation(-90);
            ScaleX = 80;
            setImage(zee);
            while (ScaleX > 30) {
                ScaleX = ScaleX - 10;
                Greenfoot.delay(50);
                zee.scale(ScaleX, ScaleX);
            }
            Greenfoot.setWorld(new Level1());
            tutorial = false;
        }

        //Tutorial Exclusive
        if  (tutorial == true && getX()>512 && enemyT.deadWorld1 == false) {
            alertS.play(); //Alert sound
            getWorld().addObject(alert, 500, 450);
            enemyT.inSight = true;
        }
        if (enemyT.inSight == true) {
            if ( alertTimer > 0) {
                alertTimer--;
                if (alertTimer == 0) alertTimeUp = true;
            }
            if   (enemyT.deadWorld1 == false && alertTimeUp == true) {
                Greenfoot.setWorld(new Tutorial());
            }
        }
        if   (tutorial == true && enemyT.deadWorld1 == true) {
            getWorld().removeObject(alert);
        }
    }

    //Stabbing Animation
    public void Stab() {
        GreenfootImage zeestab2 = getImage();
        zeestab2.scale(80, 80);
    }
}
You need to login to post a reply.