This site requires JavaScript, please enable it in your browser!
Greenfoot back
chrissy098
chrissy098 wrote ...

2014/1/7

character speed change

chrissy098 chrissy098

2014/1/7

#
im trying to change the speed a character moves at by using an else if statment. its not working, any ideas?
private void moveLeft()
    {
        setLocation(getX()-1, getY());
    }
     private void moveRight()
    {
        setLocation(getX()+1, getY());
    }
     private void moveUp()
    {
        setLocation(getX(), getY()-2);
    }
     private void moveDown()
    {
        setLocation(getX(), getY()+2);
    }
    private void SmoveUp()
    {
        setLocation(getX(), getY()-1);
    }
     private void SmoveDown()
    {
        setLocation(getX(), getY()+1);
    }
    
    
    
    private void checkKeyPress()
    {
        if (Greenfoot.isKeyDown("left"))
        {
            moveLeft();
        }

        if (Greenfoot.isKeyDown("right"))
        {
            moveRight();
        }
 
        if (Greenfoot.isKeyDown("up"))
        {
          if(getX()!=(200)+200)
            {
              SmoveUp();
            }
             else 
               moveUp();
        }
  
        if (Greenfoot.isKeyDown("down"))
        {
             if(getX()!=(200)+200)
            {
                SmoveDown();
            }
           else 
               moveDown();
        }
    }
erdelf erdelf

2014/1/7

#
what do u want exactly`? u wrote that if the down key is pressed it should check if the x-coordinate isn't 400, if yes then it should move down field if not two fields
chrissy098 chrissy098

2014/1/7

#
it doesnt work though, it keeps to the speed of Smove instead of move
erdelf erdelf

2014/1/7

#
well, is the x coordinate not 400`?
You need to login to post a reply.