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

2014/5/21

Move method isn't working

mandyg233 mandyg233

2014/5/21

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
 * Write a description of class Victor here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Victor extends Actor
{
    private int Walk = (0);

    private static final String[ ] IMAGES = {"Stick1.png", "Limp2.png"};
    private static final int RATE = 10;
    private static GreenfootImage[] backgroundarray = new GreenfootImage[100];  

    public Victor()  
    {
        if (backgroundarray[1] == null)  
        {  
            backgroundarray[1] = new GreenfootImage("Crazy123.png");  

            backgroundarray[2] = new GreenfootImage("Inside.jpg");
            backgroundarray[3] = new GreenfootImage("Black.png");

        }
    }

    public void act() 
    {
        doThis();
    }
    public void doThis()
    {
        getWorld().removeObjects(getWorld().getObjects(Sled.class));  
        if (getX() >1185 && getY() ==565)
        {
            Walk = (Walk+1)%(RATE*IMAGES.length);  
            if (Walk%RATE==0)  
            {  
                setImage(IMAGES[Walk/RATE]);  

            }
            move(-3);

        }
        if (getX() ==1185 && getY() == 565)
        {
            FWorld.labelW.setText("WHO IS that?");
            Greenfoot.delay(30);
            FWorld.labelW.setText("Let's find out!");
            Greenfoot.delay(50);

            getWorld().setBackground(new GreenfootImage("Inside.jpg"));

            setLocation(1025,523);
            getWorld().removeObjects(getWorld().getObjects(Boat.class));  
            FWorld.labelW.setText("");
            getWorld().addObject (new Walton(), 832, 279);
            FWorld.labelW.setText("Hi");
            Greenfoot.delay(50);
            FWorld.label2.setText("Hi");
            Greenfoot.delay(40);
            FWorld.labelW.setText("      Who are \nyou?");
            FWorld.label2.setText("");
            Greenfoot.delay(50);
            FWorld.labelW.setText("");
            FWorld.label2.setText("Call me \n V. Frankenstein.");
            Greenfoot.delay(30);
            FWorld.label2.setText("One time...");

            Greenfoot.delay(50);
            FWorld.label2.setText("");

            getWorld().setBackground(new GreenfootImage("Crazy123.png"));

            Greenfoot.playSound("thunder12.mp3");

            getWorld().removeObjects(getWorld().getObjects(Walton.class));  
            setLocation(100,200);
            Greenfoot.delay(300);
            getWorld().setBackground(new GreenfootImage("Inside.jpg"));
            setLocation(1025,523);

            getWorld().addObject (new Walton(), 832, 279);
            FWorld.label2.setText("That was \na bad idea.");
            Greenfoot.delay(60);

            FWorld.label2.setText("But yeah\n I didn't like it.");
            Greenfoot.delay(50);
            FWorld.label2.setText("I wanted\n nothing to\n do with it.");
            Greenfoot.delay(30);
            FWorld.labelW.setText("           Makes\n           sense.");
            Greenfoot.delay(30);
            FWorld.labelW.setText("");
            FWorld.label2.setText("");
            getWorld().setBackground(new GreenfootImage("Black.png"));
            getWorld().removeObjects(getWorld().getObjects(Walton.class));  
            setLocation(100,400);

            getWorld().addObject (new Creature(), 832, 279);
            Greenfoot.delay(10);
            FWorld.labelC.setText("NO IT DOESN'T.");
            Greenfoot.delay(40);
            FWorld.labelC.setText("He was my father.");
            Greenfoot.delay(40);
            FWorld.labelC.setText("He left me to die.");
            Greenfoot.delay(40);
            FWorld.labelC.setText("All I wanted was a friend.");
            Greenfoot.delay(40);
            FWorld.labelC.setText("But I had nobody.");
            FWorld.labelC.setText("I asked V to give \nme a female friend.");
            Greenfoot.delay(40);
            FWorld.labelC.setText("He said yes.");
            Greenfoot.delay(40);
            FWorld.labelC.setText("He lied.");
            Greenfoot.delay(40);
            FWorld.labelC.setText("I was angry and \n acted out");
            Greenfoot.delay(40);
            getWorld().addObject (new Tomb(), 400, 279);
            Greenfoot.delay(60);
            FWorld.labelC.setText("Then he came after me.");
            getWorld().removeObjects(getWorld().getObjects(Tomb.class));  
            FWorld.labelC.setText("");
            
            pleaseWork();



        }

        //         if            ( getX() >= 100)
        //         {
        //         Greenfoot.delay(390);
        //         move(15);
        //     }

        
    }
    
    
    public void pleaseWork()
    {
        move(15);
        
        
    }
    
    
}  
//       
danpost danpost

2014/5/21

#
If you wanted the movement before (or between) the dialogs then line 126 needs to be moved outside the 'if' block (maybe to line 138).
mandyg233 mandyg233

2014/5/22

#
No, I want the dialogs to happen first, then the movement to start.
mandyg233 mandyg233

2014/5/22

#
Does it matter where the pleaseWork() method is called, like if it is called after line 35 on to line 138 would those two codes be the same? I tried moving it to 138 and there was a different problem, Victor never made it to 1185, 565
danpost danpost

2014/5/22

#
mandyg233 wrote...
Does it matter where the pleaseWork() method is called, like if it is called after line 35 on to line 138 would those two codes be the same? I tried moving it to 138 and there was a different problem, Victor never made it to 1185, 565
Yes, it makes a big difference. If at line 36, Victor will find the right edge of the world and stop near it. If placed between 46 and 47, Victor will find the right edge of the world and stop at it. If placed where you have it above, Victor will find (115, 400) and stop there. Maybe you need to add a boolean field to track whether the dialog has taken place or not. Put everything from line 36 to 125 in an enclosing 'if' block governed by 'if (!pastDialog)'. Then have an 'else' part for the final moving. Of course, you will need to set the 'pastDialog' field to 'true' when the dialog is taking place.
mandyg233 mandyg233

2014/5/22

#
That works!
You need to login to post a reply.