public void Awake() { cState = controllerState.OFF_ALL; dropState = dropBtnState.OFFLINE; deliveryState = limbDeliveryState.SEARCHING; dropInvoked = false; liftingLimb = false; uiScreenSwitched = false; clawXStart = claw.transform.localPosition.x; clawZStart = claw.transform.localPosition.z; rope = GetComponent <LineRenderer> (); limbCount = 0; beamRotationY = 0f; beamRotationX = 180f; targetRotationX = 0f; targetRotationY = 0f; clawExtension = 0f; targetExtension = 0f; rotationStateX = 0f; rotationStateY = 0f; clawHeight = claw.transform.localPosition.y; restHeight = clawHeight; bottomHeight = clawHeight + armLength; currentDrop = 0.0f; targetDrop = 0.0f; audio = GetComponent <AudioSource> (); }
public void Move(controllerState state) { amountToMove = Vector3.zero; viewportPosition = _camera.WorldToViewportPoint(transform.position); if(state.horizontal > 0.0f) //if going right { if(viewportPosition.x + (state.horizontal * _stats.speed) < 1.0f) { amountToMove.x = (state.horizontal * _stats.speed); } } else if(state.horizontal < 0.0f) //if going left { if(viewportPosition.x + (state.horizontal * _stats.speed) > 0.0f) { amountToMove.x = (state.horizontal * _stats.speed); } } if(state.vertical > 0.0f) //if going up { if(viewportPosition.y + (state.vertical * _stats.speed) < 1.0f) { amountToMove.y = (state.vertical * _stats.speed); } } else if(state.vertical < 0.0f) //if going down { if(viewportPosition.y + (state.vertical * _stats.speed) > 0.0f) { amountToMove.y = (state.vertical * _stats.speed); } } transform.Translate (amountToMove); }
// Update is called once per frame void Update() { switch (contState) { case controllerState.INACTIVE: case controllerState.IDLE: if (Input.GetMouseButtonDown(0)) { contState = controllerState.DRAGGING; mousePos = Input.mousePosition; } break; case controllerState.DRAGGING: if (Input.GetMouseButton(0)) //currently dragging { Vector3 posMoved = (mousePos - Input.mousePosition) * mouseSensitivity; MoveCamera(posMoved); mousePos = Input.mousePosition; } if (Input.GetMouseButtonUp(0)) //end of drag { contState = controllerState.IDLE; mousePos = new Vector3(0, 0, 0); } break; } if (contState != controllerState.INACTIVE) { Vector2 controllerDir = new Vector3(0, 0, 0); controllerDir.x = player.GetAxis("MoveX"); controllerDir.y = player.GetAxis("MoveY"); if (controllerDir.x != 0.0f || controllerDir.y != 0.0f) { Vector3 posMoved = new Vector3(0, 0, 0); posMoved.x = controllerDir.x; posMoved.y = controllerDir.y; posMoved = posMoved * panSpeed * Time.deltaTime; MoveCamera(posMoved); } } if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } }
public void Awake() { State = new controllerState(); _stats.curAbility = 1; _stats.loadAbilities(); _velocity = _normalizedForce = new Vector2(0.0f, 0.0f); _transform = transform; _boxCollider = GetComponent <BoxCollider2D>(); var colliderWidth = _boxCollider.size.x - (2 * skinWidth); _horizontalDistanceBetweenRays = colliderWidth / (totalRays - 1); var colliderHeight = _boxCollider.size.y - (2 * skinWidth); _verticalDistanceBetweenRays = colliderHeight / (totalRays - 1); }
// Use this for initialization void Start() { _state = new controllerState(); _controller = this.gameObject.GetComponent<playerController>(); }
public void OnLeft() { cState = controllerState.ON_LEFT; }
public void OnTop() { cState = controllerState.ON_TOP; }
public void OffAll() { cState = controllerState.OFF_ALL; }
public void OnBottom() { cState = controllerState.ON_BOTTOM; }
public void OnRight() { cState = controllerState.ON_RIGHT; }
// Start is called before the first frame update void Start() { contState = controllerState.INACTIVE; mousePos = new Vector3(0, 0, 0); }
public void Fire(controllerState state) { }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); keyboardState = Keyboard.GetState(); mouseState = Mouse.GetState(); Gamepad = GamePad.GetState(PlayerIndex.One); #region Universal userControl if (currentcState == controllerState.User) { if (keyboardState.IsKeyDown(Keys.Down)) { currentcState = controllerState.Debug; } } #endregion #region debug controls if (currentcState == controllerState.Debug) { if (keyboardState.IsKeyDown(Keys.D1)) { currentState = gameState.StartMenu; } if (keyboardState.IsKeyDown(Keys.D4)) { currentState = gameState.Game; } if (keyboardState.IsKeyDown(Keys.D0)) { currentcState = controllerState.User; } if (keyboardState.IsKeyDown(Keys.F)) { Fog = true; } if (keyboardState.IsKeyDown(Keys.D)) { Fog = false; } if(keyboardState.IsKeyDown(Keys.G)) { currentSubGame = subGameState.godSpeed; } if (keyboardState.IsKeyUp(Keys.U)) { player.available = mainPlayer.Weapons.LongRange; } } #endregion #region Difficulty if (currentState == gameState.DifficultySelect) { Hard.Active = true; Medium.Active = true; Hard.setText("Hard", Button.Width, Button.Height); Medium.setText("Medium", Button.Width, Button.Height); this.IsMouseVisible = true; if (mouseState.LeftButton == ButtonState.Pressed) { Hard.CollisionCheck(mouseState, Button.Width, Button.Height); Medium.CollisionCheck(mouseState, Button.Width, Button.Height); if (Hard.Pressed == true) { Fog = true; currentState = gameState.ControllerSelect; Hard.Pressed = false; } if (Medium.Pressed == true) { Fog = false; currentState = gameState.ControllerSelect; Medium.Pressed = false; } } Hard.Active = false; Medium.Active = false; } #endregion #region StartMenu if (currentState == gameState.StartMenu) { StartButton.setText("Start", Button.Width, Button.Height); StartButton.Active = true; this.IsMouseVisible = true; if (mouseState.LeftButton == ButtonState.Pressed) { StartButton.CollisionCheck(mouseState, Button.Width, Button.Height); if (StartButton.Pressed == true) { currentState = gameState.DifficultySelect; StartButton.Pressed = false; StartButton.Active = false; } } } #endregion #region Controller selectScreen if (currentState == gameState.ControllerSelect) { ScreenSize = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); if (Gamepad.Buttons.A == ButtonState.Pressed) { currentcontroller = GameController.Joypad; currentState = gameState.ControlLesson; } if (keyboardState.IsKeyDown(Keys.Enter)) { currentcontroller = GameController.Keyboard; currentState = gameState.ControlLesson; } } #endregion #region ControlLesson if (currentState == gameState.ControlLesson) { if (keyboardState.IsKeyDown(Keys.S) || Gamepad.Buttons.B == ButtonState.Pressed) { currentState = gameState.Game; } } #endregion #region GameState Game if (currentState == gameState.Game) { this.IsMouseVisible = false; #region Keyboard stuffs if (currentcontroller == GameController.Keyboard) { if (keyboardState.IsKeyDown(Keys.B)) { currentcamera = newcamera; } if (keyboardState.IsKeyDown(Keys.L)) { currentcamera = player.eyes; } if (keyboardState.IsKeyDown(Keys.T)) { currentcamera = thirdPerCamera; } } #endregion for (int i = 0; i < redballoon.Length; i++) { redballoon[i].update(); } player.shortRange.update(player.Position); player.LongRange.update(player.Position); if (currentcontroller == GameController.Joypad) { player.JoyPadControls(Gamepad); } if (currentcontroller == GameController.Keyboard) { player.eyes.FPSController(mouseState, keyboardState); player.Controls(keyboardState, mouseState); } player.update(); //Third Person Camera is set thirdPerCamera.cPosition = (player.Position + thirdPerOffset); thirdPerCamera.setViewMatrix(thirdPerCamera.cPosition, player.Position, Vector3.Up); thirdPerCamera.FPSController(mouseState, keyboardState); thirdPerCamera.Move(player.Position + thirdPerOffset); thirdPerCamera.update(); if (currentSubGame == subGameState.godSpeed) { Enemy.update(); } counter = ("Number of Balloons:" + icounter); //This is where the Physics is carried out and collision are checked between all objects if (player.shortRange.Active == true) { physics.addBullets(player.shortRange, 0); for (int b = 0; b < redballoon.Length; b++) { if (redballoon[b].Active == true) { physics.addBalloons(redballoon[b], b); if (physics.Bullets[0].Intersects(physics.balloons[b])) { player.shortRange.Destroy(player.Position); redballoon[b].Active = false; Pop.Play(); --icounter; } } } physics.addObject(BlueBalloon); if (physics.Bullets[0].Intersects(physics.Char)) { BlueBalloon.Active = false; player.available = mainPlayer.Weapons.bullet; } physics.addObject(GreenBalloon); if (physics.Bullets[0].Intersects(physics.Char)) { GreenBalloon.Active = false; player.available = mainPlayer.Weapons.LongRange; } } if (player.LongRange.Active == true) { physics.addBullets(player.LongRange, 0); for (int b = 0; b < redballoon.Length; b++) { if (redballoon[b].Active == true) { physics.addBalloons(redballoon[b], b); if (physics.Bullets[0].Intersects(physics.balloons[b])) { player.LongRange.Destroy(player.Position); Pop.Play(); redballoon[b].Active = false; --icounter; } } } physics.addObject(GoldBalloon); if (physics.Bullets[0].Intersects(physics.Char)) { GoldBalloon.Active = false; // only the long range gun can pop the gold balloon currentState = gameState.GameEnd; } } for (int i = 0; i < player.bulletlist.Length; i++) { if (player.bulletlist[i].Active == true) { physics.addBullets(player.bulletlist[i], i); for (int b = 0; b < redballoon.Length; b++) { if (redballoon[b].Active == true) { physics.addBalloons(redballoon[b], b); if (physics.Bullets[i].Intersects(physics.balloons[b])) { player.bulletlist[i].Destroy(player.Position); redballoon[b].Active = false; Pop.Play(); --icounter; } } } physics.addObject(GreenBalloon); if (physics.Bullets[i].Intersects(physics.Char)) { GreenBalloon.Active = false; player.available = mainPlayer.Weapons.LongRange; } } } #endregion base.Update(gameTime); } }