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

2016/11/25

Earthquakes

1
2
Nosson1459 Nosson1459

2016/11/29

#
The pengu is also being moved from sideScrolling in scene which makes it move -7, then +7 from pressing the right arrow key, so it's vibrating to < and then > 342 so move is false then true then false etc., and you can't put the empty setLocation method in it cause then it doesn't move at all!
Nosson1459 Nosson1459

2016/11/30

#
danpost wrote...
In your code, 'actors' is a List object and there is no 'setLocation' method for a List object. See lines 131 through 135 of the class referenced here.
With the getObjects it includes the pengu and moves it left 7 pixels when I'm holding down the right arrow key so it's moved from 342 where move is true to 335 and then move is false then it jumps back to 342 and move is true again etc. so the penguin is doing big vibrations which doesn't look so good, and I can't put
public void setLocation(int x, int y){}
in pengu because then it won't move at all. What should I do with pengu using the side-scrolling discussed above? (I'm posting this (again) because my yesterdays post wasn't answered!) Here is the updated Scene code:
 import greenfoot.*; 
/**
 * 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=1;
    private int a=1;
    public int moveSpeed=-7;
    public int addObjects;
    private int addObjectsAt=375;
    public boolean move=false;
    public boolean direction=true;
    public boolean onCloud=false;
    public boolean way=true;
    public boolean shooting=false;
    public boolean pause=false;
    public boolean isDoor=false;
    public boolean startToMove=false;
    public boolean isThere=false;
    private Pengu pengu;
    public Scene()
    {  
        super(750,650,1,false);
        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,285);
                Greenfoot.stop();
            }
            if(coins==100)
            {
                score+=500;
                lives++;
                coins=0;
            }
            sideScrolling();
            levelAct();
        }
    }
    public void reset(boolean shoot)
    {
        removeObjects(getObjects(Platform.class));
        removeObjects(getObjects(Bullet.class));
        removeObjects(getObjects(Boxes.class));
        removeObjects(getObjects(Pengu.class));
        removeObjects(getObjects(Cliff.class));
        removeObjects(getObjects(Coin.class));
        removeObjects(getObjects(Monster.class));
        removeObjects(getObjects(ExtraLife.class));
        removeObjects(getObjects(Shooting.class));
        removeObjects(getObjects(Door.class));
        removeObjects(getObjects(DoorPost.class));
        isDoor=false;
        startToMove=false;
        move=false;
        onCloud=false;
        if(shoot)shooting=false;
        a=1;
    }
    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(),375,325);
            addObject(new EndScore(),375,285);
        }
    }
    public void level1()
    {
        pengu=new Pengu();
        addObject(pengu,192,470);
        for(int j=20;j<481;j+=40)
        {
            for(int i=510;i<631;i+=40)
            {
                addObject(new Block(2),j,i);
            }
        }
        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()
    {
        reset(false);
        pengu=new Pengu();
        addObject(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,440);
        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<2726;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;
        }
        addObject(new Creature(),2400,440);
        int c=509;
        for(int j=2805;j<2966;j+=40)
        {
            for(int i=510;i>c;i-=40)
            {
                addObject(new Block(2),j,i);
            }
            if(j>2805)
            c=389;
        }
        int g=590;
        int h=509;
        for(int j=2765;j<3206;j+=40)
        {
            for(int i=g;i>h;i-=40)
            {
                addObject(new Block(4),j,i);
            }
            if(j==2765)
            h+=40;
            if(j>2925)  
            h-=40;
            if(j>2965)
            g-=40;
        }
        int d=629;
        for(int j=2765;j<3206;j+=40)
        {
            for(int i=630;i>d;i-=40)
            {
                addObject(new Block(2),j,i);
            }
            if(j>2965)
            d-=40;
        }
        int e=470;
        int f=389;
        for(int j=3005;j<3206;j+=40)
        {
            for(int i=e;i>f;i-=40)
            {
                addObject(new Block(2),j,i);
            }
            e-=40;
            if(j>3005)
            f-=40;
        }
        addObject(new SnakeD(),3100,359);
        for(int i=2765;i<2966;i+=40)
        {
            addObject(new Coin(),i,595);
        }
        for(int i=2885;i<3086;i+=40)
        {
            addObject(new Coin(),i,275);
        }
        for (int j=3305; j<3546; j+=40)
        {
            for (int i=486; i<647; i+=40)
            {
                addObject(new Block(3),j,i);
            }
        }
        addObject(new Door(),3492,433);
        addObject(new DoorPost(),3492,433);
    }
    private void level2Act()
    {
    }
    private void sideScrolling()
    {
        move = pengu.getX() >= 342 && ! onCloud && ! pengu.touchingRightSide();
        if(isDoor==true||pengu.getX()<342)
        {
            move=false;
        }
        if(Greenfoot.isKeyDown("right")&&move==true)
        {
            for (Object obj: getObjects(null))
            {
                Actor actor=(Actor) obj;
                actor.setLocation(actor.getX()-7, actor.getY());
            }
        }
        if(onCloud==true)
        {
            for (Object obj: getObjects(null))
            {
                Actor actor=(Actor) obj;
                if(way==true)
                {
                    actor.setLocation(actor.getX()-4,actor.getY());
                }
                if(way==false)
                {
                    actor.setLocation(actor.getX()+4,actor.getY());
                }
            }
        }
    }
    public void help()
    {
        addObject(new Help(),375,325);
    }
    public void help2()
    {
        removeObjects(getObjects(Help.class));
    }
    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;
            }
        }
        
         
    }
}
Here is the Mover class which Pengu extends from (not posted previously):
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 abstract 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()
    {
        Block block=(Block) getOneObjectAtOffset(-getImage().getWidth()/2+8, -getImage().getHeight()/2 , Block.class);
        return block != null&&block.isThere==true;
    }
    private boolean onTop2Bc()
    {
        Block block=(Block)  getOneObjectAtOffset(0, -getImage().getHeight()/2 , Block.class);
        return block != null&&block.isThere==true;
    }
    private boolean onTop3Bc()
    {
        Block block=(Block) getOneObjectAtOffset(getImage().getWidth()/2-8, -getImage().getHeight()/2 , Block.class);
        return block != null&&block.isThere==true;
    }
    
    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()
    {
        Block block =(Block) getOneObjectAtOffset(0, getImage().getHeight()/2 , Block.class);
        return block != null&&block.isThere==true;
    }
    private boolean onGround2Bc()
    {
        Block block =(Block) getOneObjectAtOffset(getImage().getWidth()/2-10, getImage().getHeight()/2 , Block.class);
        return block != null&&block.isThere==true;
    }
    private boolean onGround3Bc()
    {
        Block block =(Block) getOneObjectAtOffset(-getImage().getWidth()/2+10, getImage().getHeight()/2 , Block.class);
        return block != null&&block.isThere==true;
    }
    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()
    {
       Block block=(Block)getOneObjectAtOffset(-getImage().getWidth()/2,getImage().getHeight()/2-10,Block.class);
       return block != null&&block.isThere==true;
    }
    private boolean touchingLeftSide2Bc()
    {
       Block block=(Block)getOneObjectAtOffset(-getImage().getWidth()/2,-getImage().getHeight()/2+1,Block.class);
       return block != null&&block.isThere==true;
    }
    private boolean touchingLeftSide3Bc()
    {
       Block block=(Block)getOneObjectAtOffset(-getImage().getWidth()/2,0,Block.class);
       return block != null&&block.isThere==true;
    }
    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()
    {
        Block block=(Block)getOneObjectAtOffset(getImage().getWidth()/2,-getImage().getHeight()/2+1,Block.class);
        return block != null&&block.isThere==true;
    }
    private boolean touchingRightSide2Bc()
    {
        Block block=(Block)getOneObjectAtOffset(getImage().getWidth()/2,getImage().getHeight()/2-10,Block.class);
        return block != null&&block.isThere==true;
    }
    private boolean touchingRightSide3Bc()
    {
        Block block=(Block)getOneObjectAtOffset(getImage().getWidth()/2,0,Block.class);
        return block != null&&block.isThere==true;
    }
    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(true);
        scene.levelUp();
    }

    public void bump()
    {
        if (onTop()||onTop2())
        {
            if(!hasHit)
            {
                vSpeed=-vSpeed;
            }
            hasHit=true;
        }
        if(onGround())
        {
            hasHit=false;
        }
    }
}
Here is the updated Pengu class:
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(!touchingLeftSide())
            moveLeft();
        }
        if (Greenfoot.isKeyDown("left"))
        {
            if(!scene.shooting)
            {
                setImage("pengu-left2.png");
            }
            else if(scene.shooting=true)
            {
                setImage("pengu-left2Shooting.png");
            }
        }
        if (Greenfoot.isKeyDown("right")&&scene.move==false)
        {
            scene.direction=true;
            if(!touchingRightSide())
            
               moveRight();
            
        }
        if (Greenfoot.isKeyDown("right"))
        {
            if(!scene.shooting)
            {
                setImage("pengu-right2.png");
            }
            else if(scene.shooting=true)
            {
                setImage("pengu-right2Shooting.png");
            }
        }
        if (Greenfoot.isKeyDown("up") )
        {
            if (onGround())
                jump();
        }
    }    
    
    private void jump()
    {
        Scene scene=(Scene)getWorld();
        setVSpeed(-jumpStrength);
        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 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");
            }
        }
    }
    public 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 boolean checkDoor()
    {
        return isTouching(Door.class)||isTouching(DoorPost.class);
    }
    //public void setLocation(int x, int y){}
}

    
I tried moving methods checkFall() and checkDoor() from Pengu into Mover, then uncommenting line 163 which is the setLoaction method for pengu , but it still didn't work. I just noticed that I have a problem with the platforms also, I want them to side scroll to get to me, while going back and forth like they've always done, so I can't put the empty setLocation method in them, but then when I go on one (onCloud=true) all actors should move -4 then +4 when it hit's an actor (or in side-scrolling the block or cliff is really hitting it) (the -4 being before +4 depends on the direction boolean) but the for-each loop in scene moves all actors -4 so the blocks, cliffs, and monsters all move but they never switch direction because the platform and pengu are also moving -4 (or +4 if I jump on after it switches direction) so everything just goes off screen and continues moving forever. Here is the Platform class code (just in case):
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Platform here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Platform extends Actor
{
    GreenfootImage image1=new GreenfootImage("paddle.png");
    GreenfootImage image2=new GreenfootImage("paddle2.png");
    GreenfootImage image3=new GreenfootImage("paddle3.png");
    GreenfootImage image4=new GreenfootImage("cloud2.png");
    private int speed = -4;
    private int counter=0;
    private boolean myWay=false;
    public Platform(int image)
    {
        if(image==1)
        setImage(image1);
        if(image==2)
        setImage(image2);
        if(image==3)
        setImage(image3);
        if(image==4)
        setImage(image4);
    }
    /**
     * Move in the direction we are currently moving in. Turn if we reach a turning point.
     */
    public void act() 
    {
        Scene scene=(Scene)getWorld();
        if(!scene.pause)
        {
            Actor actor = getOneIntersectingObject(Pengu.class);
            if(actor != null) 
            {
                scene.onCloud=true;
            
            }
            else
            {
                scene.onCloud=false;
            }
            if(!scene.onCloud)
            {
                move(speed);
            }
            turnBool();
            direction();
            remove();
        }
    }
    private void direction()
    {
        if(rightSide())
        {
            myWay=false;
        }
        else if(leftSide())
        {
            myWay=true;
        }
        if(myWay==true)
        {
            speed=4;
        }
        else if(myWay==false)
        {
            speed=-4;
        }
    }
    private void remove()
    {
        Scene scene=(Scene)getWorld();
        if(getX()<=-500)
        {
            scene.removeObject(this);
        }
    }
    private boolean rightSide()
    {
        Actor side=getOneObjectAtOffset(getImage().getWidth()/2+32,0,null);
        return side!=null;
    }
    private boolean rightSide2()
    {
        Actor side=getOneObjectAtOffset(getImage().getWidth()/2,0,null);
        return side!=null;
    }
    private boolean edge()
    {
        return getX()>=920;
    }
    private boolean leftSide()
    {
        Actor side=getOneObjectAtOffset(-getImage().getWidth()/2-36,0,null);
        return side!=null;
    }
    private void turnBool()
    {
        Scene scene=(Scene)getWorld();
        if(rightSide())
        {
            scene.way=false;
        }
        if(leftSide())
        {
           scene.way=true;
        }
    }
    //public void setLocation(int x, int y){}
}
Nosson1459 Nosson1459

