GMU:Processing im Park/Dirk Wäsch/Code Hausaufgabe VIII

From Medien Wiki

Processing v3.0.1 Quellcode:



PImage img;      
int x = 1, y = 0;
color c = color(255, 255, 0);
color wall = color(0);
color ctrail = color(255, 0, 0);

void setup() {
  size(344, 344);
  img = loadImage("Labyrinth.png");
  noSmooth(); // nichts wird pixelig
}


void draw() {
  img.set(x, y, c);
  image(img, 0, 0, width, height);
  walk();
}

void walk() {
      for(int i = 0; i < 3; i++);{
  int xnew = x;
  int ynew = y;

    
  }
}

void keyPressed() {
  
  int xnew = x;
  int ynew = y;
  
  switch(keyCode) {
  case LEFT:
    xnew = x - 1;
    break;
  case RIGHT:
    xnew = x + 1;
    break;
  case UP:
    ynew = y - 1;
    break;
  case DOWN:
    ynew = y + 1; 
    break;
  }
  
        if(img.get(xnew, ynew) != wall) {
          x = xnew;
          y = ynew;
          }
}