I'm making a maze game for a project in school, and as such i need to create boundaries for the game. not only for the outer walls but also inner ones of different and sometimes not perfect squares. I was just wondering how i should go about doing this? Is there a way for the program to realize what colour it's about to go onto, then make plans accordingly? like the colour white is okay to walk on, but black isn't

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Dimension;
import java.util.Random;
import java.awt.geom.Line2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.GridLayout;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.EventQueue;
import javax.swing.SwingConstants;
import java.awt.Font;

public class ZombieEscape extends JPanel implements ActionListener, KeyListener {
    private static int COUNTER = 0;
    private static final int INTERVAL = 50;
    private static final int WINDOW_WIDTH = 420;
    private static final int WINDOW_HEIGHT = 520;
    private static final Color BG_COLOR = Color.WHITE;
    private JButton Start, Help;
    private JLabel Title;
    Font font = new Font("Andes", Font.BOLD, 50);
    Random randomGenerator = new Random();

    private Ellipse2D.Double zombie1 = new Ellipse2D.Double( 380, 70, 20.0, 20.0);
    private Ellipse2D.Double zombie2 = new Ellipse2D.Double( 380, 110, 20.0, 20.0);
    private Ellipse2D.Double zombie3 = new Ellipse2D.Double( 380, 150, 20.0, 20.0);
    private Ellipse2D.Double zombie4 = new Ellipse2D.Double( 380, 190, 20.0, 20.0);
    private Ellipse2D.Double zombie5 = new Ellipse2D.Double( 380, 230, 20.0, 20.0);
    private Ellipse2D.Double zombie6 = new Ellipse2D.Double( 380, 270, 20.0, 20.0);
    private Ellipse2D.Double zombie7 = new Ellipse2D.Double( 380, 310, 20.0, 20.0);
    private Ellipse2D.Double zombie8 = new Ellipse2D.Double( 380, 350, 20.0, 20.0);
    private Ellipse2D.Double zombie9 = new Ellipse2D.Double( 380, 390, 20.0, 20.0);
    private Ellipse2D.Double zombie10 = new Ellipse2D.Double( 380, 430, 20.0, 20.0);
    private Ellipse2D.Double human = new Ellipse2D.Double(20, 250, 20.0, 20.0);
    private Rectangle2D.Double Heli = new Rectangle2D.Double(400,250,20,20);
    public int[] xBorder = {0,420,420,400,400,20,20,400,400,420,420,0};
    public int[] yBorder = {50,50,250,250,70,70,450,450,270,270,470,470};

    private int tickCount = 0;

    private javax.swing.Timer timer;

    private int width = -1;
    private int height = -1;

    public ZombieEscape() {
        setLayout( new BorderLayout() );
        setPreferredSize(new Dimension( WINDOW_WIDTH, WINDOW_HEIGHT ) );
        setBackground( BG_COLOR );

	Start = new JButton("Start");
	Help = new JButton("Help");

        JPanel buttons = new JPanel( new GridLayout(1, 2) );
	buttons.add( Start );
	buttons.add( Help );
	add( buttons, BorderLayout.SOUTH );

        timer = new javax.swing.Timer(INTERVAL, this);
        timer.start();
        addKeyListener( this );
        setFocusable( true );

	Title = new JLabel("Zombie Escape");
	Title.setFont(font);
        Title.setHorizontalAlignment(SwingConstants.CENTER);
        Title.setVerticalAlignment(SwingConstants.CENTER);
	add(Title, BorderLayout.NORTH);

        Start.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent evt ) {
            }
        });

        Help.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent evt ) {
	        timer.stop();
                JOptionPane.showMessageDialog(null,"Rules" + "\n" + "You are the only survivor of after the zombie infestation." + "\n" + "Your goal, is to get yourself (Red Circles) to the helicopter pad (Yellow Square)" + "\n" + "while avoiding the zombies (Green Circles) " + "\n" + "\n" + "Controls" + "\n" + "W - Moves Up" + "\n" + "A - Moves Left" + "\n" + "S - Moves Down" + "\n" + "D - Moves Right"); 
            }
        });
    }

    protected void paintComponent( Graphics g ) {
        super.paintComponent( g );
        Graphics2D g2d = (Graphics2D)g;
        int w = getWidth();
        int h = getHeight();

        if ( w != width || h != height ) {
            width = w;
            height = h;
        }
        g2d.setColor( Color.GREEN );
        g2d.fill( zombie1 );
        g2d.fill( zombie2 );
        g2d.fill( zombie3 );
        g2d.fill( zombie4 );
        g2d.fill( zombie5 );
        g2d.fill( zombie6 );
        g2d.fill( zombie7 );
        g2d.fill( zombie8 );
        g2d.fill( zombie9 );
        g2d.fill( zombie10 );
	g2d.setColor( Color.YELLOW );
	g2d.fill( Heli );
	g2d.setColor( Color.RED );
	g2d.fill( human );
	g2d.setColor( Color.BLACK );
	g2d.fillPolygon (xBorder, yBorder, 12);
    }

    public void actionPerformed( ActionEvent evt ){
	if (COUNTER == 5){
	    int randomInt = randomGenerator.nextInt(4);
	    if (randomInt == 0) {
	    }

	    if (randomInt == 1) {
	    }

	    if (randomInt == 2) {
	    }

	    if (randomInt == 3) {
	    }
	    COUNTER = 0;
	}
	COUNTER++;
	repaint();
    }
    public void keyPressed(KeyEvent e) {
        switch( e.getKeyChar() ) {
            case 'a':
                human.x -= 20.0;
                break;
            case 's':
                human.y += 20.0;
                break;
            case 'd':
                human.x += 20.0;
                break;
            case 'w':
                human.y -= 20.0;
                break;
        }
        repaint();
    }
    public void keyReleased(KeyEvent e) {

    }
    public void keyTyped(KeyEvent e) { 

    }
    public static void runApplication( final JPanel app ) {
       EventQueue.invokeLater(
           new Runnable() {
               public void run() {
                   JFrame frame = new JFrame();
                   frame.setSize( app.getPreferredSize() );
                   frame.setTitle( app.getClass().getName() );
                   frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                   frame.add( app );
                   frame.setVisible( true );
                }
            } );
    }

    public static void main( String[] args ) {
        ZombieEscape application = new ZombieEscape();
        runApplication( application );
    }
}

program to realize what colour it's about to go onto,

The BufferedImage class has methods for getting the color of a pixel.
Are the colored area bounded by shapes that could be used to test where the moving item is going?

This article has been dead for over six months. Start a new discussion instead.