Exemple #1
0
        /// <summary>
        /// Uses the VisualServer to draw each of an entity's split sprites, by:
        ///     1. Obtaining the Node2D that is designated to play host to a given split sprite
        ///     2. Changing the Node2D's (TileMap) parent if required
        ///     3. Creating an RID for the canvas item (the sprite drawing) and storing it so it can be freed later
        /// </summary>
        /// <param name="tileMaps"></param>
        /// <param name="tileMapZIndex"></param>
        /// <param name="entityPos"></param>
        /// <param name="entityDrawPos">Offsets the sprite upwards. Used for drawing entities falling/jumping.</param>
        public void DrawSplitSprites(TileMapList tileMaps, int tileMapZIndex, Vector2 entityPos, float entityDrawPos /*State goes here*/)
        {
            List <SplitSpriteSheetValue> splitSprites = this._splitSpriteSheet.GetSplitSpriteInfoForAnim("idle", 0); //TODO match to entity anim state

            foreach (SplitSpriteSheetValue splitSprite in splitSprites)
            {
                Node2D  splitNode2D = this._idToSplitNodes[splitSprite.splitIndex];
                TileMap tileMap     = tileMaps[tileMapZIndex + splitSprite.zIndex];
                if (splitNode2D.GetParent() != tileMap)
                {
                    if (splitNode2D.GetParent() != null)
                    {
                        splitNode2D.GetParent().RemoveChild(splitNode2D);
                    }
                    tileMap.AddChild(splitNode2D);
                }

                RID splitSpriteRID = VisualServer.CanvasItemCreate();
                this._drawnSprites.Add(splitSpriteRID);
                VisualServer.CanvasItemSetParent(splitSpriteRID, splitNode2D.GetCanvasItem());

                VisualServer.CanvasItemAddTextureRectRegion(splitSpriteRID,
                                                            new Rect2(Vector2.Zero, splitSprite.size),
                                                            this._splitSpriteSheet.GetSpriteSheetRID(),
                                                            new Rect2(splitSprite.sheetPos, splitSprite.size),
                                                            new Color(1, 1, 1, 1),
                                                            false,
                                                            this._splitSpriteSheet.GetSpriteSheetRID());

                VisualServer.CanvasItemSetTransform(splitSpriteRID, new Transform2D(0, this._relativePos - new Vector2(Globals.TileWidth / 2, Globals.TileHeight / 2) + new Vector2(0, entityDrawPos)));

                splitNode2D.Position = entityPos + splitSprite.splitPos + new Vector2(Globals.TileWidth / 2, Globals.TileHeight / 2);
            }
        }
    public void setSource(Node2D source)
    {
        this.source = source;

        // Set the parent to player
        if (!IsConnected(nameof(RayDamageSignal), source.GetParent(), "_onDamageCalculation"))
        {
            Connect(nameof(RayDamageSignal), source.GetParent(), "_onDamageCalculation");
        }
    }
Exemple #3
0
 public void _OnAreaEntered(Godot.Object otherArea)
 {
     if (this.IsFireBall)
     {
         Node2D ob = otherArea as Node2D;
         if (ob.GetParent().GetName().Contains("Peg"))
         {
             ((Peg)ob.GetParent()).Collided();
         }
     }
 }
Exemple #4
0
    public override void _Process(float delta)
    {
        if (_child == null)
        {
            return;
        }

        foreach (var body in GetOverlappingBodies() ?? new Godot.Collections.Array())
        {
            if (body is Player player)
            {
                if (Input.IsActionPressed("ui_accept"))
                {
                    var inventario = player.GetNode <Node2D>("inventario/objetos");
                    if (inventario != null)
                    {
                        if (_child != null)
                        {
                            _child.GetParent().RemoveChild(_child);
                            inventario.AddChild(_child);
                            _child.Position = inventario.Position;
                        }
                    }
                }
            }
        }
    }
Exemple #5
0
    private void CheckCollectibles()
    {
        KinematicCollision2D collision = GetSlideCollision(0);
        Node2D body = (Node2D)collision.Collider;

        if (body.GetParent().GetParent().GetName().Contains("Collectible"))
        {
            GD.Print(body.GetParent().GetParent().GetParent().GetName());
            ((Collectible)body.GetParent().GetParent()).Consume();
            ((Node2D)body.GetParent()).QueueFree();
        }
        else if (body.GetName().Contains("SceneSwitcher"))
        {
            ((SceneSwitcher)body).SwitchScene();
        }
    }
