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

2019/10/27

Maze - detect black color from picture and make it solid

Aelin Aelin

2019/10/27

#
Hello, I'm trying to do maze, I have this picture of maze - http://prntscr.com/pop6s1 and I need to make it solid. (The idea is.. actor can't go thought that black color). import greenfoot.*; import java.awt.Color; public class Actor extends Actor { public void act() { if (Greenfoot.isKeyDown("left")) { this.turn(180); this.move(3); setRotation(0); if (getWorld().getBackground().getColorAt(getX(), getY()).equals(Color.black)) { move (-1); } } if (Greenfoot.isKeyDown("down")) { this.turn(90); this.move(3); setRotation(0); if (getWorld().getBackground().getColorAt(getX(), getY()).equals(Color.black)) { move (-1); } } if (Greenfoot.isKeyDown("up")) { this.turn(270); this.move(3); setRotation(0); if (getWorld().getBackground().getColorAt(getX(), getY()).equals(Color.black)) { move (-1); } } if (Greenfoot.isKeyDown("right")) { this.move(3); if (getWorld().getBackground().getColorAt(getX(), getY()).equals(Color.black)) { move (-1); } } } } (getWorld().getBackground().getColorAt(getX(), getY()).equals(Color.black)) = it's without error, but it also doesn't work. I will be glad, if someone help me.
danpost danpost

2019/10/27

#
Why would you only move back by -1 when you move forward 3? No wonder it does not work. Also, would you not have to adjust the rotation again to move back along the same direction? On the side: remove the importing of java.awt.Color and change all 'black' to 'BLACK'.
Aelin Aelin

2019/10/28

#
Ah.. thanks. It works now.
You need to login to post a reply.