Hello there, i am trying to make a maze game where the character is blocked by the wall. I would like to create a method of stopping the character from moving if it is touching the black pixels on the background of the maze image opposed to creating each wall by hand. I am new to programming and not entirely sure what to do here.
Imgur link to maze background
I have made the character be able to move freely but i cannot figure out how to stop it from moving.
Any help will be greatly appreciated.
Thank you :)
import greenfoot.*;
public class MyWorld extends World
{
public MyWorld()
{
super(700, 700, 1);
int x = Greenfoot.getRandomNumber(900);
int y = Greenfoot.getRandomNumber(600);
addObject(new Corgi(), 320, 10);
}
}import greenfoot.*;
public class Corgi extends Animal
{
public void act()
{
if (Greenfoot.isKeyDown("w"))
{
setDirection(NORTH);
move (4);
}
if (Greenfoot.isKeyDown("d"))
{
setDirection(EAST);
move (4);
}
if (Greenfoot.isKeyDown("s"))
{
setDirection(SOUTH);
move (4);
}
if (Greenfoot.isKeyDown("a"))
{
setDirection(WEST);
move (4);
}
}
public static final int NORTH = -1;
public static final int EAST = 0;
public static final int SOUTH = 1;
public static final int WEST = 2;
public int direction;
public void setDirection(int direction)
{
this.direction = direction;
{
setRotation(90*direction);
}
}
}
