Exemplo n.º 1
0
    //This is for visual feedback. We just re-render the rooms every frame.
    public override void _Process(float delta)
    {
        Level.Clear();

        foreach (object roomObj in Rooms.GetChildren())
        {
            if (roomObj is Room room)
            {
                foreach (Vector2 offset in room)
                {
                    Level.SetCellv(offset, 0);
                }
            }
            else if (roomObj is RigidBody2D body)
            {
                //var roomCast = body as Room;
                //foreach (Vector2 offset in roomCast)
                //{
                //	Level.SetCellv(offset, 0);
                //}
                //GD.Print("RoomObj is RigidBody2D");
            }
            else
            {
                GD.Print("RoomObj is not recognized. Type is " + roomObj.GetType());
            }
        }
    }
Exemplo n.º 2
0
 public void HideParticles()
 {
     foreach (Particles2D particle in particles.GetChildren())
     {
         particle.Hide();
         particle.Emitting = false;
     }
 }
Exemplo n.º 3
0
 private void PurgeOrders()
 {
     foreach (var current in _orderContainer.GetChildren())
     {
         if (current is Order order)
         {
             order.QueueFree();
         }
     }
 }
Exemplo n.º 4
0
Arquivo: Arena.cs Projeto: exts/ld44
 public void UpdateEnemyDestination(Vector2 dest)
 {
     foreach (var node in _enemyContainer.GetChildren())
     {
         if (node is Enemy enemy)
         {
             enemy.SetDestination(dest);
         }
     }
 }
Exemplo n.º 5
0
    void Reset()
    {
        health = 150;

        numSprites      = sprites.GetChildCount();
        healthPerSprite = health / numSprites;

        currentSpriteNum    = 0;
        currentSprite       = (Sprite)sprites.GetChildren()[currentSpriteNum];
        currentSpriteHealth = healthPerSprite;
    }
Exemplo n.º 6
0
        public override void _Process(float delta)
        {
            if (!touched)
            {
                AngularAcceleration = -(Gravity / RopeLength) * Mathf.Sin(Angle);
                AngularVelocity    += AngularAcceleration;
                Angle += AngularVelocity;

                AngularVelocity *= Damping;

                circleSprite.Modulate = Colors.LightBlue;
            }
            else
            {
                circleSprite.Modulate = Colors.LightGoldenrod;
            }

            // Update sprites
            var ballPos = GetBallPosition();

            circleSprite.GlobalPosition = GlobalPosition + ballPos;
            lineSprite.PositionA        = GlobalPosition;
            lineSprite.PositionB        = GlobalPosition + ballPos;

            // Update child pendulum positions
            foreach (Node2D child in children.GetChildren())
            {
                child.Position = ballPos;
            }
        }
Exemplo n.º 7
0
 private void SpawnEnemies()
 {
     foreach (EnemySpawn enemySpawn in _enemySpawns.GetChildren())
     {
         SpawnEnemy(enemySpawn);
     }
 }
