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

2013/2/17

getIntersectingObject

1
2
3
4
5
6
7
danpost danpost

2016/4/22

#
You must be manually placing objects into your world. The 'prepare' method is empty! Other than that, which is nothing, the only thing this code provides is the size of the world. With that size, you are resetting the location of the Player1 object two-thirds across the world when interscting the KimJongUn object and having it move right from there. But without knowing where you are originally placing the object, no help can be provided. Manually place the objects in the world where you want them to start and before starting, select from the menubar 'Controls>Save the world'. Then repost the Background class.
DJ_KASKO DJ_KASKO

2016/4/22

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Background here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Background extends World
{

    /**
     * Constructor for objects of class Background.
     * 
     */
    public Background()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 

        prepare();
    }

    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        Counter counter = new Counter();
        addObject(counter,61,29);
        counter.setLocation(53,22);
        Player1 player1 = new Player1(counter);
        addObject(player1,20,162);
        KimJongUn kimjongun = new KimJongUn();
        addObject(kimjongun,309,190);
        Counter counter2 = new Counter();
        addObject(counter2,547,34);
        counter2.setLocation(547,27);
        removeObject(counter2);
    }
}
OK so i put it all in where i want it the only thing i dint do is put the second player in and its counter because that is not updated and i will just copy player 1's code and then later i might need your help with it but thats not important at the moment
DJ_KASKO DJ_KASKO

2016/4/22

#
yo you still there man?
danpost danpost

2016/4/22

#
Okay, add the following methods to your Background class for testing purposes:
public void act()
{
    if (Greenfoot.mouseClicked(null))
    {
        printStats();
    }
}

public void printStats()
{
    Actor player = (Actor)getObjects(Player1.class).get(0);
    System.out.println("\n\nPLAYER");
    System.out.println("    x:  "+player.getX())
    System.out.println("    y:  "+player.getY())
    System.out.println("    image width:  "+player.getImage().getWidth());
    System.out.println("    image height:  "+player.getImage().getHeight());
    Actor kimJongUn = (Actor)getObjcts(KimJongUn.class).get(0);
    System.out.println("\nKIM JONG UN");
    System.out.println("    x:  "+kimJongUn .getX())
    System.out.println("    y:  "+kimJongUn .getY())
    System.out.println("    image width:  "+kimJongUn .getImage().getWidth());
    System.out.println("    image height:  "+kimJongUn .getImage().getHeight());
}
Then prepare the world and before starting it, right click on the world background and select to execute the 'printStats' method. Then move the speed slider to about one-quarter speed (half way between the left end and the middle. Next, start the scenario and alternate tapping on the "up" key and clicking on the background of the world. Do this until the player should return to start over again. Take the entire output from the new code and post the results here.
DJ_KASKO DJ_KASKO

2016/4/22

#
it says cannot find symbol on getObjects LINE Actor kimJongUn = (Actor)getObjcts(KimJongUn.class).get(0);
danpost danpost

2016/4/22

#
I appears you are starting the Player1 object at an x coordinate value of '20'. Maybe that is where it should go back to when intersecting the KimJongUn object..
danpost danpost

2016/4/22

#
DJ_KASKO wrote...
it says cannot find symbol on getObjects LINE Actor kimJongUn = (Actor)getObjcts(KimJongUn.class).get(0);
That was just a misspelling. Correct it.
DJ_KASKO DJ_KASKO

2016/4/22

#
no no i found out why it is bbecause you spelt objects wrong but i am trying it out know.
DJ_KASKO DJ_KASKO

2016/4/22

#
it did not do anything different it is still the same
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Background here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Background extends World
{

    /**
     * Constructor for objects of class Background.
     * 
     */
    public Background()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 

        prepare();
    }

    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        Counter counter = new Counter();
        addObject(counter,61,29);
        counter.setLocation(53,22);
        Player1 player1 = new Player1(counter);
        addObject(player1,20,162);
        KimJongUn kimjongun = new KimJongUn();
        addObject(kimjongun,309,190);
        Counter counter2 = new Counter();
        addObject(counter2,547,34);
        counter2.setLocation(547,27);
        removeObject(counter2);
    }

    public void act()
    {
        if (Greenfoot.mouseClicked(null))
        {
            printStats();
        }
    }

    public void printStats()
    {
        Actor player = (Actor)getObjects(Player1.class).get(0);
        System.out.println("PLAYER");
        System.out.println("    x:  "+player.getX());
        System.out.println("    y:  "+player.getY());
        System.out.println("    image width:  "+player.getImage().getWidth());
        System.out.println("    image height:  "+player.getImage().getHeight());
        Actor kimJongUn = (Actor)getObjects(KimJongUn.class).get(0);
        System.out.println("\nKIM JONG UN");
        System.out.println("    x:  "+kimJongUn .getX());
        System.out.println("    y:  "+kimJongUn .getY());
        System.out.println("    image width:  "+kimJongUn .getImage().getWidth());
        System.out.println("    image height:  "+kimJongUn .getImage().getHeight());
    }

}
danpost danpost

2016/4/22

#
DJ_KASKO wrote...
it did not do anything different it is still the same
Then you probably did not follow these instructions.
danpost wrote...
Then prepare the world and before starting it, right click on the world background and select to execute the 'printStats' method. Then move the speed slider to about one-quarter speed (half way between the left end and the middle. Next, start the scenario and alternate tapping on the "up" key and clicking on the background of the world. Do this until the player should return to start over again. Take the entire output from the new code and post the results here.
DJ_KASKO DJ_KASKO

2016/4/22

#
how do i do it properly then step by step
danpost danpost

2016/4/22

#
Just follow those instructions. The preparing part is not needed, now that you have the code to add the object in your world class. Just compile and follow the rest of the instructions. The last line of the instructions means to post the terminal display output here.
DJ_KASKO DJ_KASKO

2016/4/22

#
y: 190 image width: 259 image height: 194 PLAYER x: 400 y: 162 image width: 348 image height: 266 KIM JONG UN x: 309 y: 190 image width: 259 image height: 194 PLAYER x: 400 y: 162 image width: 348 image height: 266 KIM JONG UN x: 309 y: 190 image width: 259 image height: 194 PLAYER x: 400 y: 162 image width: 348 image height: 266 KIM JONG UN x: 309 y: 190 image width: 259 image height: 194 PLAYER x: 400 y: 162 image width: 348 image height: 266 KIM JONG UN x: 309 y: 190 image width: 259 image height: 194
danpost danpost

2016/4/22

#
Your images are awfully large -- and you did not post all the output to the terminal (missing the beginning). Change the '400' in the 'setLocation' commands on line 33 and 36 of the Player1 class to '20'. (only those after 'setLocation' on those lines).
DJ_KASKO DJ_KASKO

2016/4/22

#
ok i did that but know it wont move and the counter score is going up
There are more replies on the next page.
1
2
3
4
5
6
7