// Update is called once per frame void FixedUpdate() { rb.AddForce(0, 0, forwardForce * Time.deltaTime); if (Input.GetKey("d")) { Command commandRight = new MoveRight(m_PlayerReceiver, rb, text); Invoker invoker = new Invoker(); invoker.SetCommand(commandRight); invoker.ExecuteCommand(); } if (Input.GetKey("a")) { Command commandLeft = new MoveLeft(m_PlayerReceiver, rb, text); Invoker invoker = new Invoker(); invoker.SetCommand(commandLeft); invoker.ExecuteCommand(); } if (rb.position.y < -1f) { FindObjectOfType <GameManager>().EndGame(); } }
Command GetCommand(Action Action) { Command cmd = null; switch (Action) { case Action.LEFT: cmd = new MoveLeft(m_rebel); break; case Action.RIGHT: cmd = new MoveRight(m_rebel); break; case Action.JUMP: cmd = new Jump(m_rebel); break; case Action.DUCK: cmd = new Duck(m_rebel); break; case Action.COLOR: cmd = new ChangeColor(m_rebel); break; } return(cmd); }
// Start is called before the first frame update void Start() { KeyW = new MoveUp(); KeyS = new MoveDown(); KeyA = new MoveLeft(); KeyD = new MoveRight(); }
public void Move(KeyboardState keyboardState, KeyboardState previousState) { ICommand cmd = null; if (keyboardState.IsKeyDown(Keys.W) && !previousState.IsKeyDown(Keys.W)) { cmd = new MoveForward(this); } if (keyboardState.IsKeyDown(Keys.S) && !previousState.IsKeyDown(Keys.S)) { cmd = new MoveBackward(this); } if (keyboardState.IsKeyDown(Keys.A) && !previousState.IsKeyDown(Keys.A)) { cmd = new MoveLeft(this); } if (keyboardState.IsKeyDown(Keys.D) && !previousState.IsKeyDown(Keys.D)) { cmd = new MoveRight(this); } if (cmd != null) { MoveMemory.SaveState(SaveMemento()); cmd.Execute(); Notify(); } }
// Update is called once per frame void FixedUpdate() { rb.AddForce(0, 0, forwardForce * Time.deltaTime); if (Input.GetKey("d")) // MOVE RIGHT { //////////////////////////////////////////////////////////////////////////// // --- IMPLEMENTING THE COMMAND PATTERN - START HERE --- // instead of just calling addforce, we want to package this up as a command // and send to an invoker // we'll need a command class, some commands, and an invoker... //rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveRight = new MoveRight(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveRight); invoker.ExecuteCommand(); } if (Input.GetKey("a")) // MOVE LEFT { //rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveLeft = new MoveLeft(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveLeft); invoker.ExecuteCommand(); } if (rb.position.y < -1f) { FindObjectOfType <GameManager>().EndGame(); } }
private void Update() { var keyboard = Keyboard.current; if (keyboard == null) { return; } if (Enabled) { if (keyboard.spaceKey.wasPressedThisFrame) { JumpForward?.Invoke(); } if (keyboard.aKey.wasPressedThisFrame) { MoveLeft?.Invoke(); } if (keyboard.dKey.wasPressedThisFrame) { MoveRight?.Invoke(); } } }
// Update is called once per frame void FixedUpdate() { rb.AddForce(0, 0, forwardForce * Time.deltaTime); if (Input.GetKey("d")) // MOVE RIGHT { Command moveRight = new MoveRight(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveRight); invoker.ExecuteCommand(); } if (Input.GetKey("a")) // MOVE LEFT { //rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveLeft = new MoveLeft(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveLeft); invoker.ExecuteCommand(); } if (rb.position.y < -1f) { FindObjectOfType <GameManager>().EndGame(); } }
void FixedUpdate() { rb.AddForce(0, 0, forwardForce * Time.deltaTime); if (Input.GetKey("d")) { Command moveRight = new MoveRight(rb, sideForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveRight); commandsUI.text += "\n" + moveRight.ToString(); invoker.ExecuteCommand(); } if (Input.GetKey("a")) { Command moveLeft = new MoveLeft(rb, sideForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveLeft); commandsUI.text += "\n" + moveLeft.ToString(); invoker.ExecuteCommand(); } if (rb.position.y < -1f) { FindObjectOfType <GameManager>().EndGame(null); } if (rb.GetComponentInParent <Transform>().position.z > milestoneScore) { OnMilestone?.Invoke(); } }
//public Text commandLog; // We marked this a s"Fixed"Update because we // are using it to mess with physics void FixedUpdate() { // Add a forward force rb.AddForce(0, 0, forwardForce * Time.deltaTime); if (Input.GetKey("d")) { // Only executed if condition is met //rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveR = new MoveRight(rb, sidewaysForce); Invoker invoke = new Invoker(); invoke.SetCommand(moveR); //commandLog.text += moveR.ToString() + "\n"; invoke.ExeCommand(); } if (Input.GetKey("a")) { // Only executed if condition is met //rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveL = new MoveLeft(rb, sidewaysForce); Invoker invoke = new Invoker(); invoke.SetCommand(moveL); invoke.ExeCommand(); //commandLog.text += moveL.ToString() + "\n"; } if (rb.position.x < -8f || rb.position.x > 8f) { FindObjectOfType <gameManager>().endGame(null); } }
private void Form1_KeyUp(object sender, KeyEventArgs e) {//Stops movement when key is lifted MoveUp.Stop(); MoveDown.Stop(); MoveRight.Stop(); MoveLeft.Stop(); }
// We marked this as "Fixed"Update because we // are using it to mess with physics void FixedUpdate() { // Add a forward force rb.AddForce(0, 0, forwardForce * Time.deltaTime); if (Input.GetKey("d") || Input.GetKey(KeyCode.RightArrow)) // If the player is perssing the "d" key { // Add a force to the right // Add a force to the right //rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveRight = new MoveRight(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveRight); invoker.ExecuteCommand(); } if (Input.GetKey("a") || Input.GetKey(KeyCode.LeftArrow)) // If the player is pressing the "a" key { // Add a force to the left //rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveLeft = new MoveLeft(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveLeft); invoker.ExecuteCommand(); } if (rb.position.y < -1f) { // End game if player falls off ground FindObjectOfType<GameManager>().EndGame(); } }
public void MoveRight() { Icommand command = new MoveRight(position, player); CommandManager.instance.AddComponent(command); position = position + new Vector3(0, 0, 2); }
void FixedUpdate() { //Add a forward force on the object rb.AddForce(0, 0, forwardsForce * Time.deltaTime); //Get user input and move object accordingly if (Input.GetKey("d")) { Command moveRight = new MoveRight(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveRight); invoker.ExecuteCommand(); } if (Input.GetKey("a")) { Command moveLeft = new MoveLeft(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveLeft); invoker.ExecuteCommand(); } //End game if the object falls off the platform if (rb.position.y < -1f) { FindObjectOfType <GameManager>().EndGame(); } }
// FixedUpdate is called evenly across framerates void FixedUpdate() { //Get the rigidbody by FORCE if (replayMode == true) { if (Invoker.log.Count != 0 && Invoker.log.Peek() != null) { if (Invoker.log.Peek().timeStart <= Time.timeSinceLevelLoad) { currentCommand = Invoker.log.Dequeue(); currentCommand.playerBody = GetComponent <Rigidbody>(); invoker.SetCommand(currentCommand, Time.timeSinceLevelLoad, true); //Debug.Log("Changed active movement"); } if (currentCommand != null && currentCommand.timeEnd <= Time.timeSinceLevelLoad) { invoker.SetCommand(noMovement, Time.timeSinceLevelLoad, true); } } } else { if (Input.GetKeyDown("d")) { Command moveRight = new MoveRight(rb, sidewaysForce); invoker.SetCommand(moveRight, Time.timeSinceLevelLoad); } if (Input.GetKeyDown("a")) { Command moveLeft = new MoveLeft(rb, sidewaysForce); invoker.SetCommand(moveLeft, Time.timeSinceLevelLoad); } if (Input.GetKeyUp("d")) { invoker.Clear("D"); //Debug.Log("D up"); } if (Input.GetKeyUp("a")) { invoker.Clear("A"); //Debug.Log("A up"); } } if (rb.position.y < -1f) { //End the game if the player goes off the edge if (replayMode == true) { Invoker.log.Clear(); } FindObjectOfType <GameManager>().EndGame(); } rb.AddForce(0, 0, forwardForce * Time.deltaTime); invoker.ExecuteCommand(); }
void ReleaseDesignerOutlets() { if (MoveUp != null) { MoveUp.Dispose(); MoveUp = null; } if (MoveLeft != null) { MoveLeft.Dispose(); MoveLeft = null; } if (MoveRight != null) { MoveRight.Dispose(); MoveRight = null; } if (MoveDown != null) { MoveDown.Dispose(); MoveDown = null; } if (ZoomLevel != null) { ZoomLevel.Dispose(); ZoomLevel = null; } }
public Option <ListZipper <A> > MoveRightN(int n) { return(n == 0 ? this.Some() : n < 0 ? MoveLeftN(Math.Abs(n)) : MoveRight.SelectMany(z => z.MoveRightN(n - 1))); }
void GetRandomBlock() { int RandomPosition = rand.Next(0, 4); switch (RandomBlock) { case 0: t_block = new T_Block(StartPoint, RandomPosition, BlockSize, board); moveLeft = t_block.MoveLeft; moveRight = t_block.MoveRight; moveDown = t_block.MoveDown; rotate = t_block.Rotate; BlockColor = t_block.color; returnCoordinates = t_block.returnCoordinates; break; case 1: square = new Square(StartPoint, BlockSize, board); moveLeft = square.MoveLeft; moveRight = square.MoveRight; moveDown = square.MoveDown; rotate = square.Rotate; BlockColor = square.color; returnCoordinates = square.returnCoordinates; break; case 2: stick = new Stick(StartPoint, RandomPosition, BlockSize, board); moveLeft = stick.MoveLeft; moveRight = stick.MoveRight; moveDown = stick.MoveDown; rotate = stick.Rotate; BlockColor = stick.color; returnCoordinates = stick.returnCoordinates; break; case 3: z_block = new Z_Block(StartPoint, RandomPosition, BlockSize, board); moveLeft = z_block.MoveLeft; moveRight = z_block.MoveRight; moveDown = z_block.MoveDown; rotate = z_block.Rotate; BlockColor = z_block.color; returnCoordinates = z_block.returnCoordinates; break; // default: break; } }
private static void BindKeys() { buttonW = new MoveForward(); buttonS = new MoveBackward(); buttonA = new MoveLeft(); buttonD = new MoveRight(); //buttonZ = new MoveForward(); }
public Vec2 NeedVel() { Vec2 t = Vec2.Zero; t += MoveLeft.Pressed() ? new Vec2(-1, 0) : Vec2.Zero; t += MoveRight.Pressed() ? new Vec2(1, 0) : Vec2.Zero; t += MoveDown.Pressed() ? new Vec2(0, -1) : Vec2.Zero; return(t); }
public void Schoolyard() { if (!schoolyard) { MoveRight instanceOfMoveRight = GameObject.Find("Location").GetComponent <MoveRight>(); instanceOfMoveRight.changeText("Schoolyard"); schoolyard = true; } }
void FixedUpdate() { //this is a standtard push that scales diretly to frame rate //Time.deltaTime negates the frame rate diffirences and the really high number helps the cube to actually move rb.AddForce(0, 0, forwardSpeed * Time.deltaTime); if (Input.GetKey("d")) { Command _moveRight = new MoveRight(rb, lateralSpeed); Invoker invoker = new Invoker(); invoker.SetCommand(_moveRight); invoker.ExecuteComand(); //commandDisplay.text += "\n" + _moveRight.ToString(); } if (Input.GetKey("a")) { Command _moveLeft = new MoveLeft(rb, lateralSpeed); Invoker invoker = new Invoker(); invoker.SetCommand(_moveLeft); // commandDisplay.text += "\n" + _moveLeft.ToString(); invoker.ExecuteComand(); } if (Input.GetKey("w")) { Command _moveUp = new MoveUp(rb, lateralSpeed); Invoker invoker = new Invoker(); invoker.SetCommand(_moveUp); // commandDisplay.text += "\n" + _moveUp.ToString(); invoker.ExecuteComand(); } if (Input.GetKey("s")) { //loacal _moveDown //calling the command in commmand Command _moveDown = new MoveDown(rb, lateralSpeed); Invoker invoker = new Invoker(); invoker.SetCommand(_moveDown); // commandDisplay.text += "\n" + _moveDown.ToString(); invoker.ExecuteComand(); } if (rb.position.y < -1f) { FindObjectOfType <GameManager>().EndGame(); } if (rb.GetComponentInParent <Transform>().position.z > halfWay) { OnHalfWay?.Invoke(); } }
private void Start() { prevMoves = new Stack <char>(); pc = new PlayerController(player); leftCommand = new MoveLeft(pc); rightCommand = new MoveRight(pc); backCommand = new MoveBack(pc); forwardCommand = new MoveForward(pc); }
public InputHandler(Player player, TileMapFacade tileMapFacade) { this._player = player; this._tilemap = tileMapFacade; //Bind keys with commands buttonW = new MoveForward(); buttonS = new MoveBackward(); buttonA = new MoveLeft(); buttonD = new MoveRight(); }
void GetRandomBlock() { int RandomPosition = rand.Next(0, 4); switch (RandomBlock) { case 0: t_block = new T_Block(StartPoint, RandomPosition, BlockSize,board); moveLeft = t_block.MoveLeft; moveRight = t_block.MoveRight; moveDown = t_block.MoveDown; rotate = t_block.Rotate; BlockColor = t_block.color; returnCoordinates = t_block.returnCoordinates; break; case 1: square = new Square(StartPoint, BlockSize,board); moveLeft = square.MoveLeft; moveRight = square.MoveRight; moveDown = square.MoveDown; rotate = square.Rotate; BlockColor = square.color; returnCoordinates = square.returnCoordinates; break; case 2: stick = new Stick(StartPoint, RandomPosition, BlockSize,board); moveLeft = stick.MoveLeft; moveRight = stick.MoveRight; moveDown = stick.MoveDown; rotate = stick.Rotate; BlockColor = stick.color; returnCoordinates = stick.returnCoordinates; break; case 3: z_block = new Z_Block(StartPoint, RandomPosition, BlockSize,board); moveLeft = z_block.MoveLeft; moveRight = z_block.MoveRight; moveDown = z_block.MoveDown; rotate = z_block.Rotate; BlockColor = z_block.color; returnCoordinates = z_block.returnCoordinates; break; // default: break; } }
public void Update() { //Check keys in keymap //Has Released Keys foreach (var item in keyMap.OnReleasedKeyMap) { if (Input.GetKeyUp(item.Key)) { Debug.Log(string.Format("onReleasedKeyMap Key released {0}", item.Value.ToString())); //Log key to console Command command = null; switch (item.Value) { case "Move Up": //trigger Move Up command command = new MoveUp(); break; case "Move Down": //trigger Move Down command command = new MoveDown(); break; case "Move Left": //trigger Move Left command command = new MoveLeft(); break; case "Move Right": //trigger Move Down command command = new MoveRight(); break; case "Undo": if (Commands.Count > 0) { command = (Command)Commands.Pop(); if (command is ICommandWithUndo) //if the popped command has an undo command use it { command = ((ICommandWithUndo)command).UndoCommand; } } break; } if (command != null) { if (command is ICommandWithUndo) { Commands.Push((ICommandWithUndo)command); //only push commands with undo to the stack } command.Execute(MoveCommandTarget); } } } }
void Start() { //Bind keys with commands buttonB = new DoNothing(); buttonW = new MoveUp(); buttonS = new MoveDown(); buttonA = new MoveLeft(); buttonD = new MoveRight(); elementStartPos = elementTrans.position; }
private void OnTick(object sender, float duration) { if (Input.GetKey(KeyCode.D)) { MoveRight?.Invoke(this, duration); } if (Input.GetKey(KeyCode.A)) { MoveLeft?.Invoke(this, duration); } }
public override void Update(GameTime gameTime) { var kstate = Keyboard.GetState(); if (kstate.IsKeyDown(slowMode)) { speed = (speed == originalSpeed) ? speed / slowModeModifier : speed * slowModeModifier; } if (kstate.IsKeyDown(godMode) && pastKey.IsKeyUp(godMode)) { isGod = !isGod; } // for testing the win states if (kstate.IsKeyDown(win) && pastKey.IsKeyUp(win)) { winner = 1; // win -> see win screen } //for testing lose life if (kstate.IsKeyDown(hit) && pastKey.IsKeyUp(hit)) { if (invincible == false) { takeHit(); //player is hit } } if (kstate.IsKeyDown(upKey)) { position = new MoveUp(speed).getNewPosition(position, velocity); } if (kstate.IsKeyDown(downKey)) { position = new MoveDown(speed).getNewPosition(position, velocity); } if (kstate.IsKeyDown(leftKey)) { position = new MoveLeft(speed).getNewPosition(position, velocity); } if (kstate.IsKeyDown(rightKey)) { position = new MoveRight(speed).getNewPosition(position, velocity); } if (kstate.IsKeyDown(shootKey) && pastKey.IsKeyUp(shootKey)) { shoot(); } pastKey = Keyboard.GetState(); bulletsUpdateAndCleanup(gameTime); }
// Update is called per tick void FixedUpdate() { rb.AddForce(0, -9.8f * Time.deltaTime, 0); if (bIsReplaying) { return; //Running a replay, ignore active inputs } if (Input.GetKey("d")) //Move Right { //rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveRight = new MoveRight(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveRight); invoker.ExecuteCommand(); } if (Input.GetKey("a")) //Move Left { //rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); Command moveLeft = new MoveLeft(rb, sidewaysForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveLeft); invoker.ExecuteCommand(); } if (Input.GetKey("w")) //Move Forward { //rb.AddForce(0, 0, sidewaysForce * Time.deltaTime, ForceMode.VelocityChange); Command moveForward = new MoveForward(rb, forwardForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveForward); invoker.ExecuteCommand(); } if (Input.GetKey("s")) //Move Backwards { //rb.AddForce(0, 0, -sidewaysForce * Time.deltaTime, ForceMode.VelocityChange); Command moveBack = new MoveBack(rb, forwardForce); Invoker invoker = new Invoker(); invoker.SetCommand(moveBack); invoker.ExecuteCommand(); } if (rb.position.y < -2f) {//Reset if off the map FindObjectOfType <game_manager>().GameEnd(); } }
public void SetCommandTest() { Player player = new Player("id", "username", 0); player.SetPos(50, 50); Map map = new Map(23 * 25, 19 * 25); MapFacade mapFacade = map.mapFacade; ICommand command = new MoveRight(player, mapFacade); player.SetCommand(command); player.Move(); Assert.IsTrue(50 != player.x || 50 != player.y); }
void Start() { moveforward = new MoveFoward(); movebackward = new MoveBackward(); moveright = new MoveRight(); moveleft = new MoveLeft(); jump = new Jump(); forwardkey = KeyCode.W; backwardkey = KeyCode.S; leftkey = KeyCode.A; rightkey = KeyCode.D; jumpkey = KeyCode.Space; }