Version 1 de "voiture"
Etat du code
int x=40;
int y=400;
int d=30;
boolean modeAuto = true;
boolean n = true;
boolean s = true;
boolean e = true;
boolean o = true;
PImage route;
void setup () {
size(500, 500);
route=loadImage("route.png");
}
void draw () {
image(route, 0, 0, width, height);
ellipse (x, y, d, d);
if(modeAuto==true){
detecterRoute();
detecterFeu();
detecterObsatcle();
}else{
}
}
void detecterRoute() {
if (red(get(x, y-20))!=0) {
n=true;
s=false;
}
if (red(get(x, y+20))!=0) {
s=true;
n=false;
}
if (red(get(x+20, y))!=0) {
e=true;
o=false;
}
if (red(get(x-20, y))!=0) {
o=true;
e=false;
}
if (s==false && n==false) {
y=y+1;
}
if (s==true && n==false) {
y=y-1;
}
if (s==false && n==true) {
y=y+1;
}
if (e==false && o==false) {
x=x+1;
}
if (e==true && o==false) {
x=x-1;
}
if (e==false && o==true) {
x=x+1;
}
}
void detecterFeu() {
}
void detecterObsatcle() {
}
Image à joindre