2016/11/30

#
i changed line 342 to
if(obj!=Pengu.class)actor.setLocation(actor.getX()-7, actor.getY());
and it still moved the pengu back 7
danpost danpost

2016/11/30

#
Nosson1459 wrote...
i changed line 342 to
if(obj!=Pengu.class)actor.setLocation(actor.getX()-7, actor.getY());
and it still moved the pengu back 7
The 'if' condition here will always be true. No Actor object is a Class object. I think you meant to try:
if (obj instanceof Pengu)....
However, if you utilize that, then the Pengu object will not scroll with everything else. It will not work the way you might think.
Nosson1459 Nosson1459

2016/12/1

#
Nosson1459 wrote...
The pengu is also being moved from sideScrolling in scene which makes it move -7, then +7 from pressing the right arrow key, so it's vibrating to < and then > 342 so move is false then true then false etc., and you can't put the empty setLocation method in it cause then it doesn't move at all!
Nosson1459 wrote...
With the getObjects it includes the pengu and moves it left 7 pixels when I'm holding down the right arrow key so it's moved from 342 where move is true to 335 and then move is false then it jumps back to 342 and move is true again etc. so the penguin is doing big vibrations which doesn't look so good, and I can't put
public void setLocation(int x, int y){}
in pengu because then it won't move at all. What should I do with pengu using the side-scrolling discussed above? (I'm posting this (again) because my yesterdays post wasn't answered!) I tried moving methods checkFall() and checkDoor() from Pengu into Mover, then uncommenting line 163 which is the setLoaction method for pengu , but it still didn't work. I just noticed that I have a problem with the platforms also, I want them to side scroll to get to me, while going back and forth like they've always done, so I can't put the empty setLocation method in them, but then when I go on one (onCloud=true) all actors should move -4 then +4 when it hit's an actor (or in side-scrolling the block or cliff is really hitting it) (the -4 being before +4 depends on the direction boolean) but the for-each loop in scene moves all actors -4 so the blocks, cliffs, and monsters all move but they never switch direction because the platform and pengu are also moving -4 (or +4 if I jump on after it switches direction) so everything just goes off screen and continues moving forever.)
Neither of the above posts were answered and they were posted one after the other. The first one was posted 2 days before the time THIS post was typed (right now for me), and the second was posted yesterday (or 22 hours ago). Now you replied but you didn't mention anything of these two posts only the last one (not quoted above) you said what was wrong with the if but you didn't say how to fix this problem you only replied to the last post. What happened to the other one(s), if you don't know how to solve the problem, then say so instead of keeping me asking. If you DO know how, then why aren't you saying so after all these posts and all this time (I have this problem with almost every discussion, it takes about 2 posts of the same question, and about 2-3 days to get the answer to the original discussion question).
Nosson1459 Nosson1459

