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

2013/2/17

getIntersectingObject

2
3
4
5
6
7
8
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(20, getY());
            if (getOneIntersectingObject(KimJongUn.class) != null)
        {
            setLocation(20, getY());
            counter.add(1);
        }
    }
}
DJ_KASKO DJ_KASKO

2016/4/22

#
y: 190 image width: 259 image height: 194 PLAYER x: 20 y: 162 image width: 348 image height: 266 KIM JONG UN x: 309 y: 190 image width: 259 image height: 194 PLAYER x: 20 y: 162 image width: 348 image height: 266 KIM JONG UN x: 309 y: 190 image width: 259 image height: 194 PLAYER x: 20 y: 162 image width: 348 image height: 266 KIM JONG UN x: 309 y: 190 image width: 259 image height: 194 PLAYER x: 20 y: 162 image width: 348 image height: 266 KIM JONG UN x: 309 y: 190 image width: 259 image height: 194 that is all there is on the terminal i even did what you said again
danpost danpost

2016/4/22

#
DJ_KASKO wrote...
ok i did that but know it wont move and the counter score is going up
You really need to make your images smaller so that they are not so close to touching to start. Initial location of player, 20, plus have its image width (348), 174, is 194; and the initial location of kim, 309, minus half of its image width (259), 129, is 180. There is a gap of only 6 pixels between the images and you are having the player move 75 on a single move. Soooo, it moves, intersects, increments counter and moves back all in one act cycle when the 'up' key is pressed.
DJ_KASKO DJ_KASKO

2016/4/22

#
i cant change the measurements because i dont have photoshop at home and im on school holidays and even if i use paint or something then that will make a white background on the picture witch i cant have other wise the background will include as the picture
danpost danpost

2016/4/22

#
DJ_KASKO wrote...
that is all there is on the terminal i even did what you said again
You must have a limit on the number of lines saved in the output of the terminal. There is an option for unlimited buffering.
DJ_KASKO DJ_KASKO

2016/4/22

#
so do i have unlimited buffering or not because before i didnt
danpost danpost

2016/4/22

#
You can use the 'scale' method to reduce the size of the images. For example:
public Player1(Counter pointsCounter)
{
    counter = pointsCounter;
    GreenfootImage image = getImage();
    int imgWidth = image.getWidth();
    int imgHeight = image.getHeight();
    image.scale(imgWidth*2/5, imgHeight*2/5);
}
Lines 4 through 7 can be used in the KimJongUn constructor as well.
DJ_KASKO DJ_KASKO

2016/4/22

#
so where do i put the code
DJ_KASKO DJ_KASKO

2016/4/22

#
or where is the code
DJ_KASKO DJ_KASKO

2016/4/22

#
to change the measurements
danpost danpost

2016/4/22

#
The code I gave should replace lines 13 through 16 of the Player1 class ( 'public Player1(Counter pointCounter)' ).
danpost danpost

2016/4/22

#
DJ_KASKO wrote...
or where is the code
to change the measurements
Line 7 executes the 'scale' method on the image of the actor. The '*2/5' reduces the dimension to 40% of the original size.
DJ_KASKO DJ_KASKO

2016/4/22

#
ok i did it how do i make kimjongun the same size as well then?
danpost danpost

2016/4/22

#
DJ_KASKO wrote...
how do i make kimjongun the same size as well then?
What do you not understand about the following:
danpost wrote...
Lines 4 through 7 can be used in the KimJongUn constructor as well.
DJ_KASKO DJ_KASKO

2016/4/22

#
oh sorry my bad
There are more replies on the next page.
2
3
4
5
6
7
8