Keyboard input issue

Hi I try to figure it out why I can't control my character with the keyboard but Im lost here the code its too long to share here if anybody could look at it would be much appreciated

Tagged:

Answers

  • Please describe the problem. What do you mean you cannot control your character? What are you trying to do?

    Kf

  • edited March 2017

    I tried to share the code but I cant show it here properly because

    here are the variables in the main tab

    public float bellyXloc, bellyYloc;
    public float bellyWidth, bellyHeight;
    public float accelerationX,accelerationY;
    public float decelerationX, decelerationY;
    public PVector location, acceleration, deceleration;
    public float max_speedx,max_speedy ;
    public float gravity;
    public color characterColor;
    public Boolean   isLeft=false ,  isRight=false , isUp= false ;
    

    constructor

     bellyXloc=width/2;
      bellyYloc=height/2; //-(1.6*bellyHeight);
      bellyWidth=width/20;
      bellyHeight= height*0.1;
      characterColor = color(152,223,234);
      location = new PVector(bellyXloc,bellyYloc);
      accelerationX=1.3;
      accelerationY=0;
      max_speedx = 5;
      max_speedy = 3;
      acceleration = new PVector(accelerationX,accelerationY);
      decerelationX = 0.75;
      decerelationY = 0.75;
      deceleration = new PVector(decelerationX, decelerationY);
      gravity = .3;
    
    
      a = new AlienCharacter(location,bellyWidth,bellyHeight, color(152,223,234),
                            acceleration, max_speedx, max_speedy, decerelation ,gravity);
    

    in the class void update

    void update() {
    if ( isRight ) {
      location.add(acceleration);
      if ( acceleration.x > max_speedx ) {
        max_speedx = acceleration.x;
      }
    }
    else if ( isLeft ) {
      location.sub(acceleration);
      if ( acceleration.x < -max_speedx ) {
        max_speedx = acceleration.x;
      }
    }
    else { //neither right or left pressed, decelerate
      if ( acceleration.x > 0 ) {
        acceleration.x -= deceleration.x;
        if ( acceleration.x < 0 ) {
          acceleration.x = 0;
        }
      }
      else if ( acceleration.x < 0 ) {
        acceleration.x += deceleration.x;
        if ( acceleration.x > 0 ) {
          acceleration.x = 0;
        }
      }
      }
    
      if ( isUp ) {
      location.sub(acceleration);
        if ( acceleration.y-0.5 < -max_speedy ) {
        max_speedy = acceleration.y*deceleration.y;
      }
      }
    

    and in the main tab

      void keyPressed() {
      switch(keyCode) {
      case RIGHT: isRight  = true; break;
      case LEFT: isLeft = true; break;
      case UP: isUp = true; break;
      }
      }
      void keyReleased() {
      switch(keyCode) {
      case RIGHT: isRight = false; break;
      case LEFT: isLeft = false; break;
      case UP: isUp = false; break;
    
      }
      }
    

    The problem that character doesn't react to keyboard

  • First thing:
    deceleration <--> decerelation are different :)

  • I "purposely" wrote so people can correct me, but It doesn't work with the rest so far

Sign In or Register to comment.