2016/12/1

#
Should/could I just change the getObjects to get multiple different objects, or should/could I do a separate loop for each actor that I want to side-scroll, or are none of these good ways to solve the side-scrolling problem (make sure you read the previous post (it explains how it seems that you don't read the previous posts, even if you never read them before))?
danpost danpost

2016/12/1

#
Nosson1459 wrote...
Should/could I just change the getObjects to get multiple different objects, or should/could I do a separate loop for each actor that I want to side-scroll, or are none of these good ways to solve the side-scrolling problem (make sure you read the previous post (it explains how it seems that you don't read the previous posts, even if you never read them before))?
Use 'getObjects(null)' to get all actors. Add the 'setLocation' line given into classes you do not want to have scroll (you want the Pengu class to scroll). If the Pengu actor is vibrating (like you said), then try controlling its horizontal movement from the world class, too. Have it move and then scroll everything depending on the location of pengu (to set pengu back to center when needed). Your code is extremely complicated and bulky (about 1000 lines of code given among the different classes in this thread). It is complicated by the use of multiple unnecessary boolean fields that allows you to break things up and spread them out within your code making it very difficult to determine what is happening where. It makes it almost impossible to give you a simple solution to your issues. I can only make suggestions as to where to proceed -- not give you concrete solutions. I have already read all your posts -- and others are allowed to assist if they wish when I cannot immediately give you any suggestions. It is better to leave something unanswered for that reason (they might think it is answered and decide not even to look at it).
Nosson1459 Nosson1459

2016/12/1

#
being that u answer every single persons questions i dont think anybody answers any questions anymore besides 4 u so leaving a question open is leaving it unanswered, its a bit to late to "let other people answer"
danpost danpost

2016/12/1

#
Nosson1459 wrote...
being that u answer every single persons questions i dont think anybody answers any questions anymore besides 4 u so leaving a question open is leaving it unanswered, its a bit to late to "let other people answer"
I may answer the majority of them -- but not all; and Super_Hippo does often reply to some of the threads. Even you have chimed in on a few. Occasionally, davmac will respond to a thread, as well.
Nosson1459 Nosson1459

2016/12/1

#
either way i fixed da problem by putting all the SideScrollers under a class called SideScrollers and the for each loop gets all the objects of class SideScrollers
Nosson1459 Nosson1459

2016/12/1

#
danpost wrote...
Even you have chimed in on a few.
so i shud answer my own questions??????????????????
You need to login to post a reply.
1
2