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

2016/11/20

collision

Nosson1459 Nosson1459

2016/11/20

#
 import greenfoot.*; 
import java.util.List;
/**
 * This is the whole scene. It creates and contains the objects that are in it.
 */
public class Scene extends World
{
    public int lives=2;
    private int width=750;
    private int height=500;
    public int score=0;
    public int coins=0;
    public int level=2;
    public boolean move=false;
    public boolean direction=true;
    private int a=1;
    public boolean onCloud=false;
    public boolean way=true;
    public boolean shooting=false;
    public boolean pause=false;
    public boolean isDoor=false;
    public int moveSpeed=-7;
    public boolean startToMove=false;
    public boolean isThere=false;
    public Scene()
    {    
        super(750, 650, 1, false);    // define size, resolution, cell size, and unbounded  
        setPaintOrder(EndScore.class,GameOver.class,Win.class,HelpBox.class,Help.class,Coins.class,Level.class,Life.class,Score.class,Pause.class,Bar.class,Door.class,
        Pengu.class,DoorPost.class,Paused.class,Box.class,Shooting.class,Snake.class,SnakeD.class,Platform.class);
        addObject(new Bar(),375,18);
        addObject(new Coins("Coins: "),645,18);
        addObject(new Life("Lives: "),85,18);
        addObject(new Score("Score: "),470,18);
        addObject(new Level("Level: "),270,18);
        addObject(new HelpBox(),730,18);
        addObject(new Pause(),18,18);
        levelUp();
    }
    public void act()
    {
        if(!pause)
        {
            if(lives<0)
            {
                addObject(new GameOver(),375,325);
                addObject(new EndScore(),375,337);
                Greenfoot.stop();
            }
            if(coins==100)
            {
                score+=500;
                lives++;
                coins=0;
            }
            levelAct();
        }
    }
    public void reset()
    {
        List<Platform> platform=getObjects(Platform.class);
        List<Boxes> box=getObjects(Boxes.class);
        List<Pengu> pengu=getObjects(Pengu.class);
        List<Cliff> cliff=getObjects(Cliff.class);
        List<Monster> monster=getObjects(Monster.class);
        List<Coin> coin=getObjects(Coin.class);
        List<Bullet> bullet=getObjects(Bullet.class);
        removeObjects(platform);
        removeObjects(bullet);
        removeObjects(box);
        removeObjects(pengu);
        removeObjects(cliff);
        removeObjects(coin);
        removeObjects(monster);
        onCloud=false;
        a=1;
        shooting=false;
        List<Shooting> shooting=getObjects(Shooting.class);
        removeObjects(shooting);
        List<Door> door=getObjects(Door.class);
        removeObjects(door);
        List<DoorPost> doorPost=getObjects(DoorPost.class);
        removeObjects(doorPost);
        isDoor=false;
        List<ExtraLife> extraLife=getObjects(ExtraLife.class);
        removeObjects(extraLife);
        startToMove=false;
    }
    public void levelReset()
    {
        List<Platform> platform=getObjects(Platform.class);
        List<Boxes> box=getObjects(Boxes.class);
        List<Pengu> pengu=getObjects(Pengu.class);
        List<Cliff> cliff=getObjects(Cliff.class);
        List<Monster> monster=getObjects(Monster.class);
        List<Coin> coin=getObjects(Coin.class);
        List<Bullet> bullet=getObjects(Bullet.class);
        removeObjects(platform);
        removeObjects(bullet);
        removeObjects(box);
        removeObjects(pengu);
        removeObjects(cliff);
        removeObjects(coin);
        removeObjects(monster);
        onCloud=false;
        a=1;
        List<Shooting> shooting=getObjects(Shooting.class);
        removeObjects(shooting);
        List<Door> door=getObjects(Door.class);
        removeObjects(door);
        List<DoorPost> doorPost=getObjects(DoorPost.class);
        removeObjects(doorPost);
        isDoor=false;
        List<ExtraLife> extraLife=getObjects(ExtraLife.class);
        removeObjects(extraLife);
        startToMove=false;
    }
    public void simulation()
    {
        addObject ( new Cliff(), 50, 405);
        addObject ( new Cliff(3), 650, 405);
        
        addObject ( new Platform(4), 369, 315 );
        
        addObject ( new Pengu(), 46, 291 );
        
        addObject(new SnakeD(),650,302);
        addObject(new Block(2),141,270);
        addObject(new Block(2),141,310);
        addObject(new Block(2),181,310);
        addObject(new Block(2),221,310);
        addObject(new Block(2),261,310);
        addObject(new Block(2),261,270);
        addObject(new Snake(1),201,275);
    }
    public void levelUp()
    {
        if(level==1)
        level1();
        if(level==2)
        level2();
        if(level==3)
        {
            addObject(new Win(),250,375);
            addObject(new EndScore(),375,212);
        }
    }
    public void level1()
    {
        for(int j=20;j<481;j+=40)
        {
            for(int i=510;i<631;i+=40)
            {
                addObject(new Block(2),j,i);
            }
        }
        addObject(new Pengu(),192,470);
        for(int i=240;i<401;i+=40)
        {
            addObject(new Box(1),i,390);
        }
        addObject ( new Cliff(3), 658, 555);
        addObject(new SnakeD(),658,449);
        addObject(new Box(6),658,350);
        addObject(new Cliff(2),908,525);
        addObject(new Coin(),908,310);
        addObject(new Coin(),873,310);
        addObject(new Coin(),943,310);
        addObject(new Cliff(2),1243,525);
        addObject(new Platform(4),1076,450);
        for(int j=1362;j<1483;j+=40)
        {
            for(int i=510;i<631;i+=40)
            {
                addObject(new Block(2),j,i);
            }
        }
        for(int i=1362;i<1443;i+=40)
        {
            addObject(new Coin(),i,390);
        }
        addObject(new Box(2),1482,390);
        addObject(new Block(1),1679,439);
        addObject(new Cliff(3),1788,555);
        addObject(new Cliff(2),1942,525);
        addObject(new Snake(1),1942,360);
        for (int j=2105; j<2346; j+=40)
        {
            for (int i=486; i<647; i+=40)
            {
                addObject(new Block(3),j,i);
            }
        }
        addObject(new Door(),2292,433);
        addObject(new DoorPost(),2292,433);
    }
    private void levelAct()
    {
        if(level==1)
        level1Act();
        if(level==2)
        level2Act();
    }
    private void level1Act()
    {
        if(a==1)
        {
            addObject(new Creature(),440,390);
            a=3;
        }
    }
    private void level2()
    {
        levelReset();
        addObject(new Pengu(),60,470);
        int a=509;
        for(int j=20;j<661;j+=40)
        {
            for(int i=630;i>a;i-=40)
            {
                if(j<301||j>381)
                {
                    addObject(new Block(2),j,i);
                }
            }
            if(j>381&&j<541)
            {
                a+=40;
            }
            else if(j>141&&j<261)
            {
                a-=40;
            }
        }
        for (int i=60;i<141;i+=40)
        {
            addObject(new Box(1),i,382);
        }
        for (int i=60;i<141;i+=40)
        {
            addObject(new Coin(),i,272);
        }
        addObject(new SnakeD(),660,519);
        addObject(new Platform(2),800,540);
        addObject(new Snake(1),300,358);
        for(int j=1062;j<1183;j+=40)
        {
            for(int i=630;i>470;i-=40)
            {
                addObject(new Block(2),j,i);
            }
        }
        addObject(new SnakeD(),1142,478);
        for(int i=1062;i<1183;i+=40)
        {
            addObject(new Coin(),i,340);
        }
        addObject(new Block(1),1294,461);
        addObject(new Block(1),1387,412);
        addObject(new Block(1),1487,501);
        addObject(new Block(1),1599,575);
        addObject(new Block(1),1681,427);
        addObject(new Cliff(4),1961,555);
        for(int i=2034;i>1988;i-=45)
        {
            addObject(new Snake(-2,2),i,447);
        }
        for(int i=1807;i<2116;i+=154)
        {
            addObject(new Box(4),i,354);
        }
        for(int i=1807;i<1913;i+=35)
        {
            addObject(new Coin(),i,239);
        }
        addObject(new Box(2),1961,239);
        for(int i=2010;i<2116;i+=35)
        {
            addObject(new Coin(),i,239);
        }
        int b=470;
        for(int j=2245;j<2846;j+=40)
        {
            for(int i=630;i>b;i-=40)
            {
                addObject(new Block(2),j,i);
            }
            if(j==2365)
            b-=120;
            else if(j==2405)
            b+=120;
            else if(j==2725)
            b-=120;
            else if(b==2765)
            b=470;
        }
    }
    private void level2Act()
    {
    }
    public void help()
    {
        addObject(new Help(),375,325);
    }
    public void help2()
    {
        List<Help> help=getObjects(Help.class);
        removeObjects(help);
    }
    private void test()
    {
        int a=359;
        for(int j=20;j<661;j+=40)
        {
            for(int i=480;i>a;i-=40)
            {
                if(j<301||j>381)
                {
                    addObject(new Block(2),j,i);
                }
            }
            if(j>381&&j<541)
            {
                a+=40;
            }
            else if(j>141&&j<261)
            {
                a-=40;
            }
        }
        
         
    }
}
import greenfoot.*;

