Can`t move PacMan

int xkoord = 200;
int ykoord = 200;
int summand = 10;
int winkel1 = 40;
int winkel2 = 320;

void setup() {
  size (400, 400);
  frameRate(60);
  background(0);
  PacMan();
  Waende();
}

void PacMan() {
  fill ( 255, 255, 0 );
  arc( xkoord, ykoord, 20, 20, radians(winkel1), radians(winkel2));
  stroke(0, 0, 0);
}

void Waende() {
  stroke (0, 255, 255);
  line ( 10, 10, 390, 10);
  line ( 10, 390, 390, 390 );
  line ( 10, 10, 10, 390);
  line ( 390, 10, 390, 390);
}

//Commands
void keyPressed () {
  if ( keyCode == DOWN) {
    ykoord = ykoord +15;
    winkel1 = 140;
    winkel2 = 400;
  }
  if ( keyCode == UP) {
    ykoord = ykoord -15;
    winkel1 = 310;
    winkel2 = 580;
  }
  if ( keyCode == RIGHT) {
    xkoord = xkoord +15;
    winkel1 = 40;
    winkel2 = 320;
  }
  if ( keyCode == LEFT) {
    xkoord = xkoord -15;
    winkel1 = 220;
    winkel2 = 500;
  }

  //Begrenzungen
  if (xkoord >= 390) {
    xkoord = 390;
  }
  if (xkoord <= 10) {
    xkoord = 10;
  }
  if (ykoord >= 390) {
    ykoord = 390;
  }
  if (ykoord <= 10) {
    ykoord = 10;
  }
}

Your problem is quite simple. In the code you only call PacMan() and Waende() once, in the setup() function. When keys are pressed, you are correctly updating the position variables, but the function to draw the moving ‘characters’ isn’t ever getting called it so it will never be redrawn

Also, unless I am mis-remembering, if you do not also clear the screen each time you will end up with a screen full of every rectangles and arcs because you drew one each loop but didn’t erase anything.

So, basically you need tor remove the calls: PacMan(), Waende(), and background(0) from setup() and put them in a draw() function.

void draw() {
    background(0);
    PacMan();
    Waende();
}

P.S.
If you want to draw a rectangle you don’t have to use discrete lines, there is a rectangle drawing function. However, it is important to set fill and stroke respectively f you want it to be a filled rectangle of a specified color and an outline of a different color.

https://processing.org/reference/rect_.html
https://processing.org/reference/fill_.html
https://processing.org/reference/noFill_.html
https://processing.org/reference/stroke_.html
https://processing.org/reference/noStroke_.html

2 Likes