Exemplo n.º 8
0
 bool CheckWallIsValid(Node2D wallraycast)
 {
     foreach (RayCast2D cast in wallraycast.GetChildren())
     {
         //var collider = cast.GetCollider();
         //GD.Print(collider);
         //cast is not colliding
         if (cast.IsColliding())
         {
             GD.Print("HIT");
             var dot = Math.Acos(Vector2.Up.Dot(cast.GetCollisionNormal()));
             if (dot > Math.PI * 0.35 && dot < Math.PI * 0.55)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
Exemplo n.º 9
0
 public void ClearDamageIndicators()
 {
     foreach (Node Child in DamageIndicatorRoot.GetChildren())
     {
         Child.QueueFree();
     }
 }
Exemplo n.º 10
0
 public void RaiseDebt()
 {
     foreach (Node node in EnemyLeadersNode.GetChildren())
     {
         if (node is Leader)
         {
             Leader leader = (Leader)node;
             leader.RaiseDebt();
         }
     }
 }
Exemplo n.º 11
0
 public void clearBoard()
 {
     endDraw();
     foreach (Node2D obj in drawContainerNode.GetChildren())
     {
         obj.QueueFree();
     }
     drawContainer.Clear();
     clearUndo();
     setEmptyLastDrawings();
 }
Exemplo n.º 12
0
    public void cleanDrawing()
    {
        Node2D path = (Node2D)gameworld.GetNode("path_" + Name);

        if (path != null)
        {
            foreach (Node2D node in path.GetChildren())
            {
                node.QueueFree();
            }
        }
    }
Exemplo n.º 13
0
    public void debugDrawClear()
    {
        Node2D path = (Node2D)gameWorld.GetNode("path_raycast");

        if (path != null)
        {
            foreach (Node2D node in path.GetChildren())
            {
                node.QueueFree();
            }
        }
    }
Exemplo n.º 14
0
    public override void _Process(float delta)
    {
        screenSize = GetViewportRect().Size;
        label.Text = $"Bunnies: {bunnies.GetChildCount()}";

        var bunnyChildren = bunnies.GetChildren();

        for (var i = 0; i < bunnyChildren.Count; i++)
        {
            var bunny    = (Sprite)bunnyChildren[i];
            var position = bunny.Position;
            var speed    = speeds[i];

            position.x += speed.x * delta;
            position.y += speed.y * delta;

            speed.y += gravity * delta;

            if (position.x > screenSize.x)
            {
                speed.x   *= -1;
                position.x = screenSize.x;
            }

            if (position.x < 0)
            {
                speed.x   *= -1;
                position.x = 0;
            }

            if (position.y > screenSize.y)
            {
                position.y = screenSize.y;
                if (random.NextDouble() > 0.5)
                {
                    speed.y = (random.Next() % 1100 + 50);
                }
                else
                {
                    speed.y *= -0.85f;
                }
            }

            if (position.y < 0)
            {
                speed.y    = 0;
                position.y = 0;
            }

            bunny.Position = position;
            speeds[i]      = speed;
        }
    }
Exemplo n.º 15
0
    public void ResetBody(Vector2 headPosition)
    {
        _head.Position = headPosition;
        _direction     = GetRandomDirection();

        foreach (Node bodyBlock in _body.GetChildren())
        {
            _body.RemoveChild(bodyBlock);
            bodyBlock.QueueFree();
        }

        Vector2 previousPosition = Vector2.Zero;

        for (int i = 0; i < _bodyLength; i++)
        {
            Sprite newBodyBlock = (Sprite)_sprite.Duplicate();

            switch (_direction)
            {
            case Direction.Left:
                newBodyBlock.Position = new Vector2(previousPosition.x + newBodyBlock.Texture.GetWidth(), 0);
                break;

            case Direction.Right:
                newBodyBlock.Position = new Vector2(previousPosition.x - newBodyBlock.Texture.GetWidth(), 0);
                break;

            case Direction.Up:
                newBodyBlock.Position = new Vector2(0, previousPosition.y + newBodyBlock.Texture.GetHeight());
                break;

            case Direction.Down:
                newBodyBlock.Position = new Vector2(0, previousPosition.y - newBodyBlock.Texture.GetHeight());
                break;
            }

            _body.AddChild(newBodyBlock);
            previousPosition = newBodyBlock.Position;
        }
    }
Exemplo n.º 16
0
    public override void _Ready()
    {
        Node2D participants = GetNode("../Participants") as Node2D;

        selection = GetNode("ColorRect") as ColorRect;

        foreach (Player player in participants.GetChildren())
        {
            players.Add(player);
        }

        nextController();
    }
Exemplo n.º 17
0
    public bool WallRaycast(Node2D parent)
    {
        foreach (var child in parent.GetChildren())
        {
            var raycast = (RayCast2D)child;
            if (!raycast.IsColliding())
            {
                return(false);
            }
        }

        return(true);
    }
Exemplo n.º 18
0
        public override void _Ready()
        {
            base._Ready();
            _destinations = Global.Destinations;
            _navigation2D = Global.GlobalNavigation2D;
            foreach (Position2D position2 in _destinations.GetChildren())
            {
                _possibleDestinations.Add(position2.GlobalPosition);
            }
//            _possible_destinations = new Array<Node>(_destinations.GetChildren()).ToList();
//            _possible_destinations = (from node2d in GetChildren().Cast<Node2D>() select node2d.Position).ToList();
            MakePath();
        }
Exemplo n.º 19
0
        public override void _Ready()
        {
            _cullTimer          = GetNode <Timer>("Timer");
            _spawnTimer         = GetNode <Timer>("SpawnTimer");
            _worldDetectionArea = GetNode <Node2D>("WorldDetectionArea");
            _spawnRaycasts      = _worldDetectionArea.GetChildren <RayCast2D>();

            _cullTimer.Connect("timeout", this, nameof(OnTimerTimeout));
            _spawnTimer.Connect("timeout", this, nameof(OnSpawnTimerTimeout));

            if (!Engine.IsEditorHint())
            {
                CallDeferred(nameof(SpawnAll));
            }
        }
Exemplo n.º 20
0
 public override void _Ready()
 {
     _player      = GetNode <Player>("../Player");
     _orbs        = GetNodeOrNull <Node2D>("../Orbs");
     _label1      = GetNode <Label>("CanvasLayer/Control/Ability1");
     _label2      = GetNode <Label>("CanvasLayer/Control/Ability2");
     _instruction = GetNode <Label>("CanvasLayer/Control/Instruction");
     if (_orbs != null)
     {
         foreach (var orb in _orbs.GetChildren())
         {
             (orb as AbilityOrb)?.Connect("PickUpOrb", this, nameof(_on_OrbPickUp));
         }
     }
     UpdateLabels();
 }
Exemplo n.º 21
0
    public override void _Ready()
    {
        ScoreLabel  = GetNode <Label>("HUD/Score");
        LivesLabel  = GetNode <Label>("HUD/Lives");
        Player      = GetNode <ClassicPlayer>("ClassicPlayer");
        Player.Game = this;
        MoveTimer   = GetNode <Timer>("MoveTimer");
        BonusTimer  = GetNode <Timer>("BonusTimer");
        Enemies     = GetNode <Node2D>("Enemies");
        StepSound   = GetNode <AudioStreamPlayer>("StepSound");
        EnemyCount  = Enemies.GetChildren().Count;

        GameOver           = GetNode <Control>("HUD/GameOver");
        GameOverLabel      = GetNode <Label>("HUD/GameOver/Box/Text");
        GameOverScoreLabel = GetNode <Label>("HUD/GameOver/Box/Score");
    }
Exemplo n.º 22
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));
            }
        }
    }