/**
 * The class Mover provides some basic movement methods. Use this as a superclass
 * for other actors that should be able to move left and right, jump up and fall 
 * down.
 */
public class Mover extends Actor
{
    private static final int acceleration = 2;      // down (gravity)
    private static final int speed = 7;             // running speed (sideways)
    
    public int vSpeed = 0;                         // current vertical speed
    
    private boolean hasHit=false;
    public void moveRight()
    {
        setLocation ( getX() + speed, getY() );
    }

    public void moveLeft()
    {
        setLocation ( getX() - speed, getY() );
    }
            
    public boolean onTop()
    {
        return onTop1B()||onTop2B()||onTop3B();
    }
    public boolean onTop2()
    {
        return onTop1Bc()||onTop2Bc()||onTop3Bc();
    }
    private boolean onTop1B()
    {
        Box box = (Box)getOneObjectAtOffset(-getImage().getWidth()/2+8, -getImage().getHeight()/2 , Box.class);
        return box != null&&vSpeed<0;
    }
    private boolean onTop2B()
    {
        Box box = (Box)getOneObjectAtOffset(0, -getImage().getHeight()/2 , Box.class);
        return box != null&&vSpeed<0;
    }
    private boolean onTop3B()
    {
        Box box = (Box)getOneObjectAtOffset(getImage().getWidth()/2-8, -getImage().getHeight()/2 , Box.class);
        return box != null&&vSpeed<0;
    }
    private boolean onTop1Bc()
    {
        Object under = getOneObjectAtOffset(-getImage().getWidth()/2+8, -getImage().getHeight()/2 , Block.class);
        return under != null;
    }
    private boolean onTop2Bc()
    {
        Object under = getOneObjectAtOffset(0, -getImage().getHeight()/2 , Block.class);
        return under != null;
    }
    private boolean onTop3Bc()
    {
        Object under = getOneObjectAtOffset(getImage().getWidth()/2-8, -getImage().getHeight()/2 , Block.class);
        return under != null;
    }
    
