We are about to switch to a new forum software. Until then we have removed the registration on this forum.
if ( key == CODED) {
if (keyCode == UP && linkY-20 > 0 && (map.get((int)linkX, (int)linkY-20)== -339816 || map.get((int)linkX, (int)linkY-20)== -340072 || map.get((int)linkX, (int)linkY-20)== -206680 || map.get((int)linkX, (int)linkY-20)== -9145228 || map.get((int)linkX, (int)linkY-20)== -3650548 || map.get((int)linkX, (int)linkY-20)== -16777216 || map.get((int)linkX, (int)linkY-20)== -197380))
linkY-=5;
linkImg = linkUp;
else if (keyCode == DOWN && linkY+20 < height && (map.get((int)linkX, (int)linkY+20)== -339816 || map.get((int)linkX, (int)linkY+20)== -340072 || map.get((int)linkX, (int)linkY+20)== -206680 || map.get((int)linkX, (int)linkY+20)== -9145228 || map.get((int)linkX, (int)linkY+20)== -3650548 || map.get((int)linkX, (int)linkY+20)== -16777216 || map.get((int)linkX, (int)linkY+20)== -197380))
linkY+=5;
linkImg = linkDown;
else if (keyCode == LEFT && linkX-20 > 0 && (map.get((int)linkX-20, (int)linkY)== -339816 || map.get((int)linkX-20, (int)linkY)== -340072 || map.get((int)linkX-20, (int)linkY)== -206680 || map.get((int)linkX-20, (int)linkY)== -9145228 || map.get((int)linkX-20, (int)linkY)== -3650548 || map.get((int)linkX-20, (int)linkY)== -16777216 || map.get((int)linkX-20, (int)linkY)== -197380))
linkX-=5;
linkImg = linkLeft;
else if (keyCode == RIGHT && linkX+20 < width && (map.get((int)linkX+20, (int)linkY)== -339816 || map.get((int)linkX+20, (int)linkY)== -340072 || map.get((int)linkX+20, (int)linkY)== -206680 || map.get((int)linkX+20, (int)linkY)== -9145228 || map.get((int)linkX+20, (int)linkY)== -3650548 || map.get((int)linkX+20, (int)linkY)== -16777216 || map.get((int)linkX+20, (int)linkY)== -197380))
linkX+=5;
linkImg = linkRight;
}
}
Answers
@Nathan101
Those conditionals are not cool 8-|
Please put a little bit of extra work and make them more compact and more readable. You have this error and it is not because you are missing a curly bracket. In processing, when you miss something in your code, the compiler will scream at you and it will always tell you a bracket is missing. In your case, you are actually missing a matching parentheses and I believe it is this one:
if (keyCode == UP && linkY-20 > 0 && ( ...
for the first line and I will guess it is the same problem for the other conditionals. If you find you are repeating conditions, you can try something like:
This is what I mean with making them more compact...
Also keep in mind Processing has a function call map. I personally avoid using processing keywords even though your program will work fine. Maybe try myMap instead.
Kf
I fixed it doing this:
But, my character won't move now!!!
also your conditions are
and that just won't work. the the linkY line will run conditionally, the linkImg line will run UNCONDITIONALLY. it actuall means this
put {}s around blocks of code like this to make sure they both run. in fact, put it around blocks of code even when there is only one line in the block. it's just a good habit to get into.
actually, that might be the cause of your problem because the else is unexpected.
what's this? its not clear.
i would rather split the colour condition from the others and use a local variable:
ah, ok, good, it needed the brackets. now think about splitting the enormo expression.
It says pixel is not a variable
And when I make pixel a float, and run it the player still goes right past the walls.
We would need runnable code to test that bit, what you've posted isn't enough.
Double check the colours.
Due to color blending, using get() to determine collision in Processing is very unreliable! :-SS
Maybe
blendMode(REPLACE);
can magically fix it. Who knows? :-??https://Processing.org/reference/blendMode_.html