Exemplo n.º 23
0
    public void getBest()
    {
        double        bestScore = double.MinValue;
        ShootingEnemy bestAgent = null;

        foreach (ShootingEnemy agent in SpawnContainer.GetChildren())
        {
            if (agent.Score > bestScore)
            {
                bestAgent = agent;
                bestScore = agent.Score;
            }
        }
        camera.Position = bestAgent.GlobalPosition;
        label.Text      = $"Generation:{Generation}\nBest Agent Network:";
        best            = bestAgent.GetPhenotype();
        best_set        = true;
        // VisualiseNetwork(bestAgent.GetPhenotype());
    }
Exemplo n.º 24
0
    public override void _Process(float delta)
    {
        Node2D rayCasts = jelly.GetNode <Node2D>("RayCasts");

        if (Input.IsActionPressed("ui_accept"))
        {
            Vector2 dirJump = Vector2.Zero;
            foreach (Node n in rayCasts.GetChildren())
            {
                RayCast2D rayCast = (RayCast2D)n;
                if (rayCast.IsColliding())
                {
                    dirJump -= rayCast.CastTo;
                }
            }
            dirJump = dirJump.Rotated(rayCasts.GlobalRotation).Normalized();
            jelly.center.ApplyCentralImpulse(dirJump * 120);
        }
    }
Exemplo n.º 25
0
    public void debugDrawing(Vector2 point)
    {
        Node2D path = (Node2D)gameworld.GetNode("path_" + Name);

        if (path == null)
        {
            path      = (Node2D)gameworld.GetNode("pathchart").Duplicate();
            path.Name = "path_" + Name;
            gameworld.AddChild(path);
        }

        foreach (Node2D node in path.GetChildren())
        {
            node.QueueFree();
        }

        Node2D pointNode = (Node2D)gameworld.GetNode("dot").Duplicate();

        pointNode.Name     = "pathdot_" + Name + "_" + point.x + "_" + point.y;
        pointNode.Position = point;
        path.AddChild(pointNode);
    }
Exemplo n.º 26
0
Arquivo: Arena.cs Projeto: exts/ld44
        private void SetupSpawnPointsInSpawner()
        {
            foreach (var corner in _spawnPoints.GetChildren().ToList())
            {
                if (!(corner is Node2D points))
                {
                    continue;
                }

                var list = new List <Vector2>();
                foreach (var point in points.GetChildren().ToList())
                {
                    if (point is Position2D position2D)
                    {
                        list.Add(position2D.GlobalPosition);
                    }
                }

                _spawner.AddSpawnPoints(list);
            }

            _spawner.RandomizeSpawnOrder();
        }