    private boolean onGround1B()
    {
        Box box = (Box)getOneObjectAtOffset(0, getImage().getHeight()/2 , Box.class);
        return box != null&&box.isThere==true;
    }
    private boolean onGround2B()
    {
        Box box = (Box)getOneObjectAtOffset(getImage().getWidth()/2-10, getImage().getHeight()/2 , Box.class);
        return box != null&&box.isThere==true;
    }
    private boolean onGround3B()
    {
        Box box  = (Box)getOneObjectAtOffset(-getImage().getWidth()/2+10, getImage().getHeight()/2 , Box.class);
        return box != null&&box.isThere==true;
    }
    private boolean onGroundB()
    {
        return onGround1B()||onGround2B()||onGround3B();
    }
    private boolean onGround1Bc()
    {
        Object under = getOneObjectAtOffset(0, getImage().getHeight()/2 , Block.class);
        return under != null;
    }
    private boolean onGround2Bc()
    {
        Object under = getOneObjectAtOffset(getImage().getWidth()/2-10, getImage().getHeight()/2 , Block.class);
        return under != null;
    }
    private boolean onGround3Bc()
    {
        Object under = getOneObjectAtOffset(-getImage().getWidth()/2+10, getImage().getHeight()/2 , Block.class);
        return under != null;
    }
    private boolean onGroundBc()
    {
        return onGround1Bc()||onGround2Bc()||onGround3Bc();
    }
    private boolean onGround1CA()
    {
        Object under = getOneObjectAtOffset(0, getImage().getHeight()/2 , Cliff.class);
        return under != null;
    }
    private boolean onGround2CA()
    {
        Object under = getOneObjectAtOffset(getImage().getWidth()/2-10, getImage().getHeight()/2 , Cliff.class);
        return under != null;
    }
    private boolean onGround3CA()
    {
        Object under = getOneObjectAtOffset(-getImage().getWidth()/2+10, getImage().getHeight()/2 , Cliff.class);
        return under != null;
    }
    private boolean onGroundCA()
    {
        return onGround1CA()||onGround2CA()||onGround3CA();
    }
    private boolean onGround1P()
    {
        Object under = getOneObjectAtOffset(0, getImage().getHeight()/2 , Platform.class);
        return under != null;
    }
    private boolean onGround2P()
    {
        Object under = getOneObjectAtOffset(getImage().getWidth()/2-10, getImage().getHeight()/2 , Platform.class);
        return under != null;
    }
    private boolean onGround3P()
    {
        Object under = getOneObjectAtOffset(-getImage().getWidth()/2+10, getImage().getHeight()/2 , Platform.class);
        return under != null;
    }
    private boolean onGroundP()
    {
        return onGround1P()||onGround2P()||onGround3P();
    }
    private boolean onGround1Cr()
    {
        Object under = getOneObjectAtOffset(0, getImage().getHeight()/2 , Creature.class);
        return under != null;
    }
    private boolean onGround2Cr()
    {
        Object under = getOneObjectAtOffset(getImage().getWidth()/2-10, getImage().getHeight()/2 , Creature.class);
        return under != null;
    }
    private boolean onGround3Cr()
    {
        Object under = getOneObjectAtOffset(-getImage().getWidth()/2+10, getImage().getHeight()/2 , Creature.class);
        return under != null;
    }
    private boolean onGroundCr()
    {
        return onGround1Cr()||onGround2Cr()||onGround3Cr();
    }
    public boolean onGround()
    {
        return onGroundBc()||onGroundB()||onGroundCA()||onGroundP()||onGroundCr();
    }
    
