//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DWControllerDemo { #region Using Statements using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using DarkWynter.Engine.Controllers; #endregion /// /// Game Controller for getting player inputs in-game /// public class GameController : Controller { /// /// Constructor for PC and mouse controls /// /// Player index for this controller public GameController(int playerNumber) : base(playerNumber) { Add(new KeyboardControl(Keys.Escape, Escape, 3000)); Add(new KeyboardControl(Keys.M, SwitchGameMode, 100)); Add(new KeyboardControl(Keys.W, MoveForward, 10)); Add(new KeyboardControl(Keys.A, MoveLeft, 10)); Add(new KeyboardControl(Keys.D, MoveRight, 10)); Add(new KeyboardControl(Keys.S, MoveBackward, 10)); Add(new MouseControl(ControlType.LeftButton, ChangeColorPos, 100)); Add(new MouseControl(ControlType.LeftButton, ChangeColorNeg, 100, 0)); //Add(new KeyboardControl(Keys.Up, ChangeColorPos, 100)); Add(new KeyboardControl(Keys.Down, ChangeColorNeg, 100)); Add(new MouseControl(ControlType.Motion, Motion, 0)); } /// /// Constructor for Xbox only controls /// /// public GameController(PlayerIndex playerIndex) : base(playerIndex) { // Add xbox controls } /// /// Constructor for Xbox and keyboard controls /// /// Player index in ObjectLibrary /// Player index for this controller public GameController(int player, PlayerIndex playerIndex) : base(player, playerIndex) { Add(new KeyboardControl(Keys.Escape, Escape, 3000)); Add(new KeyboardControl(Keys.M, SwitchGameMode, 100)); Add(new KeyboardControl(Keys.W, MoveForward, 0)); Add(new KeyboardControl(Keys.A, MoveLeft, 0)); Add(new KeyboardControl(Keys.D, MoveRight, 0)); Add(new KeyboardControl(Keys.S, MoveBackward, 0)); Add(new KeyboardControl(Keys.Up, ChangeColorPos, 100)); Add(new KeyboardControl(Keys.Down, ChangeColorNeg, 100)); Add(new MouseControl(ControlType.Motion, Motion, 0)); } private void Escape(ControllerBoolEventArgs args) { ControllerDemo._self.Exit(); } private void SwitchGameMode(ControllerBoolEventArgs args) { ControllerDemo._self.gameMode = ControllerDemo.GameMode.Menu; } private void MoveForward(ControllerBoolEventArgs args) { } private void Motion(ControllerVec2EventArgs args) { ControllerDemo._self.MoveMouse(args); } private void MoveBackward(ControllerBoolEventArgs args) { } private void MoveLeft(ControllerBoolEventArgs args) { } private void MoveRight(ControllerBoolEventArgs args) { } private void ChangeColorPos(ControllerBoolEventArgs args) { Vector4 color = ControllerDemo._self.backColor.ToVector4(); color.X += .1f; // R color.Y -= .1f; // G color.Z += .3f; // B ControllerDemo._self.backColor = new Microsoft.Xna.Framework.Graphics.Color(color); } private void ChangeColorNeg(ControllerBoolEventArgs args) { Vector4 color = ControllerDemo._self.backColor.ToVector4(); color.X -= .1f; // R color.Y += .1f; // G color.Z -= .3f; // B ControllerDemo._self.backColor = new Microsoft.Xna.Framework.Graphics.Color(color); } } }