Пример #1
0
 public override void Enter(KinematicBody2D host)
 {
     GetNode <Timer>("ChargeTimer").Start();
     _direction = _target.GlobalPosition - host.GlobalPosition;
     host.GetNode <AnimationPlayer>("AnimationPlayer").Play("charge");
     host.GetNode <AudioStreamPlayer2D>("Charge").Play();
 }
Пример #2
0
        private void AnimateWalk(KinematicBody2D host)
        {
            AnimationPlayer animPlayer = host.GetNode <AnimationPlayer>("AnimationPlayer");

            Sprite     torch      = host.GetNode <Sprite>("Torch");
            Position2D torchLeft  = host.GetNode <Position2D>("TorchLeft");
            Position2D torchRight = host.GetNode <Position2D>("TorchRight");

            Vector2 playerToMouse = host.GetGlobalMousePosition() - host.GlobalPosition;

            if (playerToMouse.x > 0 && playerToMouse.y > -5)
            {
                animPlayer.Play("right");
                torch.Position        = torchRight.Position;
                torch.RotationDegrees = 25;
            }
            else if (playerToMouse.x < 0 && playerToMouse.y > -5)
            {
                animPlayer.Play("left");
                torch.Position        = torchLeft.Position;
                torch.RotationDegrees = -25;
            }
            else if (playerToMouse.x > 0 && playerToMouse.y <= -5)
            {
                animPlayer.Play("up_right");
                torch.Position        = torchRight.Position;
                torch.RotationDegrees = 25;
            }
            else if (playerToMouse.x < 0 && playerToMouse.y <= -5)
            {
                animPlayer.Play("up_left");
                torch.Position        = torchLeft.Position;
                torch.RotationDegrees = -25;
            }
        }
Пример #3
0
        private void SpawnBullet()
        {
            var bullet = (EnemyBullet2)_bulletScene.Instance();

            bullet.Speed          = 100;
            bullet.Rotation       = _host.GetNode <Node2D>("BulletSpawn").Rotation;
            bullet.GlobalPosition = _host.Position;
            bullet.Direction      = Vector2.Right.Rotated(_host.GetNode <Position2D>("BulletSpawn/Position2D").RotationDegrees);
            _host.GetParent().AddChild(bullet);
            _host.GetNode <Node2D>("BulletSpawn").Rotate(_shots < 6 ? .5f : -.5f);
        }
Пример #4
0
        public override void Enter(KinematicBody2D host)
        {
            host.GetNode <Timer>("DashTimer").Start();
            host.GetNode <CollisionPolygon2D>("Hitbox/CollisionPolygon2D").Disabled = true;
            host.GetNode <AnimationPlayer>("AnimationPlayer")
            .Play(!host.GetNode <Sprite>("Sprite").FlipH ? "Dash" : "Dash_Flipped");
            _inputDirection = new Vector2(
                Convert.ToInt32(Input.IsActionPressed("move_right")) - Convert.ToInt32(Input.IsActionPressed("move_left")),
                Convert.ToInt32(Input.IsActionPressed("move_down")) - Convert.ToInt32(Input.IsActionPressed("move_up")));

            // Visual feedback for dashing
            host.Modulate = Color.Color8(100, 100, 100);
            _host         = host;
        }
Пример #5
0
 public override void Enter(KinematicBody2D host)
 {
     host.GetNode <AnimationPlayer>("AnimationPlayer").Play("Chase");
     _wanderTimer.Start();
     _dir.x = _random.Next(-50, 50);
     _dir.y = _random.Next(-50, 50);
 }
Пример #6
0
        private void ChaseTarget(KinematicBody2D host)
        {
            RayCast2D look = host.GetNode <RayCast2D>("RayCast2D");

            if (_target != null)
            {
                look.CastTo = _target.Position - host.Position;
            }
            look.ForceRaycastUpdate();

            // if we can see the target, chase it
            if (!look.IsColliding() || ((Node)look.GetCollider()).IsInGroup("player"))
            {
                ((Entity)host).GetNode <Timer>("ShootTimer").Paused = false;
                _direction = look.CastTo.Normalized();
            }
            // or chase the first scent we see
            else
            {
                ((Entity)host).GetNode <Timer>("ShootTimer").Paused = true;
                foreach (Scent scent in _target.ScentTrail)
                {
                    look.CastTo = scent.Position - host.Position;
                    look.ForceRaycastUpdate();

                    if (!look.IsColliding() || ((Node)look.GetCollider()).IsInGroup("player"))
                    {
                        _direction = look.CastTo.Normalized();
                        break;
                    }
                }
            }
        }
