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

2016/11/22

The game does not what I want.

Lars2501 Lars2501

2016/11/22

#
I have to make a game for a schoolproject. The only thing is that the game does not what I want the game to do. What I want is that if all three my characters are standing on a button. You pass that level and you move on to the next one. I do have the code but I don't know how to use themCan someone please help me? Sorry for my horrible English. This one is from the world.
public class Super2 extends World
{

    /**
     * Constructor for objects of class Super2.
     * 
     */
    public Super2()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(12, 12, 60); 
                      
        addObject (new BButton(), 3,5);
        addObject (new GButton(), 2,7);
        addObject (new RButton(), 2,6);
        addObject (new Minion(), 2,2);
        addObject (new Hulk(), 3,2);
        addObject (new Ironman(), 2,3);
        addObject (new Spike(), 2,4);
        addObject (new DO(), 2,4);
        addObject (new Spike(), 3,4);
        addObject (new DO(), 3,4);

        
        
        /**
         * Aan de bovenkant speelwereld
         */
        addObject (new DO(), 1,1);
        addObject (new DO(), 2,1);
        addObject (new DO(), 3,1);
        addObject (new DO(), 4,1);
        addObject (new DO(), 5,1);
        addObject (new DO(), 6,1);
        addObject (new DO(), 7,1);
        addObject (new DO(), 8,1);
        addObject (new DO(), 9,1);
        addObject (new DO(), 10,1);
        
        /**
         * Aan de onderkant speelwereld
         */
        addObject (new DO(), 1,10);
        addObject (new DO(), 2,10);
        addObject (new DO(), 3,10);
        addObject (new DO(), 4,10);
        addObject (new DO(), 5,10);
        addObject (new DO(), 6,10);
        addObject (new DO(), 7,10);
        addObject (new DO(), 8,10);
        addObject (new DO(), 9,10);
        addObject (new DO(), 10,10);
        
        /**
         * Aan de linkerkant speelwereld
         */
        addObject (new DO(), 1,2);
        addObject (new DO(), 1,3);
        addObject (new DO(), 1,4);
        addObject (new DO(), 1,5);
        addObject (new DO(), 1,6);
        addObject (new DO(), 1,7);
        addObject (new DO(), 1,8);
        addObject (new DO(), 1,9);
        
        /**
         * Aan de rechterkant speelwereld
         */
        addObject (new DO(), 10,2);
        addObject (new DO(), 10,3);
        addObject (new DO(), 10,4);
        addObject (new DO(), 10,5);
        addObject (new DO(), 10,6);
        addObject (new DO(), 10,7);
        addObject (new DO(), 10,8);
        addObject (new DO(), 10,9);
        
