Ejemplo n.º 1
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        //Inicializar Nodes
        MyAreaDano        = GetNode("areaDano") as Area2D;
        MyAreaBater       = GetNode("areaBater") as Area2D;
        MyTempoMorrer     = GetNode("tempoMorrer") as Timer;
        MyTempoInvencivel = GetNode("tempo_invencivel") as Timer;
        MyAnimationPlayer = GetNode("AnimationPlayer") as AnimationPlayer;
        MyCamera2D        = GetNode("Camera2D") as Camera2D;
        MySprite          = GetNode("Sprite") as Sprite;
        MyParticles2D     = GetNode("Particles2D") as Particles2D;
        MyTween           = GetNode("Tween") as Tween;
        MyPulo            = GetNode("pulo") as AudioStreamPlayer2D;
        MyDano            = GetNode("dano") as AudioStreamPlayer2D;

        //Conectar a Area2D que vai detectar se o Personagem colidiu com o Inimigo
        MyAreaDano.Connect("area_entered", this, "OnAreaDanoAreaEntered");

        //Conectar areaBater entrar
        MyAreaBater.Connect("area_entered", this, "OnAreaBaterAreaEntered");

        //Conectar areaBater Sair
        MyAreaBater.Connect("area_exited", this, "OnAreaBaterAreaExited");

        //Conectar timer
        MyTempoMorrer.Connect("timeout", this, "TempoMorrer");

        //Iniciar animação
        MyAnimationPlayer.Play("parado");

        //Camera Offset
        MyCamera2D.Offset = new Vector2(MyCamera2D.Offset.x, cameraOffSet);
    }
Ejemplo n.º 2
0
    public int direcaoInimigo = 0;           //Direção inimigo

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        //Inicializar Nodes
        MyAnimationPlayer = GetNode("AnimationPlayer") as AnimationPlayer;
        MyAreaInimigo     = GetNode("areaInimigo") as Area2D;
        MyBocaInimigo     = GetNode("bocaInimigo") as Area2D;
        MyDestroyTimer    = GetNode("destroy_timer") as Timer;
        MySprite          = GetNode("Sprite") as Sprite;
        MyTween           = GetNode("Tween") as Tween;
        MyParticles2D     = GetNode("Particles2D") as Particles2D;
        MyExplodir        = GetNode("explodir") as AudioStreamPlayer2D;

        //Conectar o AnimationPlayer quando terminar a animação
        MyAnimationPlayer.Connect("animation_finished", this, "AnimacaoTerminada");

        //Conectar ao entrar na area do personagem
        MyAreaInimigo.Connect("body_entered", this, "EntrouAreaPersonagem");

        //Conectar ao sair da area do personagem
        MyAreaInimigo.Connect("body_exited", this, "SaiuAreaPersonagem");

        //Conectar o fim do tempo de destruir
        MyDestroyTimer.Connect("timeout", this, "Destruir");

        //Iniciar animação do inimigo
        MyAnimationPlayer.Play("paradoEsquerda");
    }
Ejemplo n.º 3
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        //Inicializar Nodes
        MyTimerPatrulha    = GetNode("TimerPatrulha") as Timer;
        MyDetectorVisao    = GetNode("DetectorVisao") as Area2D;
        MyArea2D           = GetNode("DetectorSom") as Area2D;
        MyAnimationPlayer  = GetNode("AnimationPlayer") as AnimationPlayer;
        MySprite           = GetNode("Sprite") as Sprite;
        MyAlerta           = GetNode("Alerta") as Label;
        MyTimerAlerta      = GetNode("TimerAlerta") as Timer;
        MyTween            = GetNode("Tween") as Tween;
        MyAtaquePersonagem = GetNode("AtaquePersonagem") as Area2D;

        //Conexões dos Nodes
        MyTimerPatrulha.Connect("timeout", this, "TempoPatrulha");
        MyArea2D.Connect("area_entered", this, "EntrouAreaSom");
        MyArea2D.Connect("area_exited", this, "SaiuAreaSom");
        MyDetectorVisao.Connect("area_exited", this, "SaiuAreaVisao");
        MyDetectorVisao.Connect("area_entered", this, "EntrouAreaVisao");
        MyTimerAlerta.Connect("timeout", this, "SumirAlerta");
        MyTween.Connect("tween_completed", this, "RetornarBase");
        MyAtaquePersonagem.Connect("area_entered", this, "AtacarPersonagem");
        MyAtaquePersonagem.Connect("area_exited", this, "PararAtaquePersonagem");

        //Estado inicial
        posInicial = Position;
        estado     = estados.PATRULHAR.ToString();
        direcao.x  = 1;
        direcao.y  = 0;
        MyTimerPatrulha.Start();
    }