    private boolean touchingLeftSide1B()
    {
       Box box=(Box)getOneObjectAtOffset(-getImage().getWidth()/2,getImage().getHeight()/2-10,Box.class);
       return box!=null&&box.isThere==true;
    }
    private boolean touchingLeftSide2B()
    {
       Box box=(Box)getOneObjectAtOffset(-getImage().getWidth()/2,-getImage().getHeight()/2+1,Box.class);
       return box!=null&&box.isThere==true;
    }
    private boolean touchingLeftSide3B()
    {
       Box box=(Box)getOneObjectAtOffset(-getImage().getWidth()/2,0,Box.class);
       return box!=null&&box.isThere==true;
    }
    private boolean touchingLeftSideB()
    {
        return touchingLeftSide1B()||touchingLeftSide2B()||touchingLeftSide3B();
    }
    private boolean touchingLeftSide1Bc()
    {
       Object side=getOneObjectAtOffset(-getImage().getWidth()/2,getImage().getHeight()/2-10,Block.class);
       return side!=null;
    }
    private boolean touchingLeftSide2Bc()
    {
       Object side=getOneObjectAtOffset(-getImage().getWidth()/2,-getImage().getHeight()/2+1,Block.class);
       return side!=null;
    }
    private boolean touchingLeftSide3Bc()
    {
       Object side=getOneObjectAtOffset(-getImage().getWidth()/2,0,Block.class);
       return side!=null;
    }
    private boolean touchingLeftSideBc()
    {
        return touchingLeftSide1Bc()||touchingLeftSide2Bc()||touchingLeftSide3Bc();
    }
    private boolean touchingLeftSide1CA()
    {
       Object side=getOneObjectAtOffset(-getImage().getWidth()/2,getImage().getHeight()/2-10,Cliff.class);
       return side!=null;
    }
    private boolean touchingLeftSide2CA()
    {
       Object side=getOneObjectAtOffset(-getImage().getWidth()/2,-getImage().getHeight()/2+1,Cliff.class);
       return side!=null;
    }
    private boolean touchingLeftSide3CA()
    {
       Object side=getOneObjectAtOffset(-getImage().getWidth()/2,0,Cliff.class);
       return side!=null;
    }
    private boolean touchingLeftSideCA()
    {
        return touchingLeftSide1CA()||touchingLeftSide2CA()||touchingLeftSide3CA();
    }
    public boolean touchingLeftSide()
    {
        return touchingLeftSideB()||touchingLeftSideCA()|touchingLeftSideBc();
    }
    
