/// <summary> /// Class for creating a character with a wheel used to move and a body /// </summary> /// <param name="world">The world that the character is being added to</param> /// <param name="position">The position in the world that the character is being added to</param> /// <param name="texture">The texture that is being used for the character</param> /// <param name="size">The size of the texture</param> public CompositeCharacter(World world, Vector2 position, Texture2D texture, Vector2 size, Color characterColor) : base(world, position, texture, size) { if (size.X > size.Y) { throw new Exception("Cannot make character with width > height"); } if (characterColor != null) { CharacterColor = characterColor; } else { CharacterColor = Color.White; } input = new Input(this); texWidth = (int)size.X; texHeight = (int)size.Y; Dead = false; State = CharState.Idle; Direction = CharDirection.Right; body.OnCollision += new OnCollisionEventHandler(OnBodyCollision); wheel.OnCollision += new OnCollisionEventHandler(OnWheelCollision); body.OnSeparation += new OnSeparationEventHandler(body_OnSeparation); body.CollisionCategories = Category.Cat30; wheel.CollisionCategories = Category.Cat30; }
/// <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 input = new Input(); GraphicsDevice.BlendState = BlendState.AlphaBlend; dpsLockDepthWrite = new DepthStencilState(); dpsLockDepthWrite.DepthBufferWriteEnable = false; DepthStencilState dpsUnLockDepthWrite = new DepthStencilState(); dpsUnLockDepthWrite.DepthBufferWriteEnable = true; //graphics.PreferredBackBufferWidth = 1280; //graphics.PreferredBackBufferHeight = 720; //b = new Bat(-11f, Vector3.UnitZ, Vector3.Up, 0.9f, 0.9f, 0.9f, Color.Gray, graphics); myCamera = new CameraComponent(graphics); //model = new GameModel(this, Content, myCamera, Matrix.Identity, e, "box"); //Components.Add(model); float width = 2.0f; float height = 1.2f; tunnel = new Tunnel(this, graphics, myCamera, Content, 1, 15, Vector3.Zero, Vector3.Backward, Vector3.Up, width, height); frontBat = new Bat(-2.0f, Vector3.Backward, Vector3.Up, .2f, .2f, Color.Red, myCamera, graphics, width, height); backBat = new Bat(-15.0f, Vector3.Backward, Vector3.Up, .2f, .2f, Color.Green, myCamera, graphics, width, height); Components.Add(tunnel); base.Initialize(); }
public KeyBindingControl(Input.KeyBinding kb) { binding = kb; InitializeComponent(); lblAlias.Text = binding.Alias; lblEvent.Text = binding.KeyEvent.ToString(); UpdateBindingKeyAlias(); }
private void CheckKeyState(Keys key, Input input) { if (_keyState.IsKeyDown(key)) { if (_FireNewInput != null) { _FireNewInput(this, new InputEventArgs(input)); } } }
public override void Update(GameInfo gameInfo, Input input) { base.Update(gameInfo, input); if (input.PushABXY(PlayerIndex)) { Attack(); } Vector2 leftStick = input.LeftStick(PlayerIndex); if (Math.Abs(leftStick.X) < 0.5 && leftStick.Y > 0.5) { Move(Direction.UP); } else if (Math.Abs(leftStick.X) < 0.5 && leftStick.Y < -0.5) { Move(Direction.DOWN); } else if (leftStick.X > 0.5 && Math.Abs(leftStick.Y) < 0.5) { Move(Direction.RIGHT); } else if (leftStick.X < -0.5 && Math.Abs(leftStick.Y) < 0.5) { Move(Direction.LEFT); } #warning デバッグ用 1Pだけキーボードで操作できる #region キーボード操作 if (PlayerIndex == PlayerIndex.One && !input.GamePadConnect(PlayerIndex.One)) { if (input.PushKey(Keys.Z)) { Attack(); } if (input.PushKey(Keys.Down)) { Move(Direction.DOWN); } if (input.PushKey(Keys.Right)) { Move(Direction.RIGHT); } if (input.PushKey(Keys.Up)) { Move(Direction.UP); } if (input.PushKey(Keys.Left)) { Move(Direction.LEFT); } } #endregion }
public override void HandleInput(Input input) { if (input.WasButtonPressed(Keys.Escape)) { this.ExitScreen(); ScreenManager.AddScreen(new MenuScreen(), null); } if (input.WasButtonPressed(Keys.Enter)) { //Pause the game } base.HandleInput(input); }
protected override void OnKeyPressed(object sender, Input.Events.KeyboardPressedEventArgs e) { switch (e.Key) { case Keys.Left: sceneManager.Load<UtilityTestScene>(); break; case Keys.Right: sceneManager.Load<AudioTestScene>(); break; } base.OnKeyPressed(sender, e); }
public void CheckKeyState(Keys key, Input fireInput) { if (_keyState.IsKeyDown(key)) { if (!ThrottleInput || (ThrottleInput && _lastKeyState.IsKeyUp(key))) { if (_FireNewInput != null) { _FireNewInput(this, new NewInputEventArgs(fireInput)); _lastKey = key; } } } }
public Menu(Game game, ZXNA.Input.Input input, SpriteBatch spriteBatch, Rectangle bounds) : base(game) { this.game = game; this.input = input; this.spriteBatch = spriteBatch; this.bounds = bounds; Opened = true; //spriteBatch = (SpriteBatch)eTalisman.Services.GetService(typeof(SpriteBatch)); choiceBackground = game.Content.Load<Texture2D>(@"gfx\menu_item_background-300x100"); optionBackground = game.Content.Load<Texture2D>(@"gfx\menu_item_background2_selected-300x100"); spriteFont = game.Content.Load<SpriteFont>(@"font\arial"); }
protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("Font"); input = new Input(this); this.Components.Add(input); bombs = new List<Bomb>(); dog = new Dog(this, input, bombs); this.Components.Add(dog); i = 0; bombCounter = 0; text = "Bombs Passed: " + bombCounter; textPosition = new Vector2(10, 10); color = Color.Black; }
public override void HandleInput(Input.InputState input) { if (input.IsNewButtonPress(Buttons.Start) || input.IsNewKeyPress(Keys.Space) || input.IsNewKeyPress(Keys.Enter)) { if (fadeInTimer < 1f && !fadeOut) { fadeInTimer = 1f; } else if (!fadeOut) { fadeOut = true; select.Play(); } else { fadeInTimer = 0.0f; } } }
/// <summary> /// Focuses the previous or next selection button depending on if the UP or DOWN arrow keys were pressed. /// </summary> /// <param name="info">The keyboard state.</param> public override bool ProcessKeyboard(Input.KeyboardInfo info) { base.ProcessKeyboard(info); if (info.IsKeyReleased(Keys.Up) && PreviousSelection != null) { PreviousSelection.IsFocused = true; return true; } else if (info.IsKeyReleased(Keys.Down) && NextSelection != null) { NextSelection.IsFocused = true; return true; } return false; }
void MouseClick(Point pos, Input.MouseButton b) { state.MouseClick(pos, b); }
/// <summary> /// Internally check if a key is pressed, and if it is, fire an event to all attached Components with Input packaged in the EventArgs. /// </summary> /// <param name="key"></param> /// <param name="fireInput"></param> private void checkKeyState(Keys key, Input fireInput) { if (keyState.IsKeyDown(key)) { if (!BlockInput) { if (fireNewInput != null) { fireNewInput(this, new NewInputEventArgs(fireInput)); lastKey = key; } } } }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Random rnd = new Random(); input = new Input(); font = Content.Load<SpriteFont>("fonts/font"); shootEffect = Content.Load<SoundEffect>("sounds/fire"); mineEffect = Content.Load<SoundEffect>("sounds/bangSmall"); shipDeadEffect = Content.Load<SoundEffect>("sounds/bangLarge"); enemyDeadEffect = Content.Load<SoundEffect>("sounds/bangMedium"); background2 = Content.Load<Song>("sounds/Enter Sandman"); level = new Level(Content.Load<Map>("maps/" + mapNames[lev]), Content, GraphicsDevice, shootEffect, mineEffect, shipDeadEffect, enemyDeadEffect); MediaPlayer.IsRepeating = true; //MediaPlayer.Play(background2); freeCamera = new FreeCamera(GraphicsDevice, new Vector3(level.Columns / 2, 10, level.Rows / 2), new Vector3(0, 5, 0), Vector3.Up, MathHelper.PiOver4, 0.1f, 1000f); Matrix shipWorld = level.ship.World; Vector3 look = shipWorld.Forward; look.Normalize(); camera1 = new Camera(GraphicsDevice, shipWorld.Translation + (1.2f * -look) + (0.3f * shipWorld.Up), shipWorld.Translation + shipWorld.Forward, shipWorld.Up, MathHelper.PiOver4, 0.1f, 1000f); camera2 = new Camera(GraphicsDevice, shipWorld.Translation + camera2Offset, shipWorld.Translation, Vector3.Up, MathHelper.ToRadians(40), 0.1f, 100f); if(drawGrid) grid = new Grid(level.Rows, level.Columns, GraphicsDevice); if (drawXYZ) xyz = new XYZ(level.Rows, level.Columns, GraphicsDevice); if (drawPaths) paths = new Paths(level.Rows, level.Columns, level.graph.GetLinks(), GraphicsDevice); if (drawPath) path = new Path(level.getEnemyPath(), GraphicsDevice); }
public bool GetPressed(Input input) { if (CurrentController == Controller.Keyboard && InputEnabled) { switch (input) { case Input.ChangeController: return GetKey(Keys.F1); case Input.ChangeCamera: return GetKey(Keys.C); case Input.Exit: return keyboard.IsKeyDown(Keys.Escape) && previousKeyboard.IsKeyUp(Keys.Escape); case Input.Console: if (previousKeyboard.IsKeyUp(Keys.F2) && keyboard.IsKeyDown(Keys.F2)) InputEnabled = !InputEnabled; return previousKeyboard.IsKeyUp(Keys.F2) && keyboard.IsKeyDown(Keys.F2); } } else if (CurrentController == Controller.GamePad) { switch (input) { case Input.ChangeController: return previousGamePad.IsButtonUp(Buttons.Start) && gamePad.IsButtonDown(Buttons.Start); case Input.ChangeCamera: return previousGamePad.IsButtonUp(Buttons.RightStick) && gamePad.IsButtonDown(Buttons.RightStick); case Input.Exit: return gamePad.IsButtonDown(Buttons.Back); } } else if (input == Input.Console) { if (previousKeyboard.IsKeyUp(Keys.F2) && keyboard.IsKeyDown(Keys.F2)) InputEnabled = !InputEnabled; return previousKeyboard.IsKeyUp(Keys.F2) && keyboard.IsKeyDown(Keys.F2); } return false; }
public float GetState(Input input) { if (CurrentController == Controller.Keyboard && InputEnabled) { switch (input) { case Input.Thrust: return keyboard.IsKeyDown(Keys.W) ? 1.0f : 0.0f; case Input.Brake: return keyboard.IsKeyDown(Keys.S) ? 1.0f : 0.0f; case Input.Steer: return (keyboard.IsKeyDown(Keys.A) ? 1.0f : 0.0f) - (keyboard.IsKeyDown(Keys.D) ? 1.0f : 0.0f); case Input.CameraX: return (keyboard.IsKeyDown(Keys.Right) ? 1.0f : 0.0f) - (keyboard.IsKeyDown(Keys.Left) ? 1.0f : 0.0f); case Input.CameraY: return (keyboard.IsKeyDown(Keys.Up) ? 1.0f : 0.0f) - (keyboard.IsKeyDown(Keys.Down) ? 1.0f : 0.0f); } } else if (CurrentController == Controller.GamePad) { switch (input) { case Input.Thrust: return gamePad.Triggers.Right; case Input.Brake: return gamePad.Triggers.Left; case Input.Steer: return -gamePad.ThumbSticks.Left.X; case Input.CameraX: return -gamePad.ThumbSticks.Right.X; case Input.CameraY: return -gamePad.ThumbSticks.Right.Y; } } return 0.0f; }
protected override void OnLeftMouseClicked(Input.MouseInfo info) { base.OnLeftMouseClicked(info); if (isEnabled) { IsSelected = true; } }
public override void handleInput(Input.InputState inputState) { if( currentState == State.Attacking ) return; if (currentState == State.Neutral && (inputState.IsNewButtonPress(Buttons.A) || inputState.IsNewKeyPress(Keys.Space))) { currentState = State.Attacking; attackState = AttackState.Diagonal; velocity = Vector2.Zero; stateTimer = 0; return; } if (currentState == State.Neutral) { velocity = inputState.currentGamePadState.ThumbSticks.Left; velocity.Y *= -1f; acceleration = Vector2.Zero; } else { acceleration = inputState.currentGamePadState.ThumbSticks.Left * 0.1f; acceleration.Y *= -1f; return; } if (velocity.X < 0f && Math.Abs(velocity.X) > Math.Abs(velocity.Y) ) { currentSourceRect = WalkingLeft; faceDir = FaceDirection.Left; } else if (velocity.X > 0f && Math.Abs(velocity.X) > Math.Abs(velocity.Y)) { currentSourceRect = WalkingRight; faceDir = FaceDirection.Right; } else if (velocity.Y < 0f ) { currentSourceRect = WalkingUp; faceDir = FaceDirection.Up; } else if (velocity.Y > 0f) { currentSourceRect = WalkingDown; faceDir = FaceDirection.Down; } if (Keyboard.GetState().GetPressedKeys().Length > 0) { velocity = Vector2.Zero; if( inputState.currentKeyboardState.IsKeyDown(Keys.W) ) { currentSourceRect = WalkingUp; faceDir = FaceDirection.Up; velocity.Y = -1; } if (inputState.currentKeyboardState.IsKeyDown(Keys.A)) { currentSourceRect = WalkingLeft; faceDir = FaceDirection.Left; velocity.X = -1; } if (inputState.currentKeyboardState.IsKeyDown(Keys.S)) { currentSourceRect = WalkingDown; faceDir = FaceDirection.Down; velocity.Y = 1; } if (inputState.currentKeyboardState.IsKeyDown(Keys.D)) { currentSourceRect = WalkingRight; faceDir = FaceDirection.Right; velocity.X = 1; } if (velocity != Vector2.Zero) velocity.Normalize(); } //velocity.Normalize(); velocity *= maxSpeed; animSpeed = velocity.Length() / 18f; }
private void HandleMouseovers(Input mouseInput) { if (mouseInput.mType == InputType.Mouseover) { // Check for mouseovers on buttons for (var i = 0; i < mButtons.Length; i++) { if (!mButtons[i].mInvisible && mButtons[i].mRectangle.Contains((int)mouseInput.mPosition.X, (int)mouseInput.mPosition.Y)) { mButtons[i].mState = OwnButtonState.Hot; } else mButtons[i].mState = OwnButtonState.Normal; } } }
private void HandleKeyboardInput(Input keyboardInput) { // Handle keyboard input if (keyboardInput.mType != InputType.Keystroke) return; var unusedKeys = new List<Keys>(); var nothingUsed = true; if (mTextBoxes != null) { foreach (var tbox in mTextBoxes.Where(tbox => tbox.IsFocused())) { unusedKeys.AddRange(keyboardInput.mKey.Where(key => !tbox.OnKeyDown(key))); nothingUsed = false; break; } } if (nothingUsed) unusedKeys = keyboardInput.mKey.ToList(); foreach (var key in unusedKeys) { OnKeyDown(key); } }
private void HandleClicks(Input mouseInput) { // Handle clicks on buttons if (mouseInput.mType == InputType.LeftButtonDown || mouseInput.mType == InputType.RightButtonDown) { // Check for clicks on buttons for (var i = 0; i < mButtons.Length; i++) { if (!mButtons[i].mInvisible && mButtons[i].mRectangle.Contains((int)mouseInput.mPosition.X, (int)mouseInput.mPosition.Y)) { mButtons[i].mState = OwnButtonState.Pressed; } } } else if (mouseInput.mType == InputType.LeftButtonUp || mouseInput.mType == InputType.RightButtonUp) { // Check for clicks on buttons for (var i = 0; i < mButtons.Length; i++) { if (!mButtons[i].mInvisible && mButtons[i].mRectangle.Contains((int)mouseInput.mPosition.X, (int)mouseInput.mPosition.Y)) { if (mouseInput.mType == InputType.RightButtonUp) { if (mButtons[i].mActionRight != null) mButtons[i].mActionRight(); if (mButtons[i].mParameterActionRight != null) mButtons[i].mParameterActionRight(mButtons[i].mParameter); } else { if (mButtons[i].mAction != null) mButtons[i].mAction(); if (mButtons[i].mParameterAction != null) mButtons[i].mParameterAction(mButtons[i].mParameter); } } mButtons[i].mState = OwnButtonState.Normal; } } // Handle clicks on text boxes if (mouseInput.mType == InputType.LeftButtonUp && mTextBoxes != null) { foreach (TextBox tbox in mTextBoxes) { if (tbox.IsInBox(mouseInput.mPosition)) { tbox.OnClick(mouseInput.mPosition); } else { tbox.RemoveFocus(); } } } }
protected override void LoadContent() { m_input = new Input(Game); LoadKeyBindings(); m_spriteBatch = new SpriteBatch(Game.GraphicsDevice); m_physicsWorld = new World(new Vector2(0, 20)); //m_camera2D = new Camera2D(GraphicsDevice); m_scene.InitializeScene(m_spriteBatch, m_physicsWorld, m_camera); m_sphere = Game.Content.Load<Model>(@"Models\sphere"); int backBufferWidth = GraphicsDevice.PresentationParameters.BackBufferWidth; int backBufferHeight = GraphicsDevice.PresentationParameters.BackBufferHeight; m_colourRT = new RenderTarget2D(GraphicsDevice, backBufferWidth, backBufferHeight, false, SurfaceFormat.Color, DepthFormat.Depth24); m_normalRT = new RenderTarget2D(GraphicsDevice, backBufferWidth, backBufferHeight, false, SurfaceFormat.Color, DepthFormat.None); m_depthRT = new RenderTarget2D(GraphicsDevice, backBufferWidth, backBufferHeight, false, SurfaceFormat.Single, DepthFormat.None); m_lightRT = new RenderTarget2D(GraphicsDevice, backBufferWidth, backBufferHeight, false, SurfaceFormat.Color, DepthFormat.None); m_clearBufferEffect = Game.Content.Load<Effect>(@"Shaders/ClearGBuffer"); m_directionalLightEffect = Game.Content.Load<Effect>(@"Shaders/DirectionalLight"); m_combineFinalEffect = Game.Content.Load<Effect>(@"Shaders/CombineFinal"); m_pointLightEffect = Game.Content.Load<Effect>(@"Shaders/PointLight"); m_halfPixel.X = 0.5f / (float)GraphicsDevice.PresentationParameters.BackBufferWidth; m_halfPixel.Y = 0.5f / (float)GraphicsDevice.PresentationParameters.BackBufferHeight; base.LoadContent(); }
protected override void OnMouseIn(Input.MouseInfo info) { isMouseOver = true; base.OnMouseIn(info); }
protected override void OnMouseExit(Input.MouseInfo info) { isMouseOver = false; base.OnMouseExit(info); }
void MouseDown(Point pos, Input.MouseButton b) { state.MouseDown(pos, b); }
void MouseUp(Point pos, Input.MouseButton b) { state.MouseUp(pos, b); }
public Dog(Game1 game, Input input, List<Bomb> bombs) : this(game) { this.input = input; this.bombs = bombs; }
public virtual void Update(GameTime gameTime, Input mouseInput, Input keyboardInput) { HandleClicks(mouseInput); HandleMouseovers(mouseInput); HandleKeyboardInput(keyboardInput); }
/// <summary> /// Called when the control should process keyboard information. /// </summary> /// <param name="info">The keyboard information.</param> /// <returns>True if the keyboard was handled by this control.</returns> public override bool ProcessKeyboard(Input.KeyboardInfo info) { if (info.IsKeyReleased(Keys.Space) || info.IsKeyReleased(Keys.Enter)) { IsSelected = true; return true; } else if (Parent != null) { if (info.IsKeyReleased(Keys.Up)) Parent.TabPreviousControl(); else if (info.IsKeyReleased(Keys.Down)) Parent.TabNextControl(); return true; } return false; }