Ejemplo n.º 4
0
 public override void _Ready()
 {
     interact = GetNode <Area2D>("Interact");
     shader   = (ShaderMaterial)GetNode <Sprite>("Sprite").Material;
     interact.Connect("body_entered", this, nameof(BodyEntered));
     interact.Connect("body_exited", this, nameof(BodyExited));
 }
Ejemplo n.º 5
0
 protected override void _Sinais()
 {
     base._Sinais();
     _sensorPe.Connect("body_entered", this, nameof(_SensorPeCorpoEntrou));
     _sensorPe.Connect("body_exited", this, nameof(_SensorPeCorpoSaiu));
     _sensorBlocosPulo.Connect("body_exited", this, nameof(_SensorBlocosPuloEntrou));
 }
Ejemplo n.º 6
0
 private void UpdateSignals()
 {
     if (IsCPU && !IsBorrowMode)
     {
         if (Area2D.IsConnected("mouse_entered", this, nameof(OnMouseEntered)))
         {
             Area2D.Disconnect("mouse_entered", this, nameof(OnMouseEntered));
         }
         if (Area2D.IsConnected("mouse_exited", this, nameof(OnMouseExited)))
         {
             Area2D.Disconnect("mouse_exited", this, nameof(OnMouseExited));
         }
         if (Area2D.IsConnected("input_event", this, nameof(OnInputEvent)))
         {
             Area2D.Disconnect("input_event", this, nameof(OnInputEvent));
         }
     }
     else
     {
         if (!Area2D.IsConnected("mouse_entered", this, nameof(OnMouseEntered)))
         {
             Area2D.Connect("mouse_entered", this, nameof(OnMouseEntered));
         }
         if (!Area2D.IsConnected("mouse_exited", this, nameof(OnMouseExited)))
         {
             Area2D.Connect("mouse_exited", this, nameof(OnMouseExited));
         }
         if (!Area2D.IsConnected("input_event", this, nameof(OnInputEvent)))
         {
             Area2D.Connect("input_event", this, nameof(OnInputEvent));
         }
     }
 }
Ejemplo n.º 7
0
    public override void _Ready()
    {
        actionRadiusCollider = GetNode <Area2D>(actionRadiusColliderNodePath);
        actionRadiusCollider.Connect("area_entered", this, nameof(OnAreaEntered));
        actionRadiusCollider.Connect("area_exited", this, nameof(OnAreaExited));

        pathfindingTileMap = NodeGetter.GetFirstNodeInGroup <PathfindingTileMap>(GetTree(), GameConstants.PathfindingTileMapGroup, true);
    }
Ejemplo n.º 8
0
 public override void _Ready()
 {
     base._Ready();
     area        = GetNode <Area2D>(areaPath);
     openPlayer  = GetNode <AudioStreamPlayer2D>("OpenPlayer");
     closePlayer = GetNode <AudioStreamPlayer2D>("ClosePlayer");
     area.Connect("body_entered", this, nameof(_body_entered));
     area.Connect("body_exited", this, nameof(_body_exited));
 }
Ejemplo n.º 9
0
        public override void _Ready()
        {
            itemSprite         = GetNode <Sprite>("Sprite");
            itemSprite.Texture = stats.worldSprite;

            area2D = GetNode <Area2D>("Area2D");
            area2D.Connect("body_entered", this, nameof(HandleBodyEntered));
            area2D.Connect("body_exited", this, nameof(HandleBodyExited));
        }
