Ejemplo n.º 1
0
        void OnCollisionEnter2D(Collision2D col)
        {
            {
                var rabbit = col.gameObject.GetComponent <HeroRabbit>();
                if (rabbit != null && !_dying)
                {
                    var angle = Math.Atan2(
                        rabbit.transform.position.y - transform.position.y,
                        rabbit.transform.position.x - transform.position.x
                        );

                    if (angle > Math.PI / 4 && angle < 3 * Math.PI / 4)
                    {
                        _dying = true;
                        Kill(false);
                        rabbit.SmallJump();
                    }
                    else
                    {
                        MoveAnimator.SetBool("atack", true);
                        LevelController.Current.OnRabbitDeath(rabbit);
                    }
                }
            }
        }
Ejemplo n.º 2
0
    public void CreateByCell(MoveImpl move)
    {
        foreach (GameObject marker in route)
        {
            Destroy(marker);
        }
        route.Clear();

        CFG.Animation route_animation = MoveAnimator.CreateAnimation(move);

        if (route_animation == null)
        {
            return;
        }

        double  cur_length = 0;
        double  angle;
        Vector2 cur_pos = new Vector2();

        while (route_animation.GetPosition(cur_length, out cur_pos, out angle))
        {
            //ToDo change GetPosition to return Vector3 and rotate board to be xy instead of xz
            Vector3    offset            = new Vector3((float)cur_pos.x, 0.1f, (float)cur_pos.y);
            GameObject route_marker_inst = Instantiate(route_marker, offset, transform.rotation) as GameObject;
            route.Add(route_marker_inst);

            cur_length += 0.5;//ToDo this is not good
        }
    }
Ejemplo n.º 3
0
        public void MoveTo(BlockPoint point)
        {
            var x = point.X * _sizeCell;
            var y = -point.Y * _sizeCell;

            MoveAnimator.MoveTo(new Vector2(x, y));
        }
Ejemplo n.º 4
0
        private new void FixedUpdate()
        {
            base.FixedUpdate();
            if (IsDead || Idle)
            {
                return;
            }

            var isOnGround = IsOnGround();

            if (isOnGround && !_lastOnGround)
            {
                _onJumpedAudioSource.PlayWithPrefs();
            }
            _lastOnGround = isOnGround;

            var value    = Input.GetAxis("Horizontal");
            var velocity = Physics.velocity;
            // ReSharper disable once CompareOfFloatsByEqualityOperator
            var running = value != 0;

            if (running)
            {
                Sprite.flipX = value < 0;
            }

            if ((Mathf.Abs(value) > 0))
            {
                velocity.x = value * Speed;
            }

            if (Input.GetButtonDown("Jump") && isOnGround)
            {
                _jumpActive = true;
            }

            if (_jumpActive)
            {
                if (Input.GetButton("Jump"))
                {
                    _jumpTime += Time.deltaTime;
                    if (_jumpTime < MaxJumpTime)
                    {
                        velocity.y = JumpSpeed * (1.0f - _jumpTime / MaxJumpTime);
                    }
                }
                else
                {
                    _jumpActive = false;
                    _jumpTime   = 0;
                }
            }

            MoveAnimator.SetBool("run", running);
            Physics.velocity     = velocity;
            transform.localScale = Vector3.Lerp(
                transform.localScale,
                _isGrewUp ? _defaultScale * GrewScaleFactor : _defaultScale, Time.deltaTime);
        }
Ejemplo n.º 5
0
        private new void FixedUpdate()
        {
            base.FixedUpdate();
            if (IsDead || _dying)
            {
                return;
            }

            PointA.y = PointB.y = transform.position.y;

            Debug.DrawLine(PointA, PointB, Color.cyan);

            if (HasToAttack())
            {
                _mode = Mode.Attack;
            }
            else if (_mode == Mode.Attack)
            {
                _mode = Mode.GoToA;
            }

            if (_mode == Mode.Attack)
            {
                Atack();
            }
            else
            {
                StopAtack();
                if (_waitTimeout > 0)
                {
                    _waitTimeout -= Time.deltaTime;
                }
                else
                {
                    var myPos  = transform.position;
                    var start  = _mode == Mode.GoToA ? PointB : PointA;
                    var target = _mode == Mode.GoToA ? PointA : PointB;

                    if (HasArrived(myPos, start, target))
                    {
                        _waitTimeout = WaitTime;
                        _mode        = _mode == Mode.GoToA ? Mode.GoToB : Mode.GoToA;
                    }

                    var curVelocity = Physics.velocity;
                    curVelocity.x    = WalkSpeed * (_mode == Mode.GoToA ? -1 : 1);
                    Physics.velocity = curVelocity;
                }
            }

            var moving = Math.Abs(Physics.velocity.x) > 0.1f;

            if (moving)
            {
                Sprite.flipX = Physics.velocity.x > 0;
            }

            MoveAnimator.SetBool("walk", moving);
        }
Ejemplo n.º 6
0
 public Button(MonoGameLibrary.Game game, Screen screen, int x, int y, int width, int height) : base(game, screen, Assets.getColorTexture(game, Color.Blue), x, y, width, height)
 {
     OnHover += onHover;
     OnLeave += onLeave;
     OnDown  += onClick;
     a        = new MoveAnimator(game, this, 1, 1, new Point(0, 0), new Point(100, 100), new Point(1000, 400), new Point(1000, 500));
     Animators.Add(a);
 }
Ejemplo n.º 7
0
        private void LaunchCarrot(bool direction)
        {
            MoveAnimator.SetBool("atack", true);
            var obj      = Instantiate(PrefabCarrot);
            var position = transform.position;

            position.y            += 0.5f;
            obj.transform.position = position;
            obj.GetComponent <Carrot>().Launch(direction);
            Sprite.flipX = direction;
        }
Ejemplo n.º 8
0
 public BallController(BallView ballView, int xPositinon, int yPosition, TypeBall typeBall, ResourcesCount typeResources)
 {
     _ballView      = ballView;
     _xPositinon    = xPositinon;
     _yPosition     = yPosition;
     _typeBall      = typeBall;
     _typeResources = typeResources;
     _moveAnimator  = _ballView.MoveAnimator;
     _ballView.PointerObject.BallMoveSide += PointerObject_BallMoveSide;
     _ballView.MoveAnimator.EndAnimation  += OnEndAnimation;
     _isChanged = true;
 }
Ejemplo n.º 9
0
        protected override void Atack()
        {
            var rabbit  = HeroRabbit.LastRabbit;
            var rabbitX = rabbit.transform.position.x;

            var curVelocity = Physics.velocity;

            curVelocity.x    = RunSpeed * (transform.position.x > rabbitX ? -1 : 1);
            Physics.velocity = curVelocity;
            MoveAnimator.SetBool("walk", false);
            MoveAnimator.SetBool("run", true);
        }
Ejemplo n.º 10
0
 protected override void StopAtack()
 {
     MoveAnimator.SetBool("run", false);
 }