    private boolean touchingRightSide1B()
    {
        Box box=(Box)getOneObjectAtOffset(getImage().getWidth()/2,-getImage().getHeight()/2+1,Box.class);
        return box!=null&&box.isThere==true;
    }
    private boolean touchingRightSide2B()
    {
        Box box=(Box)getOneObjectAtOffset(getImage().getWidth()/2,getImage().getHeight()/2-10,Box.class);
        return box!=null&&box.isThere==true;
    }
    private boolean touchingRightSide3B()
    {
        Box box=(Box)getOneObjectAtOffset(getImage().getWidth()/2,0,Box.class);
        return box!=null&&box.isThere==true;
    }
    public boolean touchingRightSideB()
    {
        return touchingRightSide1B()||touchingRightSide2B()||touchingRightSide3B(); 
    }
    private boolean touchingRightSide1Bc()
    {
        Object side=getOneObjectAtOffset(getImage().getWidth()/2,-getImage().getHeight()/2+1,Block.class);
        return side!=null;
    }
    private boolean touchingRightSide2Bc()
    {
        Object side=getOneObjectAtOffset(getImage().getWidth()/2,getImage().getHeight()/2-10,Block.class);
        return side!=null;
    }
    private boolean touchingRightSide3Bc()
    {
        Object side=getOneObjectAtOffset(getImage().getWidth()/2,0,Block.class);
        return side!=null;
    }
    public boolean touchingRightSideBc()
    {
        return touchingRightSide1Bc()||touchingRightSide2Bc()||touchingRightSide3Bc(); 
    }
    private boolean touchingRightSide1CA()
    {
        Object side=getOneObjectAtOffset(getImage().getWidth()/2,-getImage().getHeight()/2+1,Cliff.class);
        return side!=null;
    }
    private boolean touchingRightSide2CA()
    {
        Object side=getOneObjectAtOffset(getImage().getWidth()/2,getImage().getHeight()/2-20,Cliff.class);
        return side!=null;
    }
    private boolean touchingRightSide3CA()
    {
        Object side=getOneObjectAtOffset(getImage().getWidth()/2,0,Cliff.class);
        return side!=null;
    }
    public boolean touchingRightSideCA()
    {
        return touchingRightSide1CA()||touchingRightSide2CA()||touchingRightSide3CA(); 
    }
    public boolean touchingRightSide()
    {
        return touchingRightSideB()||touchingRightSideCA()||touchingRightSideBc(); 
    }
    
