示例#1
0
    public override void _Ready()
    {
        MusicMenu = (AudioStreamPlayer2D)GetNode("MusicMenu");
        MusicPlay = (AudioStreamPlayer2D)GetNode("MusicPlay");
        MusicMenu.Play();
        animOnOffMusic = (AnimatedSprite)GetNode("Menu/MusicOnOf");
        StatusmusicOn  = 1;
        MusicOnOfLabel = (Label)GetNode("Menu/MusicOnOf/MusicStatus");

        player   = (KinematicBody2D)GetNode("Player");
        npc      = (PackedScene)ResourceLoader.Load("res://Scene/NPCJatuh1.tscn");
        NpcTimer = (Timer)GetNode("NpcTimer");
        NpcTimer.Stop();
        WaveLabel             = (Label)GetNode("GUI/WaveLabel");
        PanelGameOver         = (Panel)GetNode("GameOver");
        PanelGameOver.Visible = false;

        AboutPanel = (Node2D)GetNode("Menu/About");
        AboutTween = (Tween)GetNode("Menu/About/Tween");

        meteor      = (PackedScene)ResourceLoader.Load("res://Scene/Meteor.tscn");
        MeteorTimer = (Timer)GetNode("MeteorTimer");



        player.Visible = false;
    }
示例#2
0
        public KinematicBody2DAgent(KinematicBody2D _body, MovementType _movement_type = MovementType.SLIDE)
        {
            Body          = _body;
            movement_type = _movement_type;

            _body.GetTree().Connect("physics_frame", this, "_OnSceneTreePhysicsFrame");
        }
 public VelocityBasedCharacterController(KinematicBody2D kb, float moveSpeed, float jumpImpulse, float gravity)
 {
     _kb          = kb;
     _moveSpeed   = moveSpeed;
     _jumpImpulse = jumpImpulse;
     _gravity     = gravity;
 }
示例#4
0
 private void InitPaddles()
 {
     leftPaddle          = GetNode(new NodePath("./Paddle Left")) as KinematicBody2D;
     rightPaddle         = GetNode(new NodePath("./Paddle Right")) as KinematicBody2D;
     leftPaddleStartPos  = leftPaddle.Position;
     rightPaddleStartPos = rightPaddle.Position;
 }
示例#5
0
        public virtual void _ApplyOrientationSteering(float angular_acceleration, float delta)
        {
            KinematicBody2D _body = (KinematicBody2D)_body_ref.GetRef();

            if (_body == null)
            {
                return;
            }

            var velocity = Mathf.Clamp(
                angular_velocity + angular_acceleration * delta,
                -angular_acceleration_max,
                angular_acceleration_max
                );

            if (apply_angular_drag)
            {
                velocity = Mathf.Lerp(velocity, 0, angular_drag_percentage);
            }
            _body.Rotation += velocity * delta;
            if (calculate_velocities)
            {
                angular_velocity = velocity;
            }
        }
示例#6
0
 public override void HandleInput(KinematicBody2D host, InputEvent @event)
 {
     if (@event.IsActionPressed("dash"))
     {
         EmitSignal(nameof(Finished), "Dash");
     }
 }
示例#7
0
 public void entered(KinematicBody2D body)
 {
     if (body.Name == "KinematicBody2D")
     {
         GetTree().ChangeScene("res://scene/menu.tscn");
     }
 }
示例#8
0
 private void _on_VisibilityNotifier2D_screen_entered()
 {
     _player = GetParent().GetNode <KinematicBody2D>("Player");
     GetNode <Timer>("ShootTimer").Start();
     _canShoot = true;
     ChangeState("Chase");
 }
示例#9
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);
 }
示例#10
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();
 }
 public void CastSpellAtSlot(int index, KinematicBody2D player)
 {
     if (index < spells.Count)
     {
         spells[index].CastSpell(player);
     }
 }
