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

2018/6/7

Color detection?

aayu1004 aayu1004

2018/6/7

#
I know this question has been asked several times already, but I tried a few solutions I found on this site but none of them actually worked. This is what I currently have:
        Color mazeColor = new Color (0, 0 , 225);
        Color pacmanColor = getImage().getColorAt(37/2, 42/2); //Pacman is 37 x 42 
        
        if (pacmanColor.equals(mazeColor))
        {
            // Stuff that I want to do
        }
But it doesn't work at all. Even if the Pacman actor is touching a blue wall, it continues on without executing the code inside the if block. Is there a better way/ Am I doing something wrong? Maze with blue walls: Pacman: https://drive.google.com/file/d/1f1urYhwxYGrhouCJdVFw4Ifz_rKtXyW2/view
danpost danpost

2018/6/7

#
Line 2 is getting a Color from the center of the image of the pacman -- not from the image of the wall. Test it. Add the following line for line 3:
System.out.println("pacmanColor:  RED: "+pacmanColor.getRed()+"    GREEN: "+pacmanColor.getGreen()+"    BLUE: "+pacmanColor.getBlue());
aayu1004 aayu1004

2018/6/7

#
danpost wrote...
Line 2 is getting a Color from the center of the image of the pacman -- not from the image of the wall. Test it. Add the following line for line 3:
System.out.println("pacmanColor:  RED: "+pacmanColor.getRed()+"    GREEN: "+pacmanColor.getGreen()+"    BLUE: "+pacmanColor.getBlue());
Yes it seems so, I simply printed the “pacmanColor” and it gave me the RGB values for yellow (255, 255, 0). Also I might be a bit confused. I already have the color of the wall - mazeColor. Was I supposed to set “pacmanColor” to the maze-wall’s color as well?
danpost danpost

2018/6/7

#
aayu1004 wrote...
Was I supposed to set “pacmanColor” to the maze-wall’s color as well?
I think you are supposed to get the color of the world background image where the pacman wants to go.
You need to login to post a reply.