Ejemplo n.º 10
0
 public override void _Ready()
 {
     anim      = GetNode <AnimationPlayer>("AnimationPlayer");
     mouseArea = GetNode <Area2D>("Area2D");
     mouseArea.Connect("mouse_entered", this, nameof(MouseEntered));
     mouseArea.Connect("mouse_exited", this, nameof(MouseExited));
     mouseInside = false;
     grid        = GetParent <Grid>();
     SetProcess(true);
 }
Ejemplo n.º 11
0
 public override void _Ready()
 {
     Controllable            = true;
     interactionArea         = GetChild(2) as Area2D;
     interactionIcon         = GetParent().GetChild(2) as Control;
     interactionIcon.Visible = false;
     interactionOffset       = interactionArea.Position.Length();
     interactionArea.Connect("body_entered", this, nameof(CheckInteractableEnter));
     interactionArea.Connect("body_exited", this, nameof(CheckInteractableExit));
 }
Ejemplo n.º 12
0
        public override void _Ready()
        {
            _collisionShape         = GetNode <CollisionShape2D>(collisionShapeNodePath);
            _explosionCollisionArea = GetNode <Area2D>(explosionCollisionAreaNodePath);

            _explosionCollisionArea.Connect("body_entered", this, nameof(HandleBodyEntered));
            _explosionCollisionArea.Connect("body_exited", this, nameof(HandleBodyExited));

            CircleShape2D collisionShape = (CircleShape2D)_collisionShape.GetShape();

            collisionShape.SetRadius(explosionRadius);
        }
Ejemplo n.º 13
0
    float headingX = +1.0f;     //-1 to the left, +1 to the right

    public override void _Ready()
    {
        sprIdle      = GetNode <Sprite>("sprIdle");
        sprRun       = GetNode <Sprite>("sprRun");
        sprJumpLong  = GetNode <Sprite>("sprJumpLong");
        sprJumpShort = GetNode <Sprite>("sprJumpShort");
        sprFall      = GetNode <Sprite>("sprFall");
        sprClimb     = GetNode <Sprite>("sprClimb");


        animPlayer = GetNode <AnimationPlayer>("AnimationPlayer");

        colFront  = GetNode <CollisionShape2D>("colFront");
        colBottom = GetNode <CollisionShape2D>("colBottom");
        colRun    = GetNode <CollisionShape2D>("colRun");
        colBase   = GetNode <CollisionShape2D>("colBase");
        colUpper  = GetNode <CollisionShape2D>("colUpper");

        grabArea = GetNode <Area2D>("GrabArea");
        grabArea.Connect("body_entered", this, "OnGrab");

        rayFloor = GetNode <RayCast2D>("rayFloor");

        TurnOnSpr(SprObj.SprIdle);
    }
Ejemplo n.º 14
0
    public override void _Ready()
    {
        parent = GetParent() as Node2D;
        detect = (Area2D)GetNode("DetectRadius");
        var col    = (CollisionShape2D)detect.GetNode("CollisionShape2D");
        var circle = new CircleShape2D();

        circle.Radius = DetectRadius;
        col.Shape     = circle;
        lookAhead1    = GetNode("LookAhead1") as RayCast2D;
        lookAhead2    = GetNode("LookAhead2") as RayCast2D;
        detect.Connect("body_entered", this, "OnDetectEntered");
        detect.Connect("body_exited", this, "OnDetectExited");

        base._Ready();
    }
Ejemplo n.º 15
0
        public override void _Ready()
        {
            _bodyArea = GetNode <Area2D>("BodyArea");
            _bodyArea.Connect("area_entered", this, nameof(OtherCollisionChecker));

            GD.Print(":::Player Script Loaded");
        }
