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(); } }
// Update is called once per frame void Update() { scoreStr = Mathf.FloorToInt(score).ToString(); scoreText.text = "Score: " + scoreStr; if (Input.GetKey(KeyCode.LeftShift)) { playerControllerScript.dashing = true; movingObjects = FindMovingObjects(); foreach (GameObject movingGO in movingObjects) { moveLeftScript = movingGO.GetComponent <MoveLeft>(); moveLeftScript.dashing = true; } } else { playerControllerScript.dashing = false; movingObjects = FindMovingObjects(); foreach (GameObject movingGO in movingObjects) { moveLeftScript = movingGO.GetComponent <MoveLeft>(); moveLeftScript.dashing = false; } } }
void SpawnObstacle() { if (!playerControllerScript.isGameOver) { int obstacleIndex = Random.Range(0, obstacles.Length); if (obstacleIndex == 3 || obstacleIndex == 4) { GameObject obstacle = Instantiate(obstacles[obstacleIndex], spawnPosHumans, obstacles[obstacleIndex].transform.rotation); // spawn obstacle Move_Forward obshumanScript = obstacle.GetComponent <Move_Forward>(); obshumanScript.speed = obshumanScript.speed + (float)obstaclesDestroyedCount; // transform int to f float randomDelay = Random.Range(repeatRateMin, repeatRateMax); Debug.Log("Random interval" + randomDelay); Invoke("SpawnObstacle", randomDelay); } else { GameObject obstacle = Instantiate(obstacles[obstacleIndex], spawnPos, obstacles[obstacleIndex].transform.rotation); // spawn obstacle MoveLeft obsScript = obstacle.GetComponent <MoveLeft>(); //retrieve script from spawned obstacles obsScript.speed = obsScript.speed + (float)obstaclesDestroyedCount; // transform int to float float randomDelay = Random.Range(repeatRateMin, repeatRateMax); Debug.Log("Random interval" + randomDelay); Invoke("SpawnObstacle", randomDelay); } } }
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(); }
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 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); } }
// 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(); } }
// 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(); } }
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(); } }
// 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(); } }
// Start is called before the first frame update void Start() { spawnPos = new Vector3(spawnPosX, spawnPosY, spawnPosZ); playerControllerScript = GameObject.Find("Player").GetComponent <PlayerController>(); moveLeftScript = GameObject.Find("Background").GetComponent <MoveLeft>(); InvokeRepeating("SpawnObstacle", startDelay, repeatRate); }
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(); } } }
// 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(); }
IEnumerator IsGameOver() { while (true) { //if the game is over, stop spawning obstacles, //create a list of everything that's moving left //and stop them from moving left if (playerControllerScript.isGameOver) { spawnManagerScript.StopCoroutine("SpawnObstacles"); StopCoroutine("ScoreCounter"); movingObjects = FindMovingObjects(); foreach (GameObject movingGO in movingObjects) { moveLeftScript = movingGO.GetComponent <MoveLeft>(); moveLeftScript.StopCoroutine("MoveMeLeft"); } finalScoreText.text = "updated"; restartButton.gameObject.SetActive(true); scoreText.gameObject.SetActive(false); finalScoreText.text = "Final Score: " + scoreStr; finalScoreText.gameObject.SetActive(true); yield break; } yield return(null); } }
private void Form1_KeyUp(object sender, KeyEventArgs e) {//Stops movement when key is lifted MoveUp.Stop(); MoveDown.Stop(); MoveRight.Stop(); MoveLeft.Stop(); }
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(); } }
public void MoveLeft() { Icommand command = new MoveLeft(position, player); CommandManager.instance.AddComponent(command); position = position + new Vector3(0, 0, -2); }
// This is the method defined for the MoveLeft event. Mark this event as private // if you will never override it. Otherwise mark it as protected virtual. /// <summary> /// Raises the <see cref="MoveLeft"/> event. /// </summary> protected virtual void OnMoveLeft(MovedLeftEventArgs e) { // Check to see if the event is handled anywhere (in simple terms). // This is where you send data to event handlers. // Send the object related to the event as first argument (in my case this control). // Send in e which is the event args passed in from onMouseMove with the moveAmountData. MoveLeft?.Invoke(this, e); }
public Option <ListZipper <A> > MoveLeftN(int n) { return(n == 0 ? this.Some() : n < 0 ? MoveRightN(Math.Abs(n)) : MoveLeft.SelectMany(z => z.MoveLeftN(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; } }
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); }
// Start is called before the first frame update void Start() { button = GetComponent <Button>(); playerController = GameObject.Find("Player").GetComponent <PlayerController>(); moveLeft = GameObject.Find("Crate_01").GetComponent <MoveLeft>(); spawnManager = GameObject.Find("Spawn Manager").GetComponent <SpawnManager>(); repeatBackground = GameObject.Find("Background").GetComponent <RepeatBackground>(); button.onClick.AddListener(SetDifficulty); }
private static void BindKeys() { buttonW = new MoveForward(); buttonS = new MoveBackward(); buttonA = new MoveLeft(); buttonD = new MoveRight(); //buttonZ = new MoveForward(); }
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(); } }
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(); }
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); }
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; } }
void Start() { //Bind keys with commands buttonB = new DoNothing(); buttonW = new MoveUp(); buttonS = new MoveDown(); buttonA = new MoveLeft(); buttonD = new MoveRight(); elementStartPos = elementTrans.position; }
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); } } } }