// Check input by the user public void CheckKeys() { if (Hardware.KeyPressed(Hardware.KEY_UP)) { if (Hardware.KeyPressed(Hardware.KEY_RIGHT)) { player.JumpRight(); direction = 'R'; } else if (Hardware.KeyPressed(Hardware.KEY_LEFT)) { player.JumpLeft(); direction = 'L'; } else { player.Jump(); } } else if (Hardware.KeyPressed(Hardware.KEY_RIGHT)) { player.MoveRight(); direction = 'R'; } else if (Hardware.KeyPressed(Hardware.KEY_LEFT)) { player.MoveLeft(); direction = 'L'; } //if (Hardware.KeyPressed(Hardware.KEY_DOWN)) // player.MoveDown(); if ((Hardware.KeyPressed(Hardware.KEY_SPC)) && (!myShot.IsVisible())) { if (direction == 'R') { myShot = new Shot(this, player.GetX() + 20, player.GetY(), 10); } else { myShot = new Shot(this, player.GetX(), player.GetY(), -10); } } if (Hardware.KeyPressed(Hardware.KEY_ESC)) { finished = true; } }
// Check input by the user public void CheckKeys() { if ((Hardware.KeyPressed(Hardware.KEY_RIGHT)) && (currentLevel.IsValidMove( player.GetX() + player.GetSpeedX(), player.GetY(), player.GetX() + player.GetWidth() + player.GetSpeedX(), player.GetY() + player.GetHeight()))) { player.MoveRight(); Hardware.ScrollHorizontally((short)-player.GetSpeedX()); direction = 'R'; } if ((Hardware.KeyPressed(Hardware.KEY_LEFT)) && (currentLevel.IsValidMove( player.GetX() - player.GetSpeedX(), player.GetY(), player.GetX() + player.GetWidth() - player.GetSpeedX(), player.GetY() + player.GetHeight()))) { player.MoveLeft(); Hardware.ScrollHorizontally((short)player.GetSpeedX()); direction = 'L'; } if ((Hardware.KeyPressed(Hardware.KEY_DOWN)) && (currentLevel.IsValidMove( player.GetX(), player.GetY() + player.GetSpeedY(), player.GetX() + player.GetWidth(), player.GetY() + player.GetHeight() + player.GetSpeedY()))) { player.MoveDown(); Hardware.ScrollVertically((short)-player.GetSpeedY()); direction = 'D'; } if ((Hardware.KeyPressed(Hardware.KEY_UP)) && (currentLevel.IsValidMove( player.GetX(), player.GetY() - player.GetSpeedY(), player.GetX() + player.GetWidth(), player.GetY() + player.GetHeight() - player.GetSpeedY()))) { player.MoveUp(); Hardware.ScrollVertically((short)player.GetSpeedY()); direction = 'U'; } if ((Hardware.KeyPressed(Hardware.KEY_SPC)) && (!myShot.IsVisible()) && (!shoting)) { if (direction == 'R') { myShot = new Shot(currentLevel, player.GetX(), player.GetY(), 10, 0); } if (direction == 'L') { myShot = new Shot(currentLevel, player.GetX(), player.GetY(), -10, 0); } if (direction == 'U') { myShot = new Shot(currentLevel, player.GetX(), player.GetY(), 0, -10); } if (direction == 'D') { myShot = new Shot(currentLevel, player.GetX(), player.GetY(), 0, 10); } } if (Hardware.KeyPressed(Hardware.KEY_ESC)) { finished = true; } }