Hey guys !
As an homework, my friend and me have to create a labyrinth(a basic one)
With a starting and an ending. At the moment almost everything is working perfectly but the problem we met is about the collision with the walls. Our teacher told us we could try to solve this problem with the color detection but it’s f***ing hard. Do u have any other idea or can u try to explain us how to do with this method.
ps: Our laby is in black and white and i’m french.
here’s the code :
PImage labyFond;
float x;
float y;
PImage[] Yoshi = new PImage[7];
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;
}
void draw()
{
background(labyFond);
image( labyFond, 0, 0, width, height );
image( Yoshi[frameCount%1], x, y );
}
float pixels;
float nl;
float nc;
float t;
void keyPressed(){
if (key==CODED){
if (keyCode==UP){
y = y-2; // notre Yoshi avance vers le haut
image( labyFond, 0, 0, width, height );
image( Yoshi[frameCount%7], x, y );
}
if (keyCode==DOWN){
y = y+2; // notre Yoshi avance vers le bas
image( labyFond, 0, 0, width, height );
image( Yoshi[frameCount%7], x, y );
}
if (keyCode==LEFT){
x = x-2; // notre Yoshi avance vers la gauche
image( labyFond, 0, 0, width, height );
image( Yoshi[frameCount%7], x, y );
}
if (keyCode==RIGHT){
x = x+2; // notre Yoshi avance vers la droite
image( labyFond, 0, 0, width, height );
image( Yoshi[frameCount%7], x, y );
}
}
}