示例#12
0
    public override void _Process(float delta)
    {
        if (shooting)
        {
            if (!shot)
            {
                // Log.p("Ship - _Process");
                shot = true;
                t.Start(0.1f);
                // Log.p("Ship - emitting...");
                EmitSignal(nameof(Shoot), bulletScene, (Rotation + Math.PI * 90 / 180.0), GetNode <Position2D>("Position2D").GlobalPosition);
                // Log.p("Ship - emitting... done");
                // Log.p("vamos testar essa merda:");
                // Log.p("rotation -> " + (Rotation * (180.0 / Math.PI)));
                // Log.p("globalpos -> " + GetNode<Position2D>("Position2D").GlobalPosition);
            }
        }

        if (shooting2)
        {
            if (!shot2)
            {
                KinematicBody2D bulletInstance2 = bulletScene2.Instance() as KinematicBody2D;
                bulletInstance2.Rotation = Rotation;
                bulletInstance2.Position = GetNode <Position2D>("Position2D").GlobalPosition;
                GetParent().AddChild(bulletInstance2);
                shot2 = true;
                t2.Start(0.1f);
            }
        }
    }
示例#13
0
    //bool missileUpgrade = false;
    //Used to show the bullet path when the gun is fired
    //Line2D traceLine;
    //The position were the ray cast hit
    //Vector2 hitPos;
    //Timer used to time the flash of hte bullet
    //Timer traceTimer;

    //PackedScene missileScene = new PackedScene();
    //Node missile;

    //We need a line rendered to show the path of the projectile
    //We need to cas a ray to the mouse coordinates
    public override void _Ready()
    {
        //Set up the timer for the muzzle flash
        //traceTimer = new Timer();
        //traceTimer.WaitTime = .05f;
        //traceTimer.OneShot = true;
        //traceTimer.Name = "traceTimer";

        //Create the new timer
        //AddChild(traceTimer, true);
        //GetNode<Timer>(traceTimer.Name).Connect("timeout", this, nameof(HideTrace));

        //Set the trace line properties
        //traceLine = new Line2D();
        //traceLine.Width = 1f;
        //traceLine.Name = "traceLine";
        //traceLine.DefaultColor = new Color(1, 1, 1);
        //AddChild(traceLine);
        //traceLine.Visible = false;

        //Set the refference for the tanks Kinematic Body 2D
        tankBody = GetNode <KinematicBody2D>("../../../../Player");
        //Connect to the input manager to read the mouses click event
        GetNode <InputManager>("../../../../InputManager").Connect("leftMouseClicked", this, nameof(Fire));
        //missileScene = ResourceLoader.Load("res://Scenes/Missile.tscn") as PackedScene;

        //MissilePickupEvent.RegisterListener(SetMissileUpgrade);
    }
示例#14
0
 private void _UpdateRotation(KinematicBody2D parent, float delta)
 {
     if (_steering != null && _steering.HorizontalAxis != 0f)
     {
         parent.Rotate(delta * _steering.AngularChange);
     }
 }
示例#15
0
        private void ChaseTarget(KinematicBody2D host)
        {
            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"))
            {
                _direction = _look.CastTo.Normalized();
            }
            // or chase the first scent we see
            else
            {
                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;
                    }
                }
            }
        }
 private void _on_DetectRadius_body_exited(Godot.Object body)
 {
     if (body == _target)
     {
         _target = null;
     }
 }
示例#17
0
    private void RemoveAllPlayers()
    {
        // Removes ALL the entries from list of player node names due to the method's purpose.
        this.listPlayerNodeNames.Clear();

        // Create a regex string
        string regexString = String.Format("@?({0})@?.*", "Player");
        // Get a list of player node names
        List <string> playerNodeNames = new List <string>();

        foreach (Node2D node in this.GetChildren())
        {
            // For each node within the current node's (world node) children...

            if (Regex.IsMatch(node.Name, regexString))
            {
                // Add the player node names onto the list if the regex string matches it.
                playerNodeNames.Add(node.Name);
            }
        }

        if (playerNodeNames.Count > 0)
        {
            // If the node name list is not empty, then...

            foreach (string s in playerNodeNames)
            {
                // Get all the nodes from the pertaining to
                // those names and remove them from the game.
                KinematicBody2D instance = this.GetNode <KinematicBody2D>(s);
                instance.Hide();
                instance.QueueFree();
            }
        }
    }