Ejemplo n.º 16
0
    public void Initialize(Vector2 position)
    {
        base.Initialize(position);
        SetCollisionMaskBit(1, true);
        sprite.Frames = ResourceLoader.Load("res://entities/player/Player.tres") as SpriteFrames;
        sprite.Play("default");
        ChangeState(state);

        var hurtArea     = new Area2D();
        var hurtCollider = new CollisionShape2D();
        var hurtBoxShape = new RectangleShape2D();

        hurtArea.SetCollisionLayerBit(19, true);
        hurtArea.SetCollisionLayerBit(0, false);
        hurtArea.CollisionMask = 0;
        hurtArea.Name          = "HurtBox";
        hurtBoxShape.Extents   = new Vector2(2f, 4f);
        hurtCollider.Shape     = hurtBoxShape;
        hurtArea.AddChild(hurtCollider);
        hurtArea.Connect("body_entered", this, "OnTouchedByEnemy");
        AddChild(hurtArea);

        Texture gradient = ResourceLoader.Load("res://assets/gradients/radial.png") as Texture;

        _light.Texture = gradient;
        _light.Scale   = _baseLightScale;
        _light.Color   = new Color(1f, 1f, 1f, .3f);
        AddChild(_light);

        AddChild(_lightTween);

        AddToGroup("Players");
    }
Ejemplo n.º 17
0
    public override void Initialize(Vector2 position, int size = 8)
    {
        base.Initialize(Position, size: size);
        SetCollisionMaskBit(1, true);
        CollisionLayer = 0;
        CollisionShape2D hurtCollider = new CollisionShape2D();
        RectangleShape2D hurtBoxShape = new RectangleShape2D();

        _hurtArea.SetCollisionLayerBit(0, false);
        _hurtArea.SetCollisionLayerBit(2, true);
        _hurtArea.SetCollisionMaskBit(19, true);
        _hurtArea.SetCollisionMaskBit(0, false);
        _hurtArea.Name       = "HurtBox";
        hurtBoxShape.Extents = new Vector2(size / 2f, size / 2f);
        hurtCollider.Shape   = hurtBoxShape;
        _hurtArea.AddChild(hurtCollider);
        AddChild(_hurtArea);


        CollisionShape2D alertCollider = new CollisionShape2D();
        CircleShape2D    alertBoxShape = new CircleShape2D();

        _alertArea.Name = "AlertCircle";
        _alertArea.SetCollisionMaskBit(19, true);
        _alertArea.SetCollisionMaskBit(0, false);
        _alertArea.CollisionLayer = 0;
        alertBoxShape.Radius      = 35;
        alertCollider.Shape       = alertBoxShape;
        _alertArea.AddChild(alertCollider);
        AddChild(_alertArea);

        _alertArea.Connect("area_entered", this, "_OnPlayerEnter");
        _hurtArea.Connect("area_entered", this, "_OnPlayerTouch");
        AddToGroup("Enemies");
    }
Ejemplo n.º 18
0
    public override void _Ready()
    {
        _area = GetNode("Area2D") as Area2D;
        _area.Connect("body_entered", this, nameof(_onBodyEntered));

        _animationPlayer = GetNode("AnimationPlayer") as AnimationPlayer;
        _animationPlayer.Connect("animation_finished", this, nameof(_onAnimationFinished));
    }
Ejemplo n.º 19
0
 public override void _Ready()
 {
     interact = GetNode <Area2D>("Interact");
     interact.Connect("body_entered", this, nameof(BodyEntered));
     sprite        = GetNode <Sprite>("Sprite");
     pressedAudio  = GetNode <AudioStreamPlayer>("Pressed");
     releasedAudio = GetNode <AudioStreamPlayer>("Released");
 }