Exemple #6
0
    private void ChangeParent(Node2D child, Node2D newParent)
    {
        Vector2 prevPos   = child.GlobalPosition;
        Vector2 prevScale = GetGlobalScale();

        child.GetParent().RemoveChild(child);
        newParent.AddChild(child);
        child.SetGlobalPosition(prevPos);
        child.SetGlobalScale(prevScale);
    }
Exemple #7
0
    public void PickupObject(Node2D node)
    {
        if (_carriedObject == null)
        {
            if (node.IsInGroup("fuel"))
            {
                _fuelHeld = true;
            }

            _carriedObject = node;
            node.GetParent().RemoveChild(node);
            _carryAttachPoint.AddChild(node);
            node.SetPosition(new Vector2());
        }
    }
Exemple #8
0
    private void _onCollisioMaskAreaEntered(Node2D node)
    {
        // sending a signal if something colliding with the dragon

        //assuming it is a candy, get sprite node of the colliding node
        var sprite = (AnimatedSprite)node.GetParent().GetNode("sprite");

        //check if the animation of the colliding node is the same as the candy-sprite
        if (candySprite.Animation == sprite.Animation)
        {
            //play the gulp sound
            gulpSound.Play();

            //pick a new random candy
            randomCandy           = Game.rnd.Next(1, 10);
            candySprite.Animation = randomCandy.ToString();

            //increase dragon weight
            dragonWeight += 0.2f;

            //delete the node we have collided with, it is locked in the current frame so we put it in a queue
            node.GetParent().QueueFree();

            //increase score by 20
            Game.score += 20;
        }
        else         //otherwise reduce the dragn health
        {
            //play burp sound
            burpSound.Play();

            //reduce life
            life -= 0.2f;
            GD.Print("damage");
        }
    }
Exemple #9
0
    public override void _Ready()
    {
        _upperBone = GetNode <Node2D>(UpperBoneNode);
        _lowerBone = GetNode <Node2D>(LowerBoneNode);
        _terminus  = GetNode <Node2D>(TerminusNode);

        if (_lowerBone.GetParent() != _upperBone)
        {
            GD.Print("BONE ERROR");
        }
        else
        {
            _setExtendLimit(JointExtendLimit);
            _setFoldLimit(JointFoldLimit);
            _setJointSign(ReverseJoint);
            _readied = true;
        }
    }
Exemple #10
0
    private void _emit(Node2D enemy_object, int n = 0)
    {
        if (!enemyScenes.ContainsKey(enemy_object))
        {
            return;
        }
        var bullet_scene = enemyScenes[enemy_object];
        var queue        = bullets[bullet_scene];
        int limit        = bulletsLimit[bullet_scene];
        //GD.Print($"emit {enemy_object.Position} {n} {queue.Count} {OS.GetTicksMsec()}");

        BaseBullet bullet;

        if (queue.Count >= limit)
        {
            bullet = queue.Dequeue();
        }
        else if (queue.Count == 0 || queue.Peek().Visible)
        {
            bullet        = bulletScenes[bullet_scene].Instance() as BaseBullet;
            bullet.GDArea = GetParent <GDKnyttArea>();
            AddChild(bullet);
        }
        else
        {
            bullet = queue.Dequeue();
        }

        bullet.GlobalPosition = enemy_object.GlobalPosition;
        bullet.Enabled        = true;
        bullet.Visible        = true;

        var enemy_parent = enemy_object.GetParent <Node2D>();

        if (enemy_parent is CustomObject)
        {
            enemy_parent = enemy_parent.GetParent <Node2D>();
        }
        bullet.ZIndex = enemy_parent is GDKnyttObjectLayer ? enemy_parent.ZIndex - 1 : enemy_object.ZIndex;

        initEvents[enemy_object](bullet, n);
        queue.Enqueue(bullet);
    }
Exemple #11
0
    private void OnBulletBodyEntered(object body)
    {
        if (body is Enemy enemy)
        {
            enemy.TakeDamage(damage);
        }

        GetNode <CollisionShape2D>(DamageAreaCollisionPath).SetDeferred("disabled", false);
        hitParticleRoot.GetNode <Particles2D>("HitParticle").Emitting = true;
        hitParticleRoot.GlobalPosition = GetNode <BulletComponent>("BulletComponent").GlobalPosition;

        if (hitParticleRoot.GetParent() != GetTree().CurrentScene)
        {
            GetTree().CurrentScene.AddChild(hitParticleRoot);
        }


        GetTree().CurrentScene.GetNode <CameraShake>("MainCam").Shake(180, 90, 80);
        gameRules.StartSlowMotion(0.1f, 0.5f, 0.8f);

        GetTree().CreateTimer(0.1f).Connect("timeout", this, "DeleteRocket");
    }