My friend and I are working on this labyrinth and it was working but Yoshi were able to cross the wall so i added the function get() and i wanted my yoshi to walk in a direction if the key was pressed and if the color of the pixel in the same direction my yoshi is going is white but now my yoshi isn’t moving.
Thanks for replying.
ps: I’m french
PImage labyFond;
int x;
int y;
PImage[] Yoshi = new PImage[7];
color b = color (255,255,255); //White
color q;
color r;
color s;
color t;
void setup()
{
size(1024,1024);
frameRate(30);
labyFond = loadImage(“laby.png”);
Yoshi[0] = loadImage( “Yoshi0.gif” );
Yoshi[1] = loadImage( “Yoshi1.gif” );
Yoshi[2] = loadImage( “Yoshi2.gif” );
Yoshi[3] = loadImage( “Yoshi3.gif” );
Yoshi[4] = loadImage( “Yoshi4.gif” );
Yoshi[5] = loadImage( “Yoshi5.gif” );
Yoshi[6] = loadImage( “Yoshi6.gif” );
x=-5;
y=117;
// get the color of the pixel next to Yoshi :
q =get(x,y-5); //Color above Yoshi
r= get(x,y+5); //Color under Yoshi
s= get(x-5,y); //Color on the left of Yoshi
t= get(x+5,y); //Color on the right of Yoshi
}
void draw()
{
background(labyFond);
image( labyFond, 0, 0, width, height );
image( Yoshi[frameCount%1], x, y );
}
void keyPressed(){
if (key==CODED){
if ((keyCode==UP) &&( q == b)) {
y = y-2; // notre Yoshi avance vers le haut
image( labyFond, 0, 0, width, height );
image( Yoshi[frameCount%7], x, y );
}
if ((keyCode==DOWN)&&( r == b)) {
y = y+2; // notre Yoshi avance vers le bas
image( labyFond, 0, 0, width, height );
image( Yoshi[frameCount%7], x, y );
}
if ((keyCode==LEFT)&&( s == b)) {
x = x-2; // notre Yoshi avance vers la gauche
image( labyFond, 0, 0, width, height );
image( Yoshi[frameCount%7], x, y );
}
if ((keyCode==RIGHT)&&( t == b)) {
x = x+2; // notre Yoshi avance vers la droite
image( labyFond, 0, 0, width, height );
image( Yoshi[frameCount%7], x, y );
}
}
}