Ejemplo n.º 20
0
    public override void _Ready()
    {
        base._Ready();

        _base      = GetNode <Sprite>("Base");
        _tower     = GetNode <Node2D>("Tower");
        _trigger   = GetNode <Area2D>("Trigger");
        _firePoint = GetNode <Node2D>("Tower/FirePoint");

        _bullet = ResourceLoader.Load <PackedScene>("res://src/Projectiles/Bullet.tscn");

        _reloadElapsed = 0;
        _trigger.AddChild(CreateReadiusArea(_trigger.Position, Radius));

        _trigger.Connect("body_entered", this, nameof(OnTriggerAdd));
        _trigger.Connect("body_exited", this, nameof(OnTriggerRemove));
    }
Ejemplo n.º 21
0
        public override void _Ready()
        {
            _soulSprite        = GetNode <Sprite>(soulSpriteNodePath);
            _soulParticles     = GetNode <Particles2D>(soulParticleNodePath);
            _soulAreaCollision = GetNode <Area2D>(soulAreaCollisionNodePath);

            _soulAreaCollision.Connect("body_entered", this, nameof(HandleBodyEntered));
        }
Ejemplo n.º 22
0
    /// <summary>
    /// Initialise the node when the game engine is ready
    /// </summary>
    public override void _Ready()
    {
        AnimationPlayer animationPlayer = this.GetNode(ANIM_PLAYER_NODE_NAME) as AnimationPlayer;

        animationPlayer.Connect(ANIMATION_FINISHED_SIGNAL, this, nameof(this.OnAnimationFinished));
        animationPlayer.Play(ANIMATION_NAME);
        explosionArea = GetNode("ExplosionArea") as Area2D;
        explosionArea.Connect("body_entered", this, "OnBodyEnter");
    }
Ejemplo n.º 23
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        _map     = this.GetNode <Area2D>("../MainMap");
        _tilemap = _map.GetNode <TileMap>("./Ground");

        _upBorder      = this.GetNode <Area2D>("UpBorder");
        _downBorder    = this.GetNode <Area2D>("DownBorder");
        _debugPosition = this.GetNode <RichTextLabel>("DebugMapPosition");

        _isScrollingUp   = false;
        _isScrollingDown = false;

        _upBorder.Connect("mouse_entered", this, "_on_UpBorder_mouse_entered");
        _downBorder.Connect("mouse_entered", this, "_on_DownBorder_mouse_entered");

        _upBorder.Connect("mouse_exited", this, "_on_UpBorder_mouse_exited");
        _downBorder.Connect("mouse_exited", this, "_on_DownBorder_mouse_exited");
    }
Ejemplo n.º 24
0
    public void CreateConnection()
    {
        _player.Connect("OnShoot", this, nameof(OnPlayerShoot));
        _player.Connect("OnHit", this, nameof(PlayerHit));
        _player.Connect("OnGameOver", this, nameof(GameOver));
        Node2D walls = GetNode <Node2D>("Walls");

        walls.Connect("OnRightCollision", _wave, "OnCollideRight");
        walls.Connect("OnLeftCollision", _wave, "OnCollideLeft");
        _wave.Connect("OnDefeat", this, nameof(WaveWon));
        foreach (Node child in _wave.GetChildren())
        {
            if (child is Enemy)
            {
                child.Connect("OnShoot", this, nameof(OnEnemyShoot));
            }
        }
    }
Ejemplo n.º 25
0
        public override void _Ready()
        {
            base._Ready();

            _laserArea = GetNode <Area2D>(laserAreaNodePath);
            _laserArea.Connect("body_entered", this, nameof(HandleBodyEntered));
            _laserArea.Connect("body_exited", this, nameof(HandleBodyExited));

            _laserLineEffects = new List <Particles2D>();
            foreach (NodePath laserLineEffectNodePath in laserLineEffectNodePaths)
            {
                Particles2D particleEffect = GetNode <Particles2D>(laserLineEffectNodePath);
                particleEffect.SetEmitting(true);
                _laserLineEffects.Add(particleEffect);
            }

            _currentLaserTimer = laserStartUpTime;
            SetLaserState(LaserState.Launched);
        }
