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
DJ_KASKO DJ_KASKO

2016/4/22

#
DJ_KASKO wrote...
the bold parts are going to be the wrong (red) parts
    [b]if[/b] (isTouching[b](Ki[/b]mJongUn[b].cl[/b]ass[b]))[/b]
   [b] {[/b]
        setLocation[b](<?[/b] x ?>[b], [/b[b]]<? y ?[/b]>);
        counter.add[b](1[/b]);
 [b]   }[/b]
}
so basically nearly everything is wron in that code but the wrest of the whole code is fine
that didnt work well but you get what i mean
DJ_KASKO DJ_KASKO

2016/4/22

#
danpost wrote...
First, remove lines 36 through 39 (the 'getIntersectingPlayer1' method). A player does not need to check if it is intersecting with itself. Then, lines 41 through 45 need to be within a method. Move them to inside the 'act' method. Replace '<? x ?>' with '400' and replace '<? y ?>' with 'getY()'.
ok so like this
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Player1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Player1 extends Animal
{
    private Counter counter;

    public Player1(Counter pointCounter)
    {
        counter=pointCounter;
    }

    public void act()
    {
        checkKeys();
    }

    /**
     * Act - do whatever the Player1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void checkKeys()
    {
        if (Greenfoot.isKeyDown("up") )
        {
            move(75);
        }
        if (getX()>400) setLocation(400, getY());
            if (isTouching(KimJongUn.class))
        {
            setLocation(400, getY();
            counter.add(1);
        }
    }

 
    {
        return (Player1) getOneIntersectingObject(Player1.class);
}
DJ_KASKO DJ_KASKO

2016/4/22

#
danpost wrote...
First, remove lines 36 through 39 (the 'getIntersectingPlayer1' method). A player does not need to check if it is intersecting with itself. Then, lines 41 through 45 need to be within a method. Move them to inside the 'act' method. Replace '<? x ?>' with '400' and replace '<? y ?>' with 'getY()'.
so like what i did just then
danpost danpost

2016/4/22

#
On your last code post, remove lines 42 and 43. These lines:
{
    return (Player1) getOneIntersectingObject(Player1.class);
They were included as to be deleted in what I mentioned in my last posting.
DJ_KASKO DJ_KASKO

2016/4/22

#
danpost wrote...
On your last code post, remove lines 42 and 43. These lines:
{
    return (Player1) getOneIntersectingObject(Player1.class);
ok so like this
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Player1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Player1 extends Animal
{
    private Counter counter;

    public Player1(Counter pointCounter)
    {
        counter=pointCounter;
    }

    public void act()
    {
        checkKeys();
    }

    /**
     * Act - do whatever the Player1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void checkKeys()
    {
        if (Greenfoot.isKeyDown("up") )
        {
            move(75);
        }
        if (getX()>400) setLocation(400, getY());
            if (isTouching(KimJongUn.class))
        {
            setLocation(400, getY();
            counter.add(1);
        }
    }


}
danpost danpost

2016/4/22

#
Okay. How is it working? How is it not working correctly, now -- what should it be doing that it is not? and what should it be doing that it is not?
DJ_KASKO DJ_KASKO

2016/4/22

#
danpost wrote...
Okay. How is it working? How is it not working correctly, now -- what should it be doing that it is not? and what should it be doing that it is not?
on line 36 the ; at the end of the line has an error it says ')' is expected never mind i just put another ) next to the last one im testing it now
DJ_KASKO DJ_KASKO

2016/4/22

#
danpost wrote...
Okay. How is it working? How is it not working correctly, now -- what should it be doing that it is not? and what should it be doing that it is not?
OK so it works fine but the only problem is that it doesnt rebound back to its starting position and it goes half way through his head and stops and i want it to hit him and as soon as the fist touches him then it rebounds back and i press the "upkey" to do it over and over. Problems goes through head and stops half way in head counter works but when the fist stops half way in his head and counts so many points doesnt rebound
danpost danpost

2016/4/22

#
Try changing 'isTouching(KimJongUn.class)' to 'getOneIntersectingObject(KimJongUn.class) != null'.
DJ_KASKO DJ_KASKO

2016/4/22

#
danpost wrote...
Try changing 'isTouching(KimJongUn.class)' to 'getOneIntersectingObject(KimJongUn.class) != null'.
OK it still does the same thing as before but this time when i press act it does it automatically without me pressing the upkey
DJ_KASKO DJ_KASKO

2016/4/22

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

/**
 * Write a description of class Player1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Player1 extends Animal
{
    private Counter counter;

    public Player1(Counter pointCounter)
    {
        counter=pointCounter;
    }

    public void act()
    {
        checkKeys();
    }

    /**
     * Act - do whatever the Player1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void checkKeys()
    {
        if (Greenfoot.isKeyDown("up") )
        {
            move(75);
        }
        if (getX()>400) setLocation(400, getY());
            if (getOneIntersectingObject(KimJongUn.class) != null)
        {
            setLocation(400, getY());
            counter.add(1);
        }
    }
}

here is the updated code you told me to do
danpost danpost

2016/4/22

#
What is the size of your world? what is the size of the image of the KimJongUn object? and where is it located in the world? also, what is the size of the image of the Player1 object?
DJ_KASKO DJ_KASKO

2016/4/22

#
how do i tell you that paste image in post?
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()
    {
    }
}
DJ_KASKO DJ_KASKO

2016/4/22

#
i dont have the pictures of the KimJongUn and Player1 and Player2 because i dont have photoshop but my school did so i did it there and worked on it at school and then put the whole game on a usb soi dont have the pictures but i can upload this scenario and you could check it out because the pictures are in the game
There are more replies on the next page.
1
2
3
4
5
6