Exemplo n.º 27
0
    private bool _check_is_grounded()
    {
        foreach (RayCast2D raycast in Raycasts.GetChildren())
        {
            if (raycast.IsColliding())
            {
                Godot.Object myCollider = raycast.GetCollider();
                if (myCollider.GetType() != typeof(Godot.TileMap))
                {//GD.Print("Ray collided with: "+ myCollider.GetType());
                 //Only kill if we haven't been hit before
                    if (hitstun == 0)
                    {
                        myCollider.Set("DEAD", true);
                    }
                }



                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 28
0
    void Move()
    {
        var children = Enemies.GetChildren();

        if (children.Count != 0)
        {
            StepSound.Seek(0);
            StepSound.Play();
            foreach (var c in children)
            {
                if (c is ClassicEnemy e)
                {
                    e.Tick();
                }
            }

            var stepSize = 8;
            if (MoveRight)
            {
                var max    = GetMaxPosition(children);
                var target = 512 - max - 32;
                if (Enemies.Position.x >= (target))
                {
                    MoveRight        = !MoveRight;
                    Enemies.Position = new Vector2(Enemies.Position.x, Enemies.Position.y + 32);
                    var h = GetMaxHeight(children);
                    if (h >= 224)
                    {
                        Lose();
                        return;
                    }
                }
            }
            else
            {
                var min    = GetMinPosition(children);
                var target = -512 - min + 32;
                if (Enemies.Position.x <= (target))
                {
                    MoveRight        = !MoveRight;
                    Enemies.Position = new Vector2(Enemies.Position.x, Enemies.Position.y + 32);
                    var h = GetMaxHeight(children);
                    if (h >= 224)
                    {
                        Lose();
                        return;
                    }
                }
            }

            if (MoveRight)
            {
                Enemies.Position = new Vector2(Enemies.Position.x + stepSize, Enemies.Position.y);
            }
            else
            {
                Enemies.Position = new Vector2(Enemies.Position.x - stepSize, Enemies.Position.y);
            }

            var time = ((float)Enemies.GetChildren().Count / EnemyCount) * 0.8f * (0.85f / Level);
            MoveTimer.Start(time);
        }
        else
        {
            Win();
        }
    }
Exemplo n.º 29
0
        public override void _Process(float delta)
        {
            var gameState = _gameManager.GetState();
            var diceState = gameState.DiceState;

            if (diceState.CurrentDicePhase == DicePhase.Hidden)
            {
                this.Hide();
                return;
            }

            if (!diceState.DicesData.TryGetValue(diceState.CurrentDice, out var diceData))
            {
                return;
            }

            if (!_isInitialized)
            {
                var instanceCount = diceData.DiceInstances;

                foreach (DiceDisplay diceDisplay in _diceDisplays.GetChildren())
                {
                    diceDisplay.Free();
                }

                for (var x = 0; x < instanceCount; x++)
                {
                    var diceDisplayScene = ResourceLoader.Load <PackedScene>(diceData.DicePath);

                    if (diceDisplayScene != null)
                    {
                        var diceDisplayInstance = (DiceDisplay)diceDisplayScene.Instance();
                        _diceDisplays.AddChild(diceDisplayInstance);

                        diceDisplayInstance.Position = new Vector2(x * WidthPerCell, 0);
                    }
                }

                _diceDisplays.Position = new Vector2(DisplayDicePosition, 0);
                _isInitialized         = true;

                this.Show();
            }

            var diceManager = _gameManager.GetDiceManager();

            if (diceState.CurrentDicePhase == DicePhase.Rolling)
            {
                _currentTime += (delta * 1000);

                var diceArts     = diceData.DiceArts;
                var diceArtAngle = diceData.DiceArtAngles;
                var diceNames    = diceData.DiceNames;

                foreach (DiceDisplay diceDisplay in _diceDisplays.GetChildren())
                {
                    var selectedIndex = _random.Randi() % diceArts.Length;

                    diceDisplay.SetDiceData(diceArts[selectedIndex], diceNames[selectedIndex], diceArtAngle[selectedIndex]);
                }

                if (_currentTime >= 1000)
                {
                    _currentTime = 0;

                    diceManager.SetRandomValue();                     //will trigger hiding
                }
            }
            else if (diceState.CurrentDicePhase == DicePhase.Hiding)
            {
                _currentTime += (delta * 0.004f);

                var newColor = this.Modulate.LinearInterpolate(new Color(HIDDEN_COLOR), _currentTime);
                this.Modulate = newColor;

                if (this.Modulate.ToHtml() == HIDDEN_COLOR)
                {
                    diceManager.HideDice();
                    _isInitialized = false;
                }
            }
        }