Ejemplo n.º 26
0
    public override void _Ready()
    {
        _potionObject = GetNode <Node2D>("PotionObject");
        _area         = _potionObject.GetNode <Area2D>("Area2D");
        _sprite       = _potionObject.GetNode <Sprite>("Sprite");
        _soundPlayer  = _potionObject.GetNode <AudioStreamPlayer2D>("SoundPlayer");

        _potionObject.Rotation = InitialRotation;
        _potionObject.Position = InitialPosition;
        _totalDistance         = (InitialPosition - Destination).Length();
        _area.Connect("body_entered", this, nameof(OnEnter));
    }
Ejemplo n.º 27
0
    public override void _Ready()
    {
        _sprite = GetNode <Sprite>("Sprite");

        _spriteArea = GetNode <Area2D>("Sprite/Area2D");
        _spriteArea.Connect("mouse_entered", this, nameof(TriggerTimer));

        _timer = GetNode <Timer>("Timer");
        _timer.Connect("timeout", this, nameof(TimerTriggered));

        SetRandomPos();
    }
Ejemplo n.º 28
0
    public override void _Ready()
    {
        muzzle       = GetNode <Node2D>("Muzzle");
        space        = GetNode <Node2D>(spacePath);
        explode      = GetNode <Sprite>("Explode");
        area         = GetNode <Area2D>("Area2D");
        collider     = area.GetNode <CollisionShape2D>("CollisionShape2D");
        timerDestroy = GetNode <Timer>("TimerDestroy");
        sfxShoot     = GetNode <AudioStreamPlayer>("SfxShoot");
        sfxExplode   = GetNode <AudioStreamPlayer>("SfxExplode");

        area.Connect("area_entered", this, nameof(OnAreaEntered));
    }
Ejemplo n.º 29
0
    /// <summary>
    /// Parameters:
    /// - caller: The node creating this Collision.
    /// - callback: Method that will be called when the caller detects a collision with the given type. This method must have
    ///   one parameter with type <T>.
    /// - area2DPath: Path to the caller's Area2D node that's detecting this collision.
    /// </summary>
    public Collision(Node caller, Action <T> callback, string area2DPath = "Area2D")
    {
        Area2D area2D = caller.GetNodeOrNull <Area2D>(area2DPath);

        if (area2D == null)
        {
            return;
        }

        Callback = callback;
        area2D.Connect("area_entered", this, nameof(OnCollision));
        area2D.AddChild(this);
    }
Ejemplo n.º 30
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        KinematicBody   = GetNode <KinematicBody2D>("KinematicBody2D");
        FollowersNode   = GetNode <Node2D>("Followers");
        Area2D          = GetNode <Area2D>("KinematicBody2D/Area2D");
        Highlight       = GetNode <Sprite>("KinematicBody2D/Highlight");
        AnimatedSprite  = GetNode <AnimatedSprite>("KinematicBody2D/AnimatedSprite");
        AnimatedSprite2 = GetNode <AnimatedSprite>("KinematicBody2D/AnimatedSprite2");
        DebtLabel       = GetNode <Label>("KinematicBody2D/DebtLabel");
        DebugLabel      = GetNode <Label>("KinematicBody2D/DebugLabel");
        DialogLabel     = GetNode <Label>("KinematicBody2D/DialogLabel");

        if (!IsCPU)
        {
            Area2D.Connect("area_entered", this, nameof(OnAreaEntered));
            Area2D.Connect("area_exited", this, nameof(OnAreaExited));
        }

        Random random = new Random(FactionId);

        if (IsCPU)
        {
            AnimatedSprite2.Modulate = new Color(random.Next(0, 200) / 256f, random.Next(0, 200) / 256f, random.Next(0, 200) / 256f, 1);
            AnimatedSprite2.Show();
            AnimatedSprite2.Frame = random.Next(0, 4);
            AnimatedSprite.Hide();
        }
        else
        {
            AnimatedSprite.Show();
            AnimatedSprite2.Hide();
        }

        Camera       = (Camera2D)GetTree().GetNodesInGroup("camera")[0];
        PlayerLeader = (Leader)GetTree().GetNodesInGroup("player_leader")[0];
    }