Laufbewegung geht nicht..

RegenSonne

Aktives Mitglied
Jo ich habe mal gegoogelt und ein Platform game gefunden. also habe ich es nachgeschieben.. naja der typ läuft nicht.. erkennt hier jmd den fehler?:

Java:
public void setLeft(boolean b) {
  left = b;
 }
 public void setRight(boolean b) {
  right = b;
 }
 public void setjumping(boolean b) {
  if(!falling) {
   jumping = true;
  }
 }
 public void update() {
 
  // determine next position
  if(left) {
   dx -= moveSpeed;
   if(dx < -maxSpeed) {
    dx = -maxSpeed;
   }
  }else if(right) {
   dx += moveSpeed;
   if(dx>maxSpeed) {
    dx = maxSpeed;
   }
  }else {
   if(dx>0) {
    dx -= stopSpeed;
    if(dx < 0) {
     dx=0;
    }
   }else if(dx < 0) {
    dx += stopSpeed;
    if(dx >0) {
     dx = 0;
    }
   }
  }
 
  if(jumping) {
   dy = jumpStart;
   falling = true;
   jumping = false;
  }
 
  if(falling) {
   dy += gravity;
   if(dy > maxFallingSpeed) {
    dy = maxFallingSpeed;
   }
  }else {
   dy = 0;
  }
 
  //check collisions
 
  int currCol = tileMap.getColTile((int)x);
  int currRow = tileMap.getColTile((int)y);
 
  double tox = x+dx;
  double toy = y+dy;
 
  double tempx = x;
  double tempy = y;
 
  calculateCorners(x,toy);
  if(dy <0) {
   if(topLeft || topRight) {
    dy =0;
    tempy = currRow * tileMap.getTileSize()+height/2;
   }else {
    tempy += y;
   }
  }
  if(dy >0) {
   if(bottomLeft || bottomRight) {
    dy = 0;
    falling = false;
    tempy = (currRow + 1)*tileMap.getTileSize()-height/2;
   }else {
    tempy += dy;
   }
  }
 
  calculateCorners(tox, y);
  if(dx <0) {
   if(topLeft || bottomLeft) {
    dx = 0;
    tempx = currCol*tileMap.getTileSize()+width/2;
   }else {
    tempx += dx;
   }
  }
  if(dx>0) {
   if(topRight || bottomRight) {
    dx = 0;
    tempx = (currCol+1)*tileMap.getTileSize() - width/2;
   }else {
    tempx += dx;
   }
  }
  if(!falling) {
   calculateCorners(x, y+1);
   if(!bottomLeft && !bottomRight) {
    falling=true;
   }
  }
  x = tempx;
  y = tempy;
 
  //Move the map
//  tileMap.setx((int)(Gui.WIDTH/2-x));
//  tileMap.sety((int)(Gui.HEIGHT/2-y));
 
  //Sprite animation
  if(left || right) {
   animation.setFrames(walkingSprite);
   animation.setDelay(100);
  }else {
   animation.setFrames(idleSprite);
   animation.setDelay(-1);
  }
  if(dy <0) {
   animation.setFrames(jumpingSprite);
   animation.setDelay(-1);
  }
  if(dy>0) {
   animation.setFrames(fallingSprite);
   animation.setDelay(-1);
  }
  animation.update();
  if(dx <0) {
   facingLeft=true;
  }
  if(dx > 0) {
   facingLeft = false;
  }
 }
 private void calculateCorners(double x, double y) {
  int leftTile = tileMap.getColTile((int)(x-width/2));
  int rightTile = tileMap.getColTile((int)(x+width/2) - 1);
  int topTile = tileMap.getRowTile((int)(y-height/2));
  int bottomTile = tileMap.getRowTile((int)(y+height/2) - 1);
 
  topLeft = tileMap.isBlocked(topTile, leftTile);
  topRight = tileMap.isBlocked(topTile, rightTile);
  bottomLeft = tileMap.isBlocked(bottomTile, leftTile);
  bottomRight = tileMap.isBlocked(bottomTile, rightTile);
 }

LG und vielen Dank ^^
 
Könntest du bitte mal den Link zum Game reinstellen? Würde mich jetzt schon mal interessieren, weil es da tatsächlich mal sehr gute Tutorials gab! 😀
Ansonsten kann ich dir leider gerade nicht verraten, wieso dein Charakter nicht läuft. In deinem Code kann ich jetzt auf den ersten Blick keinen Fehler erkennen. Vllt. werden setLeft() und setRight() gar nicht aufgerufen?
 

Neue Themen


Zurück
Oben