2014-12-03 51 views
0

我对编程真的很陌生。对于我的班级,我正在制作一款游戏,并且我想在游戏中添加一名秒针玩家。目前,在游戏中随机出现黑色圆圈并保持增长。你是一个圈子,你需要尽可能避免圈子。一旦你与一个游戏相交,游戏就结束了。这个圆圈由箭头键控制。不过,我想用钥匙WASD添加一个新的圆。这是我的代码到目前为止。但是当游戏开始时,我可以看到这个圈子,但我无法移动它。用钥匙添加新玩家WASD

我担心的代码的主要部分是ProcessUserInput2,因为那是控制WASD的代码。我没有粘贴我的整个代码。任何帮助,将不胜感激

void draw() 
{ 
    //Call functions 

    if (gameState == 0)//Start Screen 
    { 
    ProccessUserInput_Start(); //this function is in a separate tab. It processes what the player inputs into the computer, and then translates it into commands 
    Render_Start(); 
    savedTime = millis(); 
    } 
    if (gameState == 1)//Game Playing Screen 
    { 

    ProcessUserInput1(); //this is for the arrow keys 
    ProcessUserInput2(); //this is for WASD 
    Render(); 
    totalTime = 40000; //Timer (in millis) 
    for (growingEllipse e:ellipses) 
    { 
     e.ellipseGrow(); 
     e.rendering(); 
    } 

void ProcessUserInput1() 
//Move circle Left, Right, Up or Down using arrow keys 
{ 
    if (keyPressed) 
    { 
    if (keyCode == LEFT)//Move Left 
    { 
     x1 = x1 - 2; 
    } 
    if (keyCode == RIGHT)//Move Right 
    { 
     x1 = x1 + 2; 
    } 
    if (keyCode == UP)//Move Up 
    { 
     y1 = y1 - 2; 
    } 
    if (keyCode == DOWN)//Move Down 
    { 
     y1 = y1 + 2; 
    } 
    } 
} 

    void ProcessUserInput2() 
//Move circle Left, Right, Up or Down using arrow keys 
{ 
    if (keyPressed) 
    { 
    if (keyCode == 'A')//Move Left 
    { 
     x2 = x2 - 2; 
    } 
    if (keyCode == 'D')//Move Right 
    { 
     x2 = x2 + 2; 
    } 
    if (keyCode == 'W')//Move Up 
    { 
     y2 = y2 - 2; 
    } 
    if (keyCode == 'S')//Move Down 
    { 
     y2 = y2 + 2; 
    } 
    } 
} 

void Render() 
{ 
    background(255); 
    fill(255, 228, 196); 
    ellipse (x1, y1, r1, r1); 
    ellipse (x2, y2, r1, r1); 
    //draw circle for player 
} 

如果可能的话,可以在任何真正优秀的程序员给我他们的电子邮件,这样我可以问他们问题?我仍然需要添加几个项目,例如继承和函数重载。我为此使用了处理应用程序。

+2

nottice你只捕捉'caps' char – 2014-12-03 10:45:44

回答

0

您正在使用keyCode变量,它只能用于没有关联字符的箭头键。

相反,您可能想要使用键变量,该变量是一个字符并且包含键入的字符。

此处了解详情:http://staticvoidgames.com/tutorials/intermediateConcepts/keyboardInput

编辑:此外,作为尔迪说,你只抓住大写字母。而且请不要要求电子邮件,因为这会破坏像这样的公共场所。