    public void setVSpeed(int speed)
    {
        vSpeed = speed;
    }
    
    public void fall()
    {
        bump();
        setLocation ( getX(), getY() + vSpeed);
        vSpeed = vSpeed + acceleration;
        if ( atBottom() )
            gameEnd();
    }
    
    private boolean atBottom()
    {
        return getY() >= getWorld().getHeight() - 2;
    }
    
    public void gameEnd()
    {
        Scene scene=(Scene)getWorld();
        scene.lives--;
        scene.reset();
        scene.levelUp();
    }

    public void bump()
    {
        if (onTop()||onTop2())
        {
            if(!hasHit)
            {
                vSpeed=-vSpeed;
            }
            hasHit=true;
        }
        if(onGround())
        {
            hasHit=false;
        }
    }
}
import greenfoot.*;

/**
 * A little penguin that wants to get to the other side.
 */
public class Pengu extends Mover
{
    private static final int jumpStrength = 23;
    private int timer=0;
    private int delay=0;
    private static final int gunReload=5;
    public Pengu()
    {
        setImage(new GreenfootImage("pengu-right2.png"));
    }
    public void act() 
    {
        Scene scene=(Scene)getWorld();
        if(!scene.pause)
        {
            delay++;
            shoot();
            shooting();
            coins();
            checkKeys();       
            checkFall();
        }
    }
    
    private void checkKeys()
    {
        Scene scene=(Scene)getWorld();
        if (Greenfoot.isKeyDown("left")&&getX()>=20 )
        {
            scene.direction=false;
            if(!scene.shooting)
            {
                setImage("pengu-left2.png");
            }
            else if(scene.shooting=true)
            {
                setImage("pengu-left2Shooting.png");
            } 
            if(!touchingLeftSide())
            moveLeft();
        }
        changeMove();
        if (Greenfoot.isKeyDown("right")&&scene.move==false)
        {
            scene.direction=true;
            if(!scene.shooting)
            {
                setImage("pengu-right2.png");
            }
            else if(scene.shooting=true)
            {
                setImage("pengu-right2Shooting.png");
            }
            if(!touchingRightSide())
               moveRight();
        }
        if (Greenfoot.isKeyDown("up") )
        {
            if (onGround())
                jump();
        }
    }    
    
    private void jump()
    {
        Scene scene=(Scene)getWorld();
        setVSpeed(-jumpStrength);
        fall();
    }
    private boolean checkDoor()
    {
        return isTouching(Door.class)||isTouching(DoorPost.class);
    }
    private void checkFall()
    {
        if (onGround()) {
            setVSpeed(0);
            Actor under = getOneObjectAtOffset(0, getImage().getHeight()/2 , null);
            if(!checkDoor())
            {
                if(under!=null)
                {
                    int h=under.getImage().getHeight()/2+getImage().getHeight()/2-5;
                    int y=under.getY();
                    setLocation(getX(),y-h);
                }
            }
        }
        else {
            fall();
        }
        
    }
    private void coins()
    {
        Scene scene=(Scene)getWorld();
        Coin coin=(Coin)getOneIntersectingObject(Coin.class);
        if(coin!=null)
        {
            scene.removeObject(coin);
            scene.score=scene.score+100;
            scene.coins=scene.coins+1;
        }
    }
    private void changeMove()
    {
        Scene scene=(Scene)getWorld();
        if(getX()>=342&&scene.onCloud==false)
        {
            scene.move=true;
        }
        else if(getX()<342||touchingRightSide())
        {
            scene.move=false;
        }
        if(scene.isDoor==true)
        {
            scene.move=false;
        }
    }
    private void shoot()
    {
        Scene scene=(Scene)getWorld();
        if(Greenfoot.isKeyDown("space")&&delay>=gunReload&&scene.shooting==true)
        {
            if(scene.direction==false)
            {
                scene.addObject(new Bullet(-7),getX()-26,getY());
            }
            if(scene.direction==true)
            {
                scene.addObject(new Bullet(7),getX()+26,getY());
            }
            delay=0;
        }
    }
    private void shooting()
    {
        Scene scene=(Scene)getWorld();
        if(isTouching(Shooting.class))
        {
            scene.shooting=true;
            removeTouching(Shooting.class);
        }
        if(scene.shooting)
        {
            if(scene.direction==false)
            {
                setImage("pengu-left2Shooting.png");
            }
            if(scene.direction==true)
            {
                setImage("pengu-right2Shooting.png");
            }
        }
        else if(!scene.shooting)
        {
            if(scene.direction==false)
            {
                setImage("pengu-left2.png");
            }
            if(scene.direction==true)
            {
                setImage("pengu-right2.png");
            }
        }
    }
}
is there any reason that the touchingRightSide() method should not b true even if something is there and it should be true bec. sometimes its not true wen it should be
Super_Hippo Super_Hippo

