private void Update() { bool isPressed = PlayerKeyboard.IsKeyboardThrustersOn; if (isPressed && Thrusters.OfShipInitialized) { //determine how to move the ship PlayerMoveEnum choice = PlayerMoveEnum.Undetermined; if (Input.GetAxis("Horizontal") > 0) //right { choice = PlayerMoveEnum.LeftThruster; } else if (Input.GetAxis("Horizontal") < 0) //left { choice = PlayerMoveEnum.RightThruster; } if (Input.GetAxis("Vertical") > 0) //up { //retain horizontal movement in choice choice = (PlayerMoveEnum)((int)PlayerMoveEnum.BottomThruster + (int)choice); } //determine how much to move in choice direction Thrusters thrusters = new Thrusters() { ThrusterBottom = Globals.BottomThruster, ThrusterLeft = Globals.LeftThruster, ThrusterRight = Globals.RightThruster, }; Vector3 shipForce = thrusters.ThrustOn(choice); //move the ship Globals.PlayerShip.AddForce(shipForce); } }
private Rect createButton(PlayerMoveEnum choice) { float margin = 1; float left; float top = Screen.height / 2 + margin; float width = Screen.width / 3 - (2 * margin); float height = Screen.height / 2 - (2 * margin); switch (choice) { //top row of buttons case PlayerMoveEnum.LeftThruster: left = 0 + margin; return new Rect(left, margin, width, height); case PlayerMoveEnum.RightThruster: left = (Screen.width * 2) / 3 + margin; return new Rect(left, margin, width, height); //bottom row of buttons case PlayerMoveEnum.LeftBottomThruster: left = 0 + margin; return new Rect(left, top, width, height); case PlayerMoveEnum.BottomThruster: left = Screen.width / 3 + margin; return new Rect(left, top, width, height); case PlayerMoveEnum.RightBottomThruster: left = (Screen.width * 2) / 3 + margin; return new Rect(left, top, width, height); case PlayerMoveEnum.Undetermined: default: return button; } }
public void ThrustShipOn(PlayerMoveEnum activeThrusters) { if (Globals.PlayerShip != null) { Vector3 shipForce = getThrust(activeThrusters); Globals.PlayerShip.AddForce(shipForce); } else { throw new Exception("Globals.PlayerShip need to be set before ThrustShipOn() can be used"); } }
public void ThrustShipOn(PlayerMoveEnum activeThrusters) { if (Globals.PlayerShip != null) { Vector3 shipForce = getThrust(activeThrusters); Globals.PlayerShip.AddForce(shipForce); } else { throw new Exception("Globals.PlayerShip need to be set before ThrustShipOn() can be used"); } }
private Vector3 getThrust(PlayerMoveEnum direction) { float sideThrust = 600 * Time.deltaTime; float bottomThrust = 2000 * Time.deltaTime; switch (direction) { case PlayerMoveEnum.LeftThruster: ThrusterBottom.Emit(0); ThrusterLeft.Emit(1); ThrusterRight.Emit(0); return(new Vector3(sideThrust, 0, 0)); case PlayerMoveEnum.RightThruster: ThrusterBottom.Emit(0); ThrusterLeft.Emit(0); ThrusterRight.Emit(1); return(new Vector3(-sideThrust, 0, 0)); case PlayerMoveEnum.LeftBottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(1); ThrusterRight.Emit(0); return(new Vector3(sideThrust, bottomThrust, 0)); case PlayerMoveEnum.BottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(0); ThrusterRight.Emit(0); return(new Vector3(0, 30, 0)); case PlayerMoveEnum.RightBottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(0); ThrusterRight.Emit(1); return(new Vector3(-sideThrust, bottomThrust, 0)); case PlayerMoveEnum.Undetermined: default: ThrusterBottom.Emit(0); ThrusterLeft.Emit(0); ThrusterRight.Emit(0); return(new Vector3(0, 0, 0)); } }
private Vector3 getThrust(PlayerMoveEnum direction) { float sideThrust = 600 * Time.deltaTime; float bottomThrust = 2000 * Time.deltaTime; switch (direction) { case PlayerMoveEnum.LeftThruster: ThrusterBottom.Emit(0); ThrusterLeft.Emit(1); ThrusterRight.Emit(0); return new Vector3(sideThrust,0,0); case PlayerMoveEnum.RightThruster: ThrusterBottom.Emit(0); ThrusterLeft.Emit(0); ThrusterRight.Emit(1); return new Vector3(-sideThrust,0,0); case PlayerMoveEnum.LeftBottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(1); ThrusterRight.Emit(0); return new Vector3(sideThrust,bottomThrust,0); case PlayerMoveEnum.BottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(0); ThrusterRight.Emit(0); return new Vector3(0,30,0); case PlayerMoveEnum.RightBottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(0); ThrusterRight.Emit(1); return new Vector3(-sideThrust,bottomThrust,0); case PlayerMoveEnum.Undetermined: default: ThrusterBottom.Emit(0); ThrusterLeft.Emit(0); ThrusterRight.Emit(0); return new Vector3(0,0,0); } }
public Vector3 ThrustOn(PlayerMoveEnum direction) { if (Thrusters.HaveFuel == false) return new Vector3(0, 0, 0); //update fuel usage if (direction != PlayerMoveEnum.Undetermined) { float fuelRemaining = Globals.Game.FuelRemaining; fuelRemaining -= fuelBurnSpeed * Time.deltaTime; if (fuelRemaining <= State.FuelMinimum) //we ran out of fuel { fuelRemaining = State.FuelMinimum; //uses 0.01 because a value of 0 causes trouble in handling division by zero ThrusterBottom.Emit(0); ThrusterLeft.Emit(0); ThrusterRight.Emit(0); Globals.Game.FuelRemaining = fuelRemaining; return new Vector3(0, 0, 0); } Globals.Game.FuelRemaining = fuelRemaining; } float sideThrust = 600 * Time.deltaTime; float bottomThrust = 2000 * Time.deltaTime; switch (direction) { case PlayerMoveEnum.LeftThruster: ThrusterBottom.Emit(0); ThrusterLeft.Emit(1); ThrusterRight.Emit(0); return new Vector3(sideThrust, 0, 0); case PlayerMoveEnum.RightThruster: ThrusterBottom.Emit(0); ThrusterLeft.Emit(0); ThrusterRight.Emit(1); return new Vector3(-sideThrust, 0, 0); case PlayerMoveEnum.LeftBottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(1); ThrusterRight.Emit(0); return new Vector3(sideThrust, bottomThrust, 0); case PlayerMoveEnum.BottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(0); ThrusterRight.Emit(0); return new Vector3(0, bottomThrust, 0); case PlayerMoveEnum.RightBottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(0); ThrusterRight.Emit(1); return new Vector3(-sideThrust, bottomThrust, 0); case PlayerMoveEnum.Undetermined: default: ThrusterBottom.Emit(0); ThrusterLeft.Emit(0); ThrusterRight.Emit(0); return new Vector3(0, 0, 0); } }
public Vector3 ThrustOn(PlayerMoveEnum direction) { if (Thrusters.HaveFuel == false) { return(new Vector3(0, 0, 0)); } //update fuel usage if (direction != PlayerMoveEnum.Undetermined) { float fuelRemaining = Globals.Game.FuelRemaining; fuelRemaining -= fuelBurnSpeed * Time.deltaTime; if (fuelRemaining <= State.FuelMinimum) //we ran out of fuel { fuelRemaining = State.FuelMinimum; //uses 0.01 because a value of 0 causes trouble in handling division by zero ThrusterBottom.Emit(0); ThrusterLeft.Emit(0); ThrusterRight.Emit(0); Globals.Game.FuelRemaining = fuelRemaining; return(new Vector3(0, 0, 0)); } Globals.Game.FuelRemaining = fuelRemaining; } float sideThrust = 600 * Time.deltaTime; float bottomThrust = 2000 * Time.deltaTime; switch (direction) { case PlayerMoveEnum.LeftThruster: ThrusterBottom.Emit(0); ThrusterLeft.Emit(1); ThrusterRight.Emit(0); return(new Vector3(sideThrust, 0, 0)); case PlayerMoveEnum.RightThruster: ThrusterBottom.Emit(0); ThrusterLeft.Emit(0); ThrusterRight.Emit(1); return(new Vector3(-sideThrust, 0, 0)); case PlayerMoveEnum.LeftBottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(1); ThrusterRight.Emit(0); return(new Vector3(sideThrust, bottomThrust, 0)); case PlayerMoveEnum.BottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(0); ThrusterRight.Emit(0); return(new Vector3(0, bottomThrust, 0)); case PlayerMoveEnum.RightBottomThruster: ThrusterBottom.Emit(1); ThrusterLeft.Emit(0); ThrusterRight.Emit(1); return(new Vector3(-sideThrust, bottomThrust, 0)); case PlayerMoveEnum.Undetermined: default: ThrusterBottom.Emit(0); ThrusterLeft.Emit(0); ThrusterRight.Emit(0); return(new Vector3(0, 0, 0)); } }