Hello fellow processing enthusiasts!!
I am currently working on a project for university and I am pretty much at the beginning with the code.
In it, I am using color detection to avoid the walls of the maze you’re supposed to navigate through. I’ve tried this a couple of times in 600x400 but now that I’ve tried sizing it up it doesn’t work anymore/ the figure walks through the walls instead of being pushed back. I’ve tried printing the value of the current color it reads from the position spawnx and spawny but it only shows 0.
Here is the part of the code which pushes the figure from whichever wall they hit:
spawnx and spawny are the coordinates where the figure is moved via the arrow keys.
color current = maze.get(spawnx, spawny);
println(current);
if (current < wallsColor) {
if (goingUp == true) {
spawny = spawny+(width/100);
} else if (goingDown == true) {
spawny = spawny-(width/100);
} else if (goingLeft == true) {
spawnx = spawnx+(width/100);
} else {
spawnx = spawnx-(width/100);
}
}
Could this be a performance issue, or did I miss some kind of dependance that doesn’t work for other resolutions somewhere? Would the color detection have a hard time working when the image is scaled up or down within the program? I would really appreciate two more eyes taking a look at the code, because eventually I would size up the whole thing, so it would be pretty sad if it winded up not working. <3 Thanks in advance for your input!
Since it’s not a whole lot and in case that is where the issue lies, here’s the complete code of the program (very much still under construction though^^):
PImage maze; //the image is black and white
PImage [] yussef;
int spawnx, spawny; //position and speed of family
int speed;
color wallsColor; //color of the walls of the maze
boolean goingUp; //track where the player is going so to send him back to
boolean goingDown; //the right direction if he hits a wall
boolean goingRight;
boolean goingLeft;
void setup() {
size (600, 400);
maze = loadImage("maze.jpg");
wallsColor = -16000000; //This is the number it reads when I printed the current number at the
//position of the wall, so for black
spawnx = width/2; //Spawnpunkt
spawny = height - 2*(width/60);
yussef = new PImage [3]; //laden der animation
for (int i=0; i<yussef.length; i++) {
yussef [i] = loadImage("yussef"+i+".png");
}
}
void draw () {
image (maze, 0, 0, width, height);
//displaying the player; walking animation
//image (yussef[int(map(spawnx, 0, width, 0, yussef.length))], spawnx, spawny);
image (yussef[0], spawnx, spawny, width/10, width/10);
//making the walls solid by color detection
color current = maze.get(spawnx, spawny);
println(current);
if (current < wallsColor) {
if (goingUp == true) {
spawny = spawny+(width/100);
} else if (goingDown == true) {
spawny = spawny-(width/100);
} else if (goingLeft == true) {
spawnx = spawnx+(width/100);
} else {
spawnx = spawnx-(width/100);
}
}
}
void keyPressed () {
if (key == CODED) {
if (keyCode == UP) {
goingUp = true;
spawny--;
} else {
goingUp = false;
}
if (keyCode == DOWN) {
goingDown = true;
spawny++;
} else {
goingDown = false;
}
if (keyCode == LEFT) {
goingLeft = true;
spawnx--;
} else {
goingLeft = false;
}
if (keyCode == RIGHT) {
goingRight = true;
spawnx++;
} else {
goingRight = false;
}
}
}