Exemple #1
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     for (int i = 0; i < NumWaves; i++)
     {
         PackedScene scene = (PackedScene)ResourceLoader.Load("res://Scenes/Wave" + i + ".tscn");
         Node2D      root  = (Node2D)scene.Instance();
         this.AddChild(root);
         Waves.Add(new WaveData {
             Spawns = new SpawnData[root.GetChildCount()]
         });
         int longest = 0;
         for (int idx = 0; idx < root.GetChildCount(); idx++)
         {
             SpawnData data = (SpawnData)root.GetChild(idx);
             if (data.SpawnTime >= longest)
             {
                 longest = data.SpawnTime;
             }
             Waves[i].Spawns[idx] = new SpawnData(data);
         }
         Waves[i].Length = longest;
     }
     score = 0;
     LoadHighScore();
 }
    public void IncreaseBodySize()
    {
        Sprite newBodyBlock = (Sprite)_sprite.Duplicate();

        newBodyBlock.Position = ((Node2D)_body.GetChild(_body.GetChildCount() - 1)).Position;

        _body.AddChild(newBodyBlock);
    }
Exemple #3
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;
        }
    }
Exemple #4
0
    //Places the rooms and starts the physics simulation. Once the simulation is done
    //("rooms_placed" gets emitted), it continues by assigning tiles in the Level node.
    private async void Generate()
    {
        for (int i = 1; i <= MaxRooms; i++)
        {
            var room = RoomResource.Instance() as Room;

            room.Connect(nameof(Room.SleepingStateChanged), this, nameof(_on_Room_sleeping_state_changed));
            room.Setup(_rng, Level);
            Rooms.AddChild(room);

            _meanRoomSize += room.Size;
        }
        _meanRoomSize /= Rooms.GetChildCount();

        //Wait for all rooms to be positioned in the game world.
        await ToSignal(this, nameof(RoomsPlaced));

        GD.Print("Generate RoomsPlaced Signal Received");

        Rooms.QueueFree();

        //Draws the tiles on the `level` tilemap.
        Level.Clear();

        foreach (var entry in _data)
        {
            Level.SetCellv(entry.Key, 0);
        }
    }
Exemple #5
0
    public void powerup_remover()
    {
        Node2D all_powerups = (Node2D)GetNode("Powerups");

        for (int i = 0; i < all_powerups.GetChildCount(); i += 1)
        {
            all_powerups.GetChild(i).QueueFree();
        }
    }
Exemple #6
0
 public override void _Process(float delta)
 {
     if (SpawnContainer.GetChildCount() == 0)
     {
         spawner.SpawnEntities();
         Generation++;
     }
     getBest();
     Update();
 }
Exemple #7
0
 private void PlayerWonCheck()
 {
     if (hasPlayerWonCheck == true)
     {
         if (enemiesNode.GetChildCount() == 0)
         {
             EmitSignal("SPlayerWon");
             hasPlayerWonCheck = false;
         }
     }
 }
Exemple #8
0
    void Reset()
    {
        health = 150;

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

        currentSpriteNum    = 0;
        currentSprite       = (Sprite)sprites.GetChildren()[currentSpriteNum];
        currentSpriteHealth = healthPerSprite;
    }
Exemple #9
0
    public override void _Ready()
    {
        if (!Engine.EditorHint)
        {
            GetNode <Label>("NameLabel").QueueFree();
        }

        if (HasNode("Machine"))
        {
            Machine = GetNode <Home>("Machine");
        }

        playerSpawn = GetNode <Position2D>("PlayerSpawn");

        Node2D spawnersNode = GetNode <Node2D>("Spawners");

        spawners = new Spawner[spawnersNode.GetChildCount()];
        for (int i = 0; i < spawners.Length; i++)
        {
            RayCast2D ray = spawnersNode.GetChild <RayCast2D>(i);
            spawners[i].FacingDir = (int)ray.Scale.x;
            spawners[i].Position  = ray.GlobalPosition;
        }

        Node2D dropPlacesNode = GetNode <Node2D>("DropPlaces");

        dropPlaces = new Vector2[dropPlacesNode.GetChildCount()];
        for (int i = 0; i < dropPlaces.Length; i++)
        {
            Position2D dropPlace = dropPlacesNode.GetChild <Position2D>(i);
            dropPlaces[i] = dropPlace.GlobalPosition;
        }

        Node2D doorsNode = GetNode <Node2D>("Doors");

        doors = new Door[doorsNode.GetChildCount()];
        for (int i = 0; i < doors.Length; i++)
        {
            doors[i] = doorsNode.GetChild <Door>(i);
        }

        transitions = GetNode <Node2D>("Transitions");

        if (!HasNode("ScriptSequence"))
        {
            return;
        }

        stageScript = GetNode <StageScript>("ScriptSequence");
        stageScript.BuildFor(this);
    }
Exemple #10
0
    private Stage GetStageAt(Vector2 globalPosition)
    {
        for (int i = 0; i < stages.GetChildCount(); i++)
        {
            Stage stage  = stages.GetChildOrNull <Stage>(i);
            Rect2 global = stage.GetGlobalRect();

            if (global.HasPoint(globalPosition))
            {
                return(stage);
            }
        }

        return(null);
    }
Exemple #11
0
    private void AddBomb(Vector2 position)
    {
        // TODO : Validate position before adding

        var createdBomb = (Bomb)bombScene.Instance();

        createdBomb.Position = position;



        bombsContainer.CallDeferred("add_child", createdBomb);
        bombs.Add(createdBomb);

        GD.Print($"Nb children : {bombsContainer.GetChildCount()}");
    }
Exemple #12
0
    public void SetTransitionsLock(bool lockState)
    {
        for (int i = 0; i < transitions.GetChildCount(); i++)
        {
            transitions.GetChild <StageTransition>(i).Locked = lockState;
        }

        for (int i = 0; i < doors.Length; i++)
        {
            if (!lockState)
            {
                doors[i].Open();
            }
            else
            {
                doors[i].Close();
            }
        }
    }
 public override void _Process(float delta)
 {
     screenSize = GetViewportRect().Size;
     label.Text = "Bunnies " + bunnies.GetChildCount();
 }