示例#18
0
 private void _on_Exit_body_entered(KinematicBody2D body)
 {
     if (body.IsInGroup("player"))
     {
         GetTree().ChangeScene("res://Levels/WinScreen.tscn");
     }
 }
示例#19
0
 public void HurtSignalReceived(KinematicBody2D enemy)
 {
     if (GetInstanceId() == enemy.GetInstanceId())
     {
         QueueFree();
     }
 }
示例#20
0
 public override void _Ready()
 {
     player       = GetTree().Root.GetNode <KinematicBody2D>("MainScene/Player");
     sprite       = GetNode <Sprite>("Sprite");
     spriteHeight = sprite.GetRect().End.y - sprite.GetRect().Position.y;
     spriteWidth  = sprite.GetRect().End.x - sprite.GetRect().Position.x;
 }
示例#21
0
 public HoverChase(KinematicBody2D parent, int speed, int activeDistance = 300, int tooCloseDistance = 250)
 {
     this.parent           = parent;
     this.speed            = speed;
     this.activeDistance   = activeDistance;
     this.tooCloseDistance = tooCloseDistance;
 }
示例#22
0
 public void _on_Area2D_body_entered(KinematicBody2D area)
 {
     if (area.IsInGroup("enemy"))
     {
         ChangeState("Dead");
     }
 }
示例#23
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;
            }
        }
示例#24
0
        public KinematicCollision2D MoveObject(KinematicBody2D host, Vector2 direction)
        {
            Vector2 velocity = direction.Normalized() * Speed;

            host.MoveAndSlide(velocity, Vector2.Zero);
            return(host.GetSlideCount() == 0 ? null : host.GetSlideCollision(0));
        }
    private void _on_Player_enter_area(KinematicBody2D player)
    {
        Console.Out.WriteLine("Dieser name hiere das ist das wichtige dingens::: " + this.Name);

        if (!isPlayerIn)
        {
            if (this.player == null)
            {
                this.player = player;
                foreach (Node cache in player.GetChildren())
                {
                    if (cache.Name.Equals("RotatePlayer"))
                    {
                        this.rotateplayer = (AnimationPlayer)cache;
                    }
                    if (cache.Name.Equals("Area2D"))
                    {
                        this.area = (Area2D)cache;
                    }
                }
            }
            //player.RotationDegrees = 180f;
            isEvent = true;
            timer.Start();
        }
    }
    public override void _PhysicsProcess(float delta)
    {
        if (player == null)
        {
            player = playerZone.player;
        }
        acceleration += seek();
        velocity     += acceleration * delta;
        velocity      = velocity.Clamped(speed);
        Rotation      = velocity.Angle();
        Position     += velocity * delta;

        // if (playerZone.player != null)
        // {
        //     Vector2 direction = GlobalPosition.DirectionTo(playerZone.player.Position);
        //     RotationDegrees =  Mathf.Rad2Deg(GlobalPosition.AngleTo(playerZone.player.Position)) + 90;
        //     GD.Print(RotationDegrees);

        //     //  GD.Print(direction.Angle());
        //     velocity = velocity.MoveToward(direction * speed, acceleration * delta);
        //     //animatedSprite.FlipH = velocity.x < 0;
        // }



        //this.MoveAndCollide(velocity);
    }
示例#27
0
 private void _on_DetectRadius_body_exited(Object body)
 {
     if (body == Target)
     {
         Target = null;
     }
 }
示例#28
0
 private void OnBodyEntered(Node body)
 {
     if (body is Arthur arthur)
     {
         Body = arthur;
     }
 }
示例#29
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;
                    }
                }
            }
        }
示例#30
0
 public override void Update(KinematicBody2D host, float delta)
 {
     if (_canChase)
     {
         ChaseTarget(host);
     }
     host.MoveAndSlide(_direction * Speed);
 }