public override void Attach(DirectionalArrow arrow, Transform arrowTransform, Jonko joint) { playField = FindObjectOfType <PlayField>().gameObject; GameObject newStick = Instantiate(Resources.Load("Stick", typeof(GameObject)) as GameObject, playField.transform); float halfObjectLength = newStick.GetComponent <AttachToStick>().stick.GetComponent <MeshRenderer>().bounds.extents.y; newStick.transform.rotation = arrowTransform.rotation; Vector3 normalizedDir = (arrowTransform.position - transform.position).normalized; Vector3 dir1or0 = new Vector3(Mathf.RoundToInt(normalizedDir.x), Mathf.RoundToInt(normalizedDir.y), 0); newStick.transform.position = anchor.transform.position + (dir1or0 * jointOffset); if (joint != null) { HingeJoint newHingeJoint = joint.gameObject.AddComponent <HingeJoint>(); newHingeJoint.connectedBody = newStick.GetComponent <Rigidbody>(); } else { if (anchor.GetComponent <FixedJoint>()) { anchor.GetComponent <FixedJoint>().connectedBody = newStick.GetComponentInChildren <Rigidbody>(); anchor.GetComponent <FixedJoint>().connectedAnchor = new Vector3(0, 2, 0); } else if (anchor.GetComponent <HingeJoint>()) { anchor.GetComponent <HingeJoint>().connectedBody = newStick.GetComponentInChildren <Rigidbody>(); anchor.GetComponent <HingeJoint>().connectedAnchor = new Vector3(0, 2, 0); } } base.Attach(arrow, arrowTransform, joint); }
private void OnArrowPressed(DirectionalArrow arrow) { if (PlayerState != State.ScriptControl) { PlayerState = State.PlayerControl; _arrowRoutine = StartCoroutine(PressArrowRoutine(arrow)); } }
public override void Attach(DirectionalArrow arrow, Transform arrowTransform, Jonko joint) { playField = FindObjectOfType <PlayField>().gameObject; GameObject newStick = Instantiate(Resources.Load("JointAndStick", typeof(GameObject)) as GameObject, playField.transform); newStick.transform.rotation = arrow.gameObject.transform.rotation; Vector3 normalizedDir = (arrowTransform.position - transform.position).normalized; Vector3 dir1or0 = new Vector3(Mathf.RoundToInt(normalizedDir.x), Mathf.RoundToInt(normalizedDir.y), 0); newStick.transform.position = stick.transform.position + (dir1or0 * jointOffset); stick.AddFixedJoint(); stick.ConnectRigidBody(newStick.transform.Find("HingeJoint").GetComponent <Rigidbody>()); base.Attach(arrow, arrowTransform, joint); createEndItem.visible = false; createEndItem.ApplyVisibility(); }
private IEnumerator PressArrowRoutine(DirectionalArrow arrow) { var move = Vector3.zero; switch (arrow.Direction) { case Direction.UpLeft: { move = Vector3.back; break; } case Direction.UpRight: { move = Vector3.left; break; } case Direction.DownRight: { move = Vector3.forward; break; } case Direction.DownLeft: { move = Vector3.right; break; } } while (true) { if (PlayerState != State.PlayerControl) { break; } var newPosition = transform.position + move * Time.deltaTime * _speed; UpdateTargetPosition(newPosition); yield return(null); } }
private void OnArrowReleased(DirectionalArrow arrow) { if (_arrowRoutine != null) { StopCoroutine(_arrowRoutine); _arrowRoutine = null; } if (PlayerState == State.PlayerControl) { var position = transform.position; var nextNode = FindNode(position); nextNode = nextNode ?? _lastValidNode; position = nextNode.Anchor; position = CorrectPosition(position, false); _targetPosition = position; PlayerState = State.Idle; } }
public Player(World world) { Size = new Size(100, 100); Velocity = new Vector2(Speed, 0); // Inputin alustus. defaultSetup = new InputControlSetup(); controller = new InputController(Game.Instance.InputManager); controller.ChangeSetup(defaultSetup); Game.Instance.MapManager.OnMapChanged += new MapManagerEventHandler(MapManager_OnMapChanged); animator = Game.Instance.Content.Load <CharacterModel>("playeri\\plaery").CreateAnimator("player"); animator.ChangeAnimation("attack"); animator.Scale = 0.35f; // Colliderin alustus. body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(100), ConvertUnits.ToSimUnits(100), 1.0f); body.Friction = 0f; body.BodyType = BodyType.Dynamic; body.Restitution = 0f; body.LinearDamping = 5f; body.UserData = this; Position = Vector2.Zero; Size = new Size(100, 100); HealthComponent health = new HealthComponent(100); // Komponentti alustus. components.Add(targetingComponent = new TargetingComponent <Monster>(this)); components.Add(directionalArrow = new DirectionalArrow()); components.Add(weaponComponent = new WeaponComponent(targetingComponent, new BaseballBat())); components.Add(health); Game.Instance.MapManager.OnMapChanged += new MapManagerEventHandler(MapManager_OnMapChanged); // weaponSound = Game.Instance.Content.Load<SoundEffect>("music\\baseballbat"); Speed = 15f; }
public virtual void Attach(DirectionalArrow arrow, Transform arrowTransform, Jonko joint) { arrow.visible = false; arrow.ApplyVisibility(); }