2016/11/20

#
Do you mean it is true if it should not be and the other way around? (I am confused by this 'should' in your sentence.) I am pretty sure that you don't need so many methods for collision checking. Two things: first, I don't know what the changeMove-method in the Pengu class should do. Second, in line 224 in the Mover class, you use | instead of || once. I am not sure if it is a difference in the result, but I think you should use || everywhere. Well, this is in the touchingLeftSide and not right side though...
Nosson1459 Nosson1459

2016/11/21

#
sometimes 4 some reason wen theres something there it just goes right through it as if all my collision detection doesnt exist and the reason i hav so many collision detecting methods is bec. i hav lots of other classes that i dont want to detct so passing null would cause problems and thnx 4 that correction and the changeMove() method is 4 the side scrolling in all the objects that move theres an if that checks if move==true if it does then they move if not they dont the changeMove() tells them whether or not to move and 4 some reason the 2nd part of line 117 doesnt work and wen getX()>342 and theres something in the way it just goes right through
danpost danpost

2016/11/21

#
Nosson1459 wrote...
the changeMove() method is 4 the side scrolling in all the objects that move theres an if that checks if move==true if it does then they move if not they dont the changeMove() tells them whether or not to move
Instead of the 'move' field, you can place the following line in all classes that creates objects you do not want to move:
public void setLocation(int x, int y) { }
That will override the 'setLocation(int, int)' method of the Actor class and remove its implementation; thereby, making it immune to relocating.
4 some reason the 2nd part of line 117 doesnt work and wen getX()>342 and theres something in the way it just goes right through
If 'onCloud' is false, then the second part of line 117 is irrelevant as the condition on line 13 was true and the else part is therefore ignored. You can probably replace lines 113 through 120 with the following:
scene.move = getX() >= 342 && ! scene.onCloud && ! touchingRightSide();
Nosson1459 Nosson1459

2016/11/21

#
i dont want them to move continuously and cud u plz explain with a little more detail it seems like u may hav contradicted urself and im all confused
Nosson1459 Nosson1459

2016/11/21

#
but ur coding worked so whatever no explanation necessary
danpost danpost

2016/11/21

#
Nosson1459 wrote...
but ur coding worked so whatever no explanation necessary
I will explain, anyway. The condition for setting 'scene.move' to true are what I have shown: x-coordinate must be at least 342; and must not be on cloud; and must not be touching anything at right The conditions for setting 'scene.move' to false are just the opposite: x-coordinate is below 342; or on cloud; or touching something at right So, instead of using 'if-else if' (which got a bit confusing), I made a simple assignment statement out of it.
Nosson1459 Nosson1459

2016/11/21

#
not that everything before it
danpost danpost

2016/11/21

#
Nosson1459 wrote...
not that everything before it
Where exactly do you think I contradicted myself?
You need to login to post a reply.