예제 #1
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        _gameState  = (GameState)GetNode("/root/GameState");
        Collectible = (PackedScene)ResourceLoader.Load("res://scenes/Collectible.tscn");
        Player      = GetNode <Player>("Player");
        Pickups     = GetNode <TileMap>("Pickups");
        Blocks      = GetNode <TileMap>("Blocks");
        Hud         = GetNode <HUD>("CanvasLayer/HUD");
        Pickups.Hide();
        Blocks.Hide();
        Score = 0;

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

        /* signal ScoreChanged is emitted from 2 places so needs to be connected in both places. Need
         * the Player.Connect(...) when connecting from outside Player*/
        Connect("ScoreChanged", Hud, "_on_ScoreChanged");
        Player.Connect("ScoreChanged", Hud, "_on_ScoreChanged");
        Connect("LifeChanged", Hud, "_on_Player_LifeChanged");
        Player.Connect("LifeChanged", Hud, "_on_Player_LifeChanged");

        GetNode <Player>("Player").Start(new Vector2(startPos.Position.x, startPos.Position.y));

        SetCameraLimits();
        SpawnPickups();
    }