本文整理汇总了C#中InputHelper.KeyPressed方法的典型用法代码示例。如果您正苦于以下问题:C# InputHelper.KeyPressed方法的具体用法?C# InputHelper.KeyPressed怎么用?C# InputHelper.KeyPressed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InputHelper
的用法示例。
在下文中一共展示了InputHelper.KeyPressed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleInput
// Methods
public void HandleInput(InputHelper inputHelper)
{
if (inputHelper.KeyPressed(Keys.R))
Color = Color.Red;
else if (inputHelper.KeyPressed(Keys.G))
Color = Color.Green;
else if (inputHelper.KeyPressed(Keys.B))
Color = Color.Blue;
double opposite = inputHelper.MousePosition.Y - barrelPosition.Y;
double adjacent = inputHelper.MousePosition.X - barrelPosition.X;
angle = (float)Math.Atan2(opposite, adjacent);
}
示例2: HandleInput
/// <summary>Enables going to the next level.</summary>
public override void HandleInput(InputHelper inputHelper)
{
if (!(inputHelper.KeyPressed(Keys.Space) || inputHelper.ControlerButtonPressed(Buttons.A)))
return;
GameEnvironment.GameStateManager.SwitchTo("playingState");
(playingState as PlayingState).NextLevel();
}
示例3: HandleInput
public override void HandleInput(InputHelper inputHelper)
{
if (!inputHelper.KeyPressed(Keys.Space))
return;
playingState.Reset();
GameEnvironment.GameStateManager.SwitchTo("playingState");
}
示例4: HandleInput
public override void HandleInput(InputHelper inputHelper)
{
if (inputHelper.KeyPressed(Keys.Space))
if (can_shoot == 0)
{
this.visible = true;
Mirror = true;
}
}
示例5: HandleInput
public override void HandleInput(InputHelper inputHelper)
{
base.HandleInput(inputHelper);
if (inputHelper.KeyPressed(Keys.R))
cannonColor.Color = Color.Red;
else if (inputHelper.KeyPressed(Keys.G))
cannonColor.Color = Color.Green;
else if (inputHelper.KeyPressed(Keys.B))
cannonColor.Color = Color.Blue;
double opposite = inputHelper.MousePosition.Y - cannonBarrel.GlobalPosition.Y;
double adjacent = inputHelper.MousePosition.X - cannonBarrel.GlobalPosition.X;
cannonBarrel.Angle = (float)Math.Atan2(opposite, adjacent);
if (inputHelper.MouseLeftButtonPressed() && !ball.Shooting)
ball.Shoot(inputHelper, cannonColor, cannonBarrel);
}
示例6: HandleInput
/// <summary>Handle user input.</summary>
public override void HandleInput(InputHelper inputHelper)
{
float walkingSpeed = 400;
if (walkingOnIce)
walkingSpeed *= 1.5f;
if (!isAlive)
return;
if (inputHelper.IsKeyDown(Keys.Left) || inputHelper.IsKeyDown(Keys.A) || inputHelper.IsControlerButtonDown(Buttons.DPadLeft) || inputHelper.GetLeftControlerStick() == Direction.Left)
velocity.X = -walkingSpeed;
else if (inputHelper.IsKeyDown(Keys.Right) || inputHelper.IsKeyDown(Keys.D) || inputHelper.IsControlerButtonDown(Buttons.DPadRight) || inputHelper.GetLeftControlerStick() == Direction.Right)
velocity.X = walkingSpeed;
else if (!walkingOnIce && isOnTheGround)
velocity.X = 0.0f;
if (velocity.X != 0.0f)
Mirror = velocity.X < 0;
if ((inputHelper.KeyPressed(Keys.Up) || inputHelper.KeyPressed(Keys.W) || inputHelper.ControlerButtonPressed(Buttons.DPadUp) || inputHelper.ControlerButtonPressed(Buttons.A)) && isOnTheGround)
Jump();
if (inputHelper.KeyPressed(Keys.Space) || inputHelper.ControlerButtonPressed(Buttons.X))
Shoot();
}
示例7: HandleInput
public override void HandleInput(InputHelper inputHelper)
{
if (!shooting)
{
if (inputHelper.KeyPressed(Keys.Right))
{
//schieten naar rechts
shooting = true;
velocity = new Vector2(900, 0);
}
if (inputHelper.KeyPressed(Keys.Left))
{
//schieten naar links
shooting = true;
velocity = new Vector2(-900, 0);
}
if (inputHelper.KeyPressed(Keys.Up))
{
//schieten naar boven
shooting = true;
velocity = new Vector2(0, -900);
}
}
}
示例8: HandleInput
public override void HandleInput(InputHelper inputHelper)
{
if(inputHelper.KeyPressed(Keys.P))
{
InsaneKillerArcher.GameStateManager.SwitchTo("playingState");
}
if(MouseOver(inputHelper.MousePosition, overheadArrows) && inputHelper.MouseLeftButtonPressed()) {
InsaneKillerArcher.AssetManager.PlaySound("buy_shit");
overheadArrows.IsActive = true;
}
if (MouseOver(inputHelper.MousePosition, rollingBoulder) && inputHelper.MouseLeftButtonPressed())
{
InsaneKillerArcher.AssetManager.PlaySound("buy_shit");
rollingBoulder.IsActive = true;
}
if (MouseOver(inputHelper.MousePosition, boilingOil) && inputHelper.MouseLeftButtonPressed())
{
InsaneKillerArcher.AssetManager.PlaySound("buy_shit");
boilingOil.IsActive = true;
}
if (MouseOver(inputHelper.MousePosition, castleUpgrade) && inputHelper.MouseLeftButtonPressed())
{
InsaneKillerArcher.AssetManager.PlaySound("buy_shit");
castleUpgrade.UpgradeLevel();
}
if (MouseOver(inputHelper.MousePosition, archerUpgrade) && inputHelper.MouseLeftButtonPressed())
{
InsaneKillerArcher.AssetManager.PlaySound("buy_shit");
archerUpgrade.UpgradeLevel();
archerUpgrade.Claimed = false;
}
if (MouseOver(inputHelper.MousePosition, catapultUpgrade) && inputHelper.MouseLeftButtonPressed())
{
InsaneKillerArcher.AssetManager.PlaySound("buy_shit");
catapultUpgrade.UpgradeLevel();
}
base.HandleInput(inputHelper);
}
示例9: HandleInput
public override void HandleInput(InputHelper inputHelper)
{
//Berekent de Angle van het wapen van de player met behulp van de positie van de muis.
float adjacent = inputHelper.MousePosition.X - player.Position.X;
float opposite = inputHelper.MousePosition.Y - player.Position.Y;
//Heeft nog een restrictie nodig, max/min opposite en adjacent. Zodat de arm niet 360 graden kan draaien.
player.Weapon.Angle = (float)Math.Atan2(opposite, adjacent);
if (inputHelper.MouseLeftButtonDown() && canShoot)
{
Shoot(adjacent, opposite);
}
if (inputHelper.KeyPressed(Keys.P))
{
InsaneKillerArcher.GameStateManager.SwitchTo("store");
}
base.HandleInput(inputHelper);
}
示例10: HandleInput
/// <summary>
/// Handleinput for the objects in the level
/// </summary>
/// <param name="inputHelper">The inputhelper to react to input</param>
public override void HandleInput(InputHelper inputHelper)
{
if (inputHelper.KeyPressed(Keys.F) && NoteInVicinity)
{
foreach (GameObject obj in gameObjects)
{
if (obj is NoteObject)
{
foreach (Sound sound in MusicPlayer.SoundEffect)
if (sound.Name == "paperrustle")
sound.PlaySound();
NoteObject note = obj as NoteObject;
note.PickUp();
}
}
}
if (inputHelper.KeyPressed(Keys.R))
{
this.completed = true;
}
Find("Player").HandleInput(inputHelper);
}
示例11: HandleInput
/// <summary>
/// React to the input
/// </summary>
/// <param name="inputHelper">The inputhelper to react to input</param>
public override void HandleInput(InputHelper inputHelper)
{
base.HandleInput(inputHelper);
inputHelper.Update();
//Check if the exitButton is being pressed to go back to the title screen
if (exitButton.ButtonIsPressed)
{
foreach (Sound sound in MusicPlayer.Music)
{
sound.PlaySound();
}
GameEnvironment.GameStateManager.SwitchTo("titleScreenState");
}
//Check if the resumeButton is being pressed to go back to the game
if (continueButton.ButtonIsPressed || inputHelper.KeyPressed(Keys.Escape))
{
foreach (Sound sound in MusicPlayer.SoundEffect)
if (sound.Name == "paperrustle2")
sound.PlaySound();
game.IsMouseVisible = false;
Mouse.SetPosition(GameEnvironment.Screen.X / 2, GameEnvironment.Screen.Y / 2);
GameEnvironment.GameStateManager.SwitchTo("playingState");
}
//Change visibility of mouseoverbutton
if (continueButton.IsMouseOver)
continueButtonMouseOver.Visible = true;
else
continueButtonMouseOver.Visible = false;
if (exitButtonMouseOver.IsMouseOver)
exitButtonMouseOver.Visible = true;
else
exitButtonMouseOver.Visible = false;
}
示例12: HandleInput
/// <summary>
/// Handling the input concernig the note
/// </summary>
/// <param name="inputhelper">The inputhelper to react to input</param>
public override void HandleInput(InputHelper inputhelper)
{
if (inputhelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.E) && inVicinity)
PickUp();
}
示例13: HandleInput
public void HandleInput(GameTime gameTime, InputHelper inputHelper)
{
if (gameState == GameState.Playing) //Speelfase
{
blocks.HandleInput(inputHelper, i); //Het bewegen van de blokjes over het speelveld
if (inputHelper.KeyPressed(Keys.Escape))
gameState = GameState.GameOver;
}
if (gameState == GameState.Menu)
{
if (inputHelper.MouseLeftButtonPressed())
{
if (menu.PlayRect.Contains((int)inputHelper.MousePosition.X, (int)inputHelper.MousePosition.Y))
{
gameState = GameState.Playing;
}
if (menu.OptionsRect.Contains((int)inputHelper.MousePosition.X, (int)inputHelper.MousePosition.Y))
{
gameState = GameState.Options;
}
}
block1.CalculateArrayRotatingLength(4); //Hier wordt berekend hoe de blokjes moeten draaien afhankelijk van hun vorm
block2.CalculateArrayRotatingLength(4);
block3.CalculateArrayRotatingLength(4);
block4.CalculateArrayRotatingLength(4);
block5.CalculateArrayRotatingLength(4);
block6.CalculateArrayRotatingLength(4);
block7.CalculateArrayRotatingLength(4);
}
if (gameState == GameState.GameOver)
{
if (inputHelper.MouseLeftButtonPressed())
{
if (gameOver.BackRect.Contains((int)inputHelper.MousePosition.X, (int)inputHelper.MousePosition.Y))
{
score = 0;
level = 1;
levelspeed = 1;
gameState = GameState.Menu;
}
}
}
if (gameState == GameState.Options) //Optie menu
{
options.HandleInput(inputHelper);
if (inputHelper.MouseLeftButtonPressed() && options.BackRect.Contains((int)inputHelper.MousePosition.X, (int)inputHelper.MousePosition.Y)) //Het beginnen van het spel
{
block1.BlockForm = block1.CurrentBlockForm; //De bewerkte vormen moeten doorgegeven worden aan de speelfase
block2.BlockForm = block2.CurrentBlockForm;
block3.BlockForm = block3.CurrentBlockForm;
block4.BlockForm = block4.CurrentBlockForm;
block5.BlockForm = block5.CurrentBlockForm;
block6.BlockForm = block6.CurrentBlockForm;
block7.BlockForm = block7.CurrentBlockForm;
block1res.BlockForm = block1.CurrentBlockForm;
block2res.BlockForm = block2.CurrentBlockForm;
block3res.BlockForm = block3.CurrentBlockForm;
block4res.BlockForm = block4.CurrentBlockForm;
block5res.BlockForm = block5.CurrentBlockForm;
block6res.BlockForm = block6.CurrentBlockForm;
block7res.BlockForm = block7.CurrentBlockForm;
gameState = GameState.Menu;
}
}
}
示例14: HandleInput
public void HandleInput(InputHelper inputHelper)
{
if (inputHelper.KeyPressed(Keys.Up)) //Roteert blokje
{
RotateRight();
}
else if (inputHelper.KeyPressed(Keys.Down)) //Beweegt naar beneden
{
blockFormPosition += new Vector2(0, 1 * TetrisGrid.cellheight);
timelimit = TimeSpan.FromSeconds(1);
//Controleert of een blokje geplaatst moet worden
if (TetrisGrid.IsOutOfField(blockFormPosition, blockForm, color) || (TetrisGrid.CheckPlayField(blockFormPosition, blockForm, color)))
{
blockFormPosition -= new Vector2(0, 1 * TetrisGrid.cellheight);
TetrisGrid.FillOccupiedField(color, blockForm, blockFormPosition);
newBlock = true;
}
}
else if (inputHelper.KeyPressed(Keys.Left)) //Beweegt naar links
{
blockFormPosition += new Vector2(-1 * TetrisGrid.cellwidth, 0);
if (TetrisGrid.IsOutOfField(blockFormPosition, blockForm, color))
{
blockFormPosition += new Vector2(1 * TetrisGrid.cellwidth, 0);
}
if (TetrisGrid.CheckPlayField(blockFormPosition, blockForm, color))
{
blockFormPosition += new Vector2(1 * TetrisGrid.cellwidth, 0);
}
}
else if (inputHelper.KeyPressed(Keys.Right)) //Beweegt naar rechts
{
blockFormPosition += new Vector2(1 * TetrisGrid.cellwidth, 0);
if (TetrisGrid.IsOutOfField(blockFormPosition, blockForm, color))
{
blockFormPosition -= new Vector2(1 * TetrisGrid.cellwidth, 0);
}
if (TetrisGrid.CheckPlayField(blockFormPosition, blockForm, color))
{
blockFormPosition -= new Vector2(1 * TetrisGrid.cellwidth, 0);
}
}
}
示例15: HandleInput
public void HandleInput(GameTime gameTime, InputHelper inputHelper)
{
switch (gameState) {
case(GameState.GameOver):
if (inputHelper.KeyPressed(Keys.Space)) {
Reset();
}
break;
case (GameState.Paused):
if (inputHelper.KeyPressed(Keys.P, false)) {
gameState = GameState.Playing;
}
break;
case(GameState.Playing):
if (inputHelper.KeyPressed(Keys.A)) {
grid.Move(new Vector2(-1, 0));
}
if (inputHelper.KeyPressed(Keys.W, false)) {
grid.Rotate();
}
if (inputHelper.KeyPressed(Keys.D)) {
grid.Move(new Vector2(1, 0));
}
if (inputHelper.KeyPressed(Keys.S)) {
grid.Move(new Vector2(0, 1));
}
if (inputHelper.KeyPressed(Keys.Left)) {
grid.Move(new Vector2(-1, 0));
}
if (inputHelper.KeyPressed(Keys.Up, false)) {
grid.Rotate();
}
if (inputHelper.KeyPressed(Keys.Right)) {
grid.Move(new Vector2(1, 0));
}
if (inputHelper.KeyPressed(Keys.Down)) {
grid.Move(new Vector2(0, 1));
}
if (inputHelper.KeyPressed(Keys.R, false)) {
Reset();
}
if (inputHelper.KeyPressed(Keys.M, false)) {
if (Muted) {
Muted = false;
} else {
Muted = true;
}
}
if (inputHelper.KeyPressed(Keys.P, false)) {
gameState = GameState.Paused;
}
break;
}
}