本文整理汇总了C#中Microsoft.Xna.Framework.Input.KeyboardState类的典型用法代码示例。如果您正苦于以下问题:C# KeyboardState类的具体用法?C# KeyboardState怎么用?C# KeyboardState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyboardState类属于Microsoft.Xna.Framework.Input命名空间,在下文中一共展示了KeyboardState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public override void Update()
{
// Bounding Box
rectangle = new Rectangle
(
(int)Position.X,
(int)Position.Y,
(int)Size.X,
(int)Size.Y
);
KeyboardState keyboardState = Keyboard.GetState();
if (Keyboard.GetState().IsKeyDown(Keys.D))
{
Position += movingVector;
body.ApplyLinearImpulse(movingImpulse);
}
else if (Keyboard.GetState().IsKeyDown(Keys.A))
{
Position -= movingVector;
body.ApplyLinearImpulse(-movingImpulse);
}
if (Keyboard.GetState().IsKeyDown(Keys.W) && !prevKeyboardState.IsKeyDown(Keys.W))
{
if ((DateTime.Now - previousJump).TotalSeconds >= jumpInterval)
{
jumpEffect.Play();
body.ApplyLinearImpulse(jumpingImpulse);
previousJump = DateTime.Now;
}
}
prevKeyboardState = keyboardState;
}
示例2: move
public override void move(ArrayList colidables)
{
KeyboardState newKeyBoardState = Keyboard.GetState();
if (newKeyBoardState.IsKeyDown(Keys.Up))
{
if (checkCollision(colidables, 0, +velocity) == true)
y -= velocity;
}
else if (newKeyBoardState.IsKeyDown(Keys.Down))
{
if (checkCollision(colidables, 0, -velocity) == true)
y += velocity;
}
else if (newKeyBoardState.IsKeyDown(Keys.Left))
{
if (checkCollision(colidables, velocity, 0) == true)
x -= velocity;
}
else if (newKeyBoardState.IsKeyDown(Keys.Right))
{
if (checkCollision(colidables, -velocity, 0) == true)
x += velocity;
}
oldKeyBoardState = newKeyBoardState;
hitBox = new Rectangle(x, y, width, height);
}
示例3: Update
public int Update(GameTime gameTime)
{
KeyboardState keyState;
keyState = Keyboard.GetState(PlayerIndex.One);
if (keyState.IsKeyDown(Keys.Up) && !prevKeyState.IsKeyDown(Keys.Up))
{
if (selected > 0)
{
selected--;
}
}
if (keyState.IsKeyDown(Keys.Down) && !prevKeyState.IsKeyDown(Keys.Down))
{
if (selected < buttonList.Count - 1)
{
selected++;
}
}
if (keyState.IsKeyDown(Keys.Enter))
{
return selected;
}
prevKeyState = keyState;
return -1;
}
示例4: Console
private Console()
{
booleanValues = new Dictionary<string, bool>();
floatValues = new Dictionary<string, float>();
integerValues = new Dictionary<string, int>();
integerValues.Add("consoleHeight", 512);
integerValues.Add("consoleWidth", 768);
integerValues.Add("consolePositionX", 64);
integerValues.Add("consolePositionY", 64);
integerValues.Add("consoleBorderWidth", 16);
integerValues.Add("consoleAlpha", 220);
booleanValues.Add("consoleActive", false);
commandHistory = new ConsoleHistory(120);
messageHistory = new ConsoleHistory(120);
lines = new List<String>();
currentCommand = "";
lastState = new KeyboardState();
booleanValues.Add("texInfo", false);
booleanValues.Add("meshCountInfo", false);
booleanValues.Add("showPosition", false);
booleanValues.Add("occluderInfo", false);
booleanValues.Add("drawshadowtex", false);
booleanValues.Add("glow", true);
floatValues.Add("hdrpower", 4.0f);
}
示例5: Update
public void Update()
{
previousMouseState = currentMouseState;
previousKeyboardState = currentKeyboardState;
currentMouseState = Mouse.GetState();
currentKeyboardState = Keyboard.GetState();
}
示例6: Input
public Input(MouseState cms, MouseState pms, KeyboardState cks, KeyboardState pks)
{
Pms = pms;
Pks = pks;
Cms = cms;
Cks = cks;
}
示例7: HandleKeyboardInput
public override void HandleKeyboardInput(KeyboardState oldKeyboardState)
{
KeyboardState currentKeyboardState = Keyboard.GetState();
if (currentKeyboardState.IsKeyDown(Keys.Escape)
&& oldKeyboardState.IsKeyUp(Keys.Escape))
videoPlayer.Stop();
}
示例8: kill
public void kill(KeyboardState kb, MouseState ms)
{
stateTimer = 0.0f;
state = State.EXIT;
this.update(kb, ms);
this.init();
}
示例9: accessObject
public void accessObject(LLESprite playerCharacter, KeyboardState keyboardState, KeyboardState prevKeyboardState)
{
mPlayerCharacter = playerCharacter;
if (playerCharacter != null && (playerCharacter.getDirection() == LLESprite.DIRECTION_UP || playerCharacter.getDirection() == LLESprite.DIRECTION_LEFT_UP || playerCharacter.getDirection() == LLESprite.DIRECTION_RIGHT_UP)
&& keyboardState.IsKeyDown(Keys.Z) == true && prevKeyboardState.IsKeyDown(Keys.Z) == false)
{
for (int i = 0; i < mapObjects.Count; i++)
{
if (mapObjects[i] != null && mapObjects[i].getSprite() != null)
{
LLESprite target = mapObjects[i].getSprite();
if (playerCharacter.isCollidingMap(new Vector4(target.getX(), target.getY(), target.getHeight(), target.getWidth()), new Vector2(cameraX, cameraY), false, true, 4) == true)
{
scriptProcessor.extractObjectVariables(mapObjects[i]);
attack = false;
break;
}
}
}
}
}
示例10: Check
public void Check(KeyboardState last, KeyboardState curr)
{
if (last == null)
return;
if (!matchMods(curr))
return;
switch (KeyEvent)
{
case KeyEvent.Released:
if (!(keyDown(Key, last) && keyUp(Key, curr)))
return;
break;
case KeyEvent.Pressed:
if (!(keyUp(Key, last) && keyDown(Key, curr)))
return;
break;
case KeyEvent.Down:
if (!(keyDown(Key, curr)))
return;
break;
case KeyEvent.Up:
if (!(keyUp(Key, curr)))
return;
break;
default:
return;
}
// we made it through! Do something freakin' awesome
CallDelegate();
}
示例11: Update
public static void Update(MouseState mouse, KeyboardState keyboard)
{
MouseMoving(mouse);
MouseClicking(mouse);
DevInput(mouse, keyboard);
}
示例12: Update
public void Update(KeyboardState k)
{
PressedFire = IsPressed(k, Fire, FireKey);
PressedBlock = IsPressed(k, Block, BlockKey);
PressedSpecial = IsPressed(k, Special, SpecialKey);
PressedUse = IsPressed(k, Use, UseKey);
PressedUp = IsPressed(k, Up, UseKey);
PressedLeft = IsPressed(k, Left, LeftKey);
PressedRight = IsPressed(k, Right, RightKey);
PressedDown = IsPressed(k, Down, DownKey);
PressedInventoryR = IsPressed(k, InventoryR, InventoryRKey);
PressedInventoryL = IsPressed(k, InventoryL, InventoryLKey);
PressedStart = IsPressed(k, Start, StartKey);
Fire = IsHeld(k, Fire, FireKey);
Block = IsHeld(k, Block, BlockKey);
Special = IsHeld(k, Special, SpecialKey);
Use = IsHeld(k, Use, UseKey);
Up = IsHeld(k, Up, UpKey);
Left = IsHeld(k, Left, LeftKey);
Right = IsHeld(k, Right, RightKey);
Down = IsHeld(k, Down, DownKey);
InventoryR = IsHeld(k, InventoryR, InventoryRKey);
InventoryL = IsHeld(k, InventoryL, InventoryLKey);
Start = IsHeld(k, Start, StartKey);
}
示例13: Update
public void Update(Player player, KeyboardState keyboard, MouseState mouse, Engine engine)
{
// Rortational Origin
Rectangle originRect = new Rectangle((int)position.X, (int)position.Y,
(int)texture.Width, (int)texture.Height);
origin = new Vector2(originRect.Width / 2, originRect.Height / 2);
int viewDistance = 200;
double distance = Math.Sqrt(Math.Pow(player.position.X - position.X, 2) +
Math.Pow(player.position.Y - position.Y, 2));
if (distance < viewDistance)
{
float deltaX = player.position.X - position.X;
float deltaY = player.position.Y - position.Y;
float radians = (float)Math.Atan2(deltaY, deltaX);
setRotation(radians);
float zombieSpeed = 1.5f;
float dx = (float) Math.Cos(rotation) * zombieSpeed;
float dy = (float) Math.Sin(rotation) * zombieSpeed;
position.X += dx;
position.Y += dy;
}
}
示例14: Update
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
currentstate = Keyboard.GetState();
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
else
{
if (currentstate.IsKeyDown(Keys.A) && !oldstate.IsKeyDown(Keys.A))
{
sounds[0].Play();
//var sd = soundEffects[0].CreateInstance();
//sd.IsLooped = false;
//sd.Play();
//sd.Dispose();
}
if (currentstate.IsKeyDown(Keys.R) && !oldstate.IsKeyDown(Keys.R)) { rd.BMS파일분석(); }
if (currentstate.IsKeyDown(Keys.Y) && !oldstate.IsKeyDown(Keys.Y)) { rd.노트시간계산();sdmgr.시간들 = rd.시간들; }
if (currentstate.IsKeyDown(Keys.S) && !oldstate.IsKeyDown(Keys.S))
{
sdmgr.Play();
//var sd = soundEffects[1].CreateInstance();
//sd.Play();
}
oldstate = currentstate;
}
base.Update(gameTime);
}
示例15: Initialize
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
oldstate = Keyboard.GetState();
base.Initialize();
}