Hi there! I am using Processing for a school project and I am not able to resolve an issue.
I don’t know how to stop the red ball when it hits the boundary of the maze. I’m thinking to put the pixels of the ball and the maze.jpg in two different array. I don’t know how to say to the ball’s array STOP it when touch the black pixels. Basically the ball can’t go through the maze.
Also I organize everything in three classes, could be a problem for the arrays?
Please some one can help me?
“GAME”
Ball player;
Maze img;
void settings() {
size (1000, 1000, P2D);
img = new Maze ();
player = new Ball();
}
void draw() {
clear();
background (255);
img.display();
player.display ();
}
“BALL”
class Ball {
float x;
float y;
float n;
float m;
//float a;
float b= width-800; //canvas is 1000,
float c = height-800;
Ball () {
//float n = map ( a, 0, 100, 650, width);
// float m = map ( a, 0, 100, 650, height);
float n = constrain (b,650,width);
float m = constrain (c,650,height);
x = random(n);
y = random (m);
}
void display() {
if (mousePressed==false) {
noStroke();
fill (255, 0, 0);
ellipse (x, y, 15, 15);
} else {
noStroke();
fill (255, 0, 0);
ellipse (mouseX, mouseY, 15, 15);
}
}
}
“MAZE”
class Maze {
PImage img1;
Maze () {
img1 = new PImage ();
img1 = loadImage ("circular maze.png");
size (width, height, P2D);
img1.resize(img1.width*2, img1.height*2);
}
void display () {
pushMatrix ();
translate(width/2, height/2);
imageMode (CENTER);
image (img1, 0, 0);
popMatrix ();
}
}