        /**
         * In het midden speelwereld
         */
        addObject (new DO(), 4,4);
        addObject (new DO(), 5,4);
        addObject (new DO(), 6,4);
        addObject (new DO(), 7,4);
        addObject (new DO(), 8,4);
        addObject (new DO(), 4,5);
        addObject (new DO(), 5,5);
        addObject (new DO(), 6,5);
        addObject (new DO(), 7,5);
        addObject (new DO(), 8,5);
        addObject (new DO(), 4,6);
        addObject (new DO(), 5,6);
        addObject (new DO(), 6,6);
        addObject (new DO(), 7,6);
        addObject (new DO(), 8,6);
        addObject (new DO(), 4,7);
        addObject (new DO(), 5,7);
        addObject (new DO(), 6,7);
        addObject (new DO(), 7,7);
        addObject (new DO(), 8,7);
        addObject (new DO(), 4,8);
        addObject (new DO(), 5,8);
        addObject (new DO(), 6,8);
        addObject (new DO(), 7,8);
        addObject (new DO(), 8,8);
    }
    public void act()
    {
        if(!ready() && getObjects(Complete.class).size() == 1)
        {
         Greenfoot.delay(200);
         Greenfoot.setWorld(new Instructiescherm2());
        }
    }
    public boolean ready()
    {
        return getObjects(Complete2.class).size() == 2;
    }
}
this one is from one of my characters:
public class Hulk extends Actor
{
    /**
     * Act - do whatever the Hulk wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(12);
        if(getX() == 2 && getY() ==7)      
        {        
          getWorld().addObject(new Complete(),6,6);
        }
    }  
    public void move(int moveAmt)  
       {  
       int dx = 0, dy = 0;  
       if (Greenfoot.isKeyDown("d")) dx += 1;  
       if (Greenfoot.isKeyDown("a")) dx -= 1;  
       if (Greenfoot.isKeyDown("s")) dy += 1;  
       if (Greenfoot.isKeyDown("w")) dy -= 1;  
       
       for (int i = 0; i < moveAmt; i++)  
       {
       setLocation(getX() + dx, getY());  
       if (getOneIntersectingObject(DO.class) != null) setLocation(getX() - dx, getY());
       if (getOneIntersectingObject(Minion.class) != null) setLocation(getX() - dx, getY());
       if (getOneIntersectingObject(Ironman.class) != null) setLocation(getX() - dx, getY());
       setLocation(getX(), getY() + dy);    
       if (getOneIntersectingObject(DO.class) != null) setLocation(getX(), getY() - dy);
       if (getOneIntersectingObject(Minion.class) != null) setLocation(getX(), getY() - dy);
       if (getOneIntersectingObject(Ironman.class) != null) setLocation(getX(), getY() - dy);
       }
    }
   
    {
     if (Greenfoot.isKeyDown("a"))
     {
        move(-1);
     }   
     if (Greenfoot.isKeyDown("d"))
     {
        move(1);
     }
     if (Greenfoot.isKeyDown("w"))
     {
        setLocation(getX(), getY() - 1); 
     }
     if (Greenfoot.isKeyDown("s"))
     {
        setLocation(getX(), getY() + 1); 
     }
    } 
}
danpost danpost

2016/11/22

#
Lines 36 through 53 should probably be removed. They cannot execute before the actor is placed into a world or before the project begins running. Moving '12' (line 9 of the Hulk class) does not really make sense unless you want your character to "teleport" to any obstacle in its path or possibly pass up the checked location (2, 7). Moving '1' should be sufficient.
Lars2501 Lars2501

2016/11/22

#
Actually what I want is that the actor goas all the way from one side to the other. It is the same as the game "Minionslab". But my question was; What I want is that if all three my characters are standing on a button. You pass that level and you move on to the next one. I do have the code but I don't know how to use themCan someone please help me?
Super_Hippo Super_Hippo

2016/11/22

#
Are the three characters objects from three different classes? Then the code could be this (in the button act method).
if (isTouching(Class1.class) && isTouching(Class2.class) && isTouching(Class3.class))
{
    Greenfoot.setWorld(new World2());
}
Lars2501 Lars2501

2016/11/23

#
Thanks @Super_Hippo. The only problem is that I have three different Buttons. What do I have to than?
Super_Hippo Super_Hippo

2016/11/23

#
Maybe this could work for you:
//Super2 class
private ButtonB buttonB = new Button1();
private ButtonG buttonG = new Button2();
private ButtonR buttonR = new Button3();

//when creating the world
addObject(buttonB, 3, 5);
addObject(buttonG, 2, 7);
addObject(buttonR, 2, 6);

//in act method
if (buttonB.finish() && buttonG.finish() && buttonR.finish())
{
    Greenfoot.setWorld(new Super3());
}
And then, in the button classes, you can have this method:
public boolean finish()
{
    if (isTouching(Hulk.class)) //not sure if it should be Hulk here. The one which has to be on the button
    {
        return true;
    }
    else
    {
        return false;
    }
}
Lars2501 Lars2501

2016/11/24

#
Thanks a lot bro you helped me a lot there
You need to login to post a reply.