Пример #7
0
 public override void Enter(KinematicBody2D host)
 {
     _sprite = GetParent().GetParent().GetNode <Sprite>("Sprite");
     host.GetNode <AnimationPlayer>("AnimationPlayer").Play("float");
     _wanderTimer.Start();
     _direction.x = _random.Next(-50, 50);
     _direction.y = _random.Next(-50, 50);
 }
Пример #8
0
 public override void _Ready()
 {
     _currentZoomFactor = DefaultZoom;
     _player            = GetNode <KinematicBody2D>("/root/MainScene/Player");
     _camera            = _player.GetNode <Camera2D>("Camera2D");
     _box       = GetNode <CollisionShape2D>("CollisionShape2D");
     _rectangle = _box.GetShape() as RectangleShape2D;
     _rect      = new Rect2(_box.GlobalPosition - _rectangle.Extents, _rectangle.Extents * 2);
 }
Пример #9
0
 public override void Enter(KinematicBody2D host)
 {
     _shots = 0;
     _host  = host;
     host.GetNode <AnimationPlayer>("AnimationPlayer").Play("Chase");
     _host.GetNode <Node2D>("BulletSpawn").Rotation = new Vector2(_target.Position.x - _host.Position.x,
                                                                  _target.Position.y - _host.Position.y).Angle();
     GetNode <Timer>("ShootTimer").Start();
 }
Пример #10
0
    public override void _Ready()
    {
        _body   = GetNode <Node2D>("Body");
        _head   = GetNode <KinematicBody2D>("Head");
        _sprite = _head.GetNode <Sprite>("Sprite");

        _timeUntilNextStep     = 0.100f;
        _timeSincePreviousStep = 0f;

        ResetBody(_head.Position);
    }
Пример #11
0
 private void _on_AnimationPlayer_finished(string animName)
 {
     if (animName == "Disappear")
     {
         _host.GetNode <AnimationPlayer>("AnimationPlayer").Play("Appear");
         _host.Position = ((Player.Entity)_target).ScentTrail[0].Position;
     }
     if (animName == "Appear")
     {
         EmitSignal(nameof(Finished), "Shoot");
     }
 }
Пример #12
0
 public override void Enter(KinematicBody2D host)
 {
     host.GetNode <AnimationPlayer>("AnimationPlayer").Play("Chase");
 }
Пример #13
0
 private Vector2 GetStartPosition()
 {
     return(player.Position - new Vector2(0, player.GetNode <Sprite>("Sprite").RegionRect.Size.y + 10));
 }
Пример #14
0
 public override void Enter(KinematicBody2D host)
 {
     host.GetNode <AnimationPlayer>("AnimationPlayer").Play("Idle");
     _idleTimer.Start();
 }
Пример #15
0
 public override void Enter(KinematicBody2D host)
 {
     Speed    = 0;
     Velocity = new Vector2();
     host.GetNode <AnimationPlayer>("AnimationPlayer").Play("Walk");
 }
Пример #16
0
 public override void Enter(KinematicBody2D host)
 {
     _host = host;
     host.GetNode <AudioStreamPlayer2D>("AudioStreamPlayer2D").Play();
     host.GetNode <AnimationPlayer>("AnimationPlayer").Play("Disappear");
 }
Пример #17
0
 public override void Enter(KinematicBody2D host)
 {
     host.GetNode <AnimationPlayer>("AnimationPlayer").Play("float");
     _dir = _player.GlobalPosition - host.GlobalPosition;
 }
Пример #18
0
 public override void Exit(KinematicBody2D host)
 {
     host.GetNode <CollisionPolygon2D>("Hitbox/CollisionPolygon2D").Disabled = false;
 }
Пример #19
0
 public void DashTimer_timeout()
 {
     _host.GetNode <Timer>("DashTimer").Stop();
     _host.Modulate = new Color(1, 1, 1);
     EmitSignal(nameof(Finished), "Move");
 }
Пример #20
0
 public override void Enter(KinematicBody2D host)
 {
     _look = host.GetNode <RayCast2D>("RayCast2D");
     host.GetNode <AnimationPlayer>("AnimationPlayer").Play("chase");
     host.GetNode <AudioStreamPlayer2D>("Chase").Play();
 }
Пример #21
0
 public override void Exit(KinematicBody2D host)
 {
     host.GetNode <AudioStreamPlayer2D>("Charge").Stop();
 }