Beispiel #1
0
        public Tiler(Grid grid, Node tilesContainer, PackedScene packedScene, Node timers, HudScene hud)
        {
            Hud            = hud;
            Grid           = grid;
            Timers         = timers;
            TileScene      = packedScene;
            TilesContainer = tilesContainer;

            rand = new Random();

            score              = new Score(Hud);
            ShowHintTimer      = Timers.GetNode("show_hint_timer") as Timer;
            DestroyedTileTimer = Timers.GetNode("destroy_tiles_timer") as Timer;
        }
    //testing

    public void OnStartNextLevel()
    {
        PackedScene scene = GD.Load <PackedScene>("res://levels/Game.tscn");

        RemoveChild(currentScene);

        currentScene = scene.Instance();
        currentScene.Connect("ready", this, "OnLevelReady");
        currentScene.Connect("LevelCompleted", this, "OnLevelCompleted");
        currentScene.Connect("GameOver", this, "OnGameOver");

        musicPlayer.Stop();
        AddChild(currentScene);
    }
Beispiel #3
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     base._Ready();
     _plantScenes = new PackedScene[] {
         GD.Load <PackedScene>("res://Objects/Tree.tscn"),
         GD.Load <PackedScene>("res://Objects/FruitTree.tscn"),
         GD.Load <PackedScene>("res://Objects/Mushroom.tscn"),
         GD.Load <PackedScene>("res://Objects/Bush.tscn"),
         GD.Load <PackedScene>("res://Objects/Cactus.tscn"),
     };
     _humanScene = GD.Load <PackedScene>("res://Objects/Human.tscn");
     Group.WaterSources.Add(this);
     GenerateMap();
 }
 /// <summary>
 ///   Sets all instance variables to standard values.
 /// </summary>
 private void InitStandardValues()
 {
     Projectile          = ProjectileFactory.CreateBullet();
     _timer              = GetNode("Timer") as Timer;
     _timer.Autostart    = false;
     _timer.OneShot      = true;
     SecondsBetweenShots = 0.4f;
     MagSize             = 20;
     Ammo = MagSize;
     ProjectilesPerShot    = 8;
     ProjectileShooterName = "Abstract Projectile Shooter";
     MaxOffsetAngle        = 3;
     _knockbackForce       = 50;
 }
Beispiel #5
0
    public override void _Ready()
    {
        // Load Save File?

        // Load Main Menu
        GD.Print("I am here!");
        PackedScene MainMenuScene = ResourceLoader.Load <PackedScene>("res://MainMenu.tscn");

        GD.Print(MainMenuScene.ToString());
        MarginContainer MainMenu = MainMenuScene.Instance() as MarginContainer;

        GetTree().Root.CallDeferred("AddChild", MainMenu);
        Hide();
    }
Beispiel #6
0
    // Network callbacks from SceneTree

    // callback from SceneTree
    private void _Player_Connected(int id)
    {
        GD.Print("player connected");
        // someone connected, start the game!
        PackedScene main = (PackedScene)ResourceLoader.Load("res://Scenes/Main.tscn");
        Main        inst = (Main)main.Instance();
        Node        of   = GetNode("/root/OpenFortress");

        of.AddChild(inst);

        _network        = (Network)GetNode("/root/OpenFortress/Network");
        _network.Active = true;
        this.Hide();
    }
Beispiel #7
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     animationPlayer      = GetNode <AnimationPlayer>("AnimationPlayer");
     animationTree        = GetNode <AnimationTree>("AnimationTree");
     gunNode              = GetNode <Node2D>("Gun");
     animationTree.Active = true;
     animationState       = animationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
     bullet        = GD.Load <PackedScene>("res://Player/Bullet.tscn");
     flashbang     = GD.Load <PackedScene>("res://Player/Flashbang.tscn");
     timer         = GetNode <Timer>("Timer");
     flashCooldown = GetNode <Timer>("FlashCooldown");
     walkTimer     = GetNode <Timer>("WalkTimer");
     sound         = GetNode <AudioStreamPlayer>("AudioStreamPlayer");
 }
 public void _on_AreaBullet_area_entered(Area2D area)
 {
     if (area.Name == "AreaBarrel" || area.Name == "AreaMeteor")
     {
         HitSound         = (PackedScene)ResourceLoader.Load("res://Music/NodeDanScript/HitSound.tscn");
         HitSoundInstance = (AudioStreamPlayer)HitSound.Instance();
         GetParent().AddChild(HitSoundInstance);
         HitSoundInstance.Play();
     }
     if (area.Name == "AreaBarrel" || area.Name == "AreaMeteor" || area.Name == "AreaBullet" || area.Name == "LantaiArea2D")
     {
         QueueFree();
     }
 }
Beispiel #9
0
    private void _ToMenu()
    {
        PackedScene  target = GD.Load("res://Scenes/DisplayScore/DisplayScore.tscn") as PackedScene;
        DisplayScore scene  = (DisplayScore)target.Instance();

        scene.Score = Math.Round(Score.Percent * 100).ToString();

        for (int i = 0; i < GetChildCount(); i += 1)
        {
            GetChild(i).QueueFree();
        }
        QueueFree();
        GetTree().Root.AddChild(scene);
    }
Beispiel #10
0
    /// <summary>
    /// Deferred
    /// </summary>
    /// <param name="path"></param>
    private void DeferredGotoScene(string path)
    {
        // we are deferred so we can free the current scene
        currentScene.Free();

        // load the next scene
        PackedScene nextScene = (PackedScene)ResourceLoader.Load(path);

        // setup the next scene as a child of the root node
        currentScene = nextScene.Instance();
        GetTree().Root.AddChild(currentScene);
        // This is for compatibility with the SceneTree.change_scene() API.
        GetTree().CurrentScene = currentScene;
    }
Beispiel #11
0
 public override void _Ready()
 {
     hologram_scene   = ResourceLoader.Load("res://knytt/juni/Hologram.tscn") as PackedScene;
     MotionParticles  = GetNode <JuniMotionParticles>("JuniMotionParticles");
     Detector         = GetNode <Sprite>("Detector");
     Detector.Visible = true;
     ClimbCheckers    = GetNode <ClimbCheckers>("ClimbCheckers");
     GroundChecker    = GetNode <GroundChecker>("GroundChecker");
     Sprite           = GetNode <Sprite>("Sprite");
     Umbrella         = GetNode <Umbrella>("Umbrella");
     Umbrella.reset();
     Anim = Sprite.GetNode <AnimationPlayer>("AnimationPlayer");
     transitionState(new IdleState(this));
 }
Beispiel #12
0
    public void set_new_scene(PackedScene scene_resource)
    {
        try{
            //GD.Print("loading scene resource : ",scene_resource);
            GetTree().ChangeSceneTo(scene_resource);
            //current_scene = scene_resource.Instance();
            //GetTree().Root.AddChild(current_scene);

            EmitSignal("chargement_fini");
        }
        catch {
            GD.Print("EEEEEEEEEEEEEEEERRRRRRRRRRRRRRRRROOOOOOOOOOOOOOOOOORRRRRRRRR");
        }
    }
Beispiel #13
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        StartPressedEvent.RegisterListener(StartListener);

        menuScene         = ResourceLoader.Load("res://Scenes/Menu.tscn") as PackedScene;
        inputHandlerScene = ResourceLoader.Load("res://Scenes/InputHandler.tscn") as PackedScene;
        soundManagerScene = ResourceLoader.Load("res://Scenes/SoundManager.tscn") as PackedScene;
        playerScene       = ResourceLoader.Load("res://Scenes/Player.tscn") as PackedScene;
        OrbScene          = ResourceLoader.Load("res://Scenes/Orb.tscn") as PackedScene;
        StartRoomScene    = ResourceLoader.Load("res://Scenes/StartRoom.tscn") as PackedScene;
        mapBuilderScene   = ResourceLoader.Load("res://Scenes/MapBuilder.tscn") as PackedScene;
        winScene          = ResourceLoader.Load("res://Scenes/WinScene.tscn") as PackedScene;
        Init();
    }
Beispiel #14
0
    public override void _Ready()
    {
        var singleton = GetNode <Singleton>("/root/Singleton");

        singleton.SetHUDVisibility(true);
        singleton.UpdateLevel();
        singleton.SpeedrunActive = true;
        MobCount  = singleton.LevelNumber * 5;
        _level    = singleton.LevelNumber;
        _mobScene = (PackedScene)ResourceLoader.Load("res://objects/character/Zombie.tscn");
        _player   = GetNode <Player>("Player");

        Connect("UpdateMob", singleton, "UpdateMobCount");
    }
    public void informaMuerteCaja(EnemigoCajaBase enemigo)
    {
        try {
            listaenemigos.Remove(enemigo);

            PackedScene escena = (PackedScene)ResourceLoader.Load("res://MuerteCaja.tscn");

            MuerteCaja item = (MuerteCaja)escena.Instance();
            item.Translation = enemigo.Translation;
            AddChild(item);
        }
        catch (Exception ex) {
        }
    }
Beispiel #16
0
 public AnimalPreset(AnimalBehaviourComponent.AnimalSex sex, PackedScene scene, AnimalBehaviourComponent.AnimalDiet diet, int foodChainLevel, int breedability, string presetName, int foodDrop = 1,
                     float birthDrop = 20.0f, float oxygenConsumption = 0.0001f, float co2Production = 0.0001f)
 {
     this.sex               = sex;
     this.scene             = scene;
     this.diet              = diet;
     this.foodChainLevel    = foodChainLevel;
     this.breedability      = breedability;
     this.presetName        = presetName;
     this.oxygenConsumption = oxygenConsumption;
     this.co2Production     = co2Production;
     this.foodDrop          = foodDrop;
     this.birthDrop         = birthDrop;
 }
Beispiel #17
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     headingCast2D          = this.FindNode("RayCast2D", true, true) as RayCast2D;
     frontExhaust           = this.FindNode("FrontExhaust", true, true) as Node2D;
     backExhaust            = this.FindNode("BackExhaust", true, true) as Node2D;
     rocketLauncherPosition = this.FindNode("RocketLauncherPosition", true, true) as Position2D;
     dummyRocketScene       = (PackedScene)ResourceLoader.Load("res://src/Ammo/DummyRocket.tscn");
     ForwardThruster        = this.FindNode(nameof(ForwardThruster)) as Thruster;
     BackwardThruster       = this.FindNode(nameof(BackwardThruster)) as Thruster;
     Steering     = this.FindNode(nameof(Steering)) as Steering;
     SpeedBrake   = this.FindNode(nameof(SpeedBrake)) as Drag;
     Pilot        = this.FindNode(nameof(Pilot)) as Pilot;
     DockingPilot = this.FindNode(nameof(DockingPilot)) as DockingPilot;
 }
Beispiel #18
0
    public static void AddItemToInventory(int itemType, int stack)
    {
        Item selectedItem  = GameData.playerInventory[GameData.selectedInventorySlot];
        Item itemToRecieve = itemsDict[itemType];
        bool itemPlaced    = false;

        //First, we check if a stack of the item exists
        for (int i = 0; i < 5; i++)
        {
            if (!itemPlaced)
            {
                if (GameData.playerInventory[i].type == itemType)
                {
                    GameData.playerInventory[i].stack += stack;
                    itemPlaced = true;
                }
            }
        }

        //Second, we check if there's an empty slot
        for (int i = 0; i < 5; i++)
        {
            if (!itemPlaced)
            {
                if (GameData.playerInventory[i].type == Air)
                {
                    GameData.playerInventory[i] = itemToRecieve;
                    itemPlaced = true;
                }
            }
        }

        //Lastly, if the item can't be picked up, throw out whatever you're holding
        if (!itemPlaced)
        {
            if (selectedItem.type != Air)
            {
                PackedScene itemScene   = GD.Load <PackedScene>("res://Scenes/Environment/Items/" + selectedItem.name + ".tscn");
                Node2D      droppedItem = itemScene.Instance() as Node2D;
                droppedItem.Set("initializeTimer", 30);
                droppedItem.Set("itemType", selectedItem.type);
                droppedItem.Set("amount", selectedItem.stack);
                GameData.mapYSort.AddChild(droppedItem);
                droppedItem.GlobalPosition = Player.player.GlobalPosition;
            }
            GameData.playerInventory[GameData.selectedInventorySlot] = itemToRecieve;
        }

        GameData.gameData.EmitSignal(nameof(GameData.UpdateInventorySlotDrawings));
    }
Beispiel #19
0
 public override void _Ready()
 {
     timeSinceLastShot = 0;
     //set it to this instead of 0 so that it immediately changes direction
     timeSinceLastDirectionChange = directionChangeInterval;
     movementDirection            = Vector3.Forward;
     rng   = new Random();
     world = (Spatial)GetTree().CurrentScene;
     if (world.HasNode("Player"))
     {
         targetPlayer = GetTree().CurrentScene.GetNode <Player>("Player");
     }
     bulletScene = GD.Load <PackedScene>("res://Bullet.tscn");
 }
    /* Convenience method for creating nodes. */
    public static Node Instance(string path)
    {
        byte[] bytes = Encoding.Default.GetBytes(path);
        path = Encoding.UTF8.GetString(bytes);
        PackedScene packedScene = (PackedScene)GD.Load(path);

        if (packedScene == null)
        {
            GD.Print("Path [" + path + "] is invalid.");
            return(null);
        }

        return(packedScene.Instance());
    }
Beispiel #21
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        // Get references to parts of tanks
        trackleft  = (MeshInstance)GetNode("TrackLeft");
        trackright = (MeshInstance)GetNode("TrackRight");
        body       = (MeshInstance)GetNode("Body");
        turret     = (KinematicBody)GetNode("Turret");
        gun        = (MeshInstance)GetNode("Turret/TurretMesh/Gun");

        // load sounds
        trackmovementsound = (AudioStreamPlayer3D)GetNode("SoundGroup/TrackMovementSound");
        firesound          = (AudioStreamPlayer3D)GetNode("SoundGroup/FireSound");
        explodesound       = (AudioStreamPlayer3D)GetNode("SoundGroup/ExplosionSound");
        soundgroup         = GetNode("SoundGroup");

        // load cameras
        thirdpersoncamera = (Camera)GetNode("ThirdPersonCam");
        firstpersoncamera = (Camera)GetNode("Turret/TurretMesh/Gun/BulletSpawn/Camera");

        // reference to explosion for death
        explosion = (Particles)GetNode("Explosion/Particles");
        explosion.SetEmitting(false);

        // Load bullet scene
        bulletscene = ResourceLoader.Load("res://Bullet.tscn") as Godot.PackedScene;

        // Set a color for the tank
        setTankColor(defaultTankColor);

        health = maxhealth;

        // add signals
        AddUserSignal("dec_local_health");
        AddUserSignal("respawn");
        AddUserSignal("bullet_fired");

        // connect respawn timer
        AddChild(deathtimer);
        deathtimer.Connect("timeout", this, "Respawn");
        deathtimer.SetWaitTime(RESPAWN_SECONDS);

        SetProcess(true);

        // required to appear at spawn
        MoveAndSlide(new Vector3(0, 0, 0), new Vector3(0, 1, 0), true);

        // enforce no flying tanks issue #20
        originalY = Transform.origin.y;
    }
Beispiel #22
0
        public override void Callback(int peerId, AbstractNetworkMessage abstractNetworkMessage)
        {
            ClientPeerConnectionUpdate clientPeerConnectionUpdate = abstractNetworkMessage as ClientPeerConnectionUpdate;

            if (Tree.IsNetworkServer())
            {
                if (clientPeerConnectionUpdate.Disconnected)
                {
                    ClientRepresentation disconnectedPeer = Server.ConnectedClients[peerId];
                    //disconnect actual peer
                    Server.ENetInstance.DisconnectPeer(peerId, true);
                    foreach (var peer in Server.ConnectedClients)
                    {
                        if (peer.Key != peerId)
                        {
                            ObjectBroker.Instance.NetworkService.toClient(peer.Key, new ClientPeerConnectionUpdate(disconnectedPeer, true));
                        }
                    }
                }
            }
            else
            {
                if (!clientPeerConnectionUpdate.Disconnected)
                {
                    if (Tree.Root.GetNode(SceneService.NODE_PATH_SCENE).HasNode(GD.Str(clientPeerConnectionUpdate.ClientRepresentation.Id)))
                    {
                        return;
                    }

                    PackedScene         peerRepresentationResource = ResourceLoader.Load("res://assets/scenes/Character/Character.tscn") as PackedScene;
                    Godot.KinematicBody peerRepresentation         = peerRepresentationResource.Instance() as Godot.KinematicBody;
                    peerRepresentation.Name = GD.Str(clientPeerConnectionUpdate.ClientRepresentation.Id);
                    peerRepresentation.SetNetworkMaster(clientPeerConnectionUpdate.ClientRepresentation.Id);
                    peerRepresentation.Translation = clientPeerConnectionUpdate.ClientRepresentation.Translation;
                    peerRepresentation.Rotation    = clientPeerConnectionUpdate.ClientRepresentation.Rotation;

                    Node peerName = peerRepresentation.GetNode("Name");
                    ((Label)peerName.GetNode("Viewport/Label")).Text = clientPeerConnectionUpdate.ClientRepresentation.Name;

                    Tree.Root.GetNode(SceneService.NODE_PATH_SCENE).AddChild(peerRepresentation);
                }
                else
                {
                    Node peerNode = Tree.Root.GetNode(SceneService.NODE_PATH_SCENE).GetNode(GD.Str(clientPeerConnectionUpdate.ClientRepresentation.Id));
                    Tree.Root.GetNode(SceneService.NODE_PATH_SCENE).RemoveChild(peerNode);
                    peerNode.QueueFree();
                }
            }
        }
Beispiel #23
0
    public override void _Ready()
    {
        loadingItem              = GetNode <Control>(LoadingItemPath);
        noSavesItem              = GetNode <Control>(NoSavesItemPath);
        savesList                = GetNode <BoxContainer>(SavesListPath);
        deleteConfirmDialog      = GetNode <CustomConfirmationDialog>(DeleteConfirmDialogPath);
        loadOlderConfirmDialog   = GetNode <CustomConfirmationDialog>(LoadOlderSaveDialogPath);
        loadNewerConfirmDialog   = GetNode <CustomConfirmationDialog>(LoadNewerSaveDialogPath);
        loadInvalidConfirmDialog = GetNode <CustomConfirmationDialog>(LoadInvalidSaveDialogPath);
        loadIncompatibleDialog   = GetNode <CustomConfirmationDialog>(LoadIncompatibleDialogPath);
        upgradeSaveDialog        = GetNode <CustomConfirmationDialog>(UpgradeSaveDialogPath);
        upgradeFailedDialog      = GetNode <ErrorDialog>(UpgradeFailedDialogPath);

        listItemScene = GD.Load <PackedScene>("res://src/saving/SaveListItem.tscn");
    }
Beispiel #24
0
    public override void _Ready()
    {
        //Load the music scene that contains all the songs
        musicScene = ResourceLoader.Load("res://Scenes/Music.tscn") as PackedScene;
        music      = musicScene.Instance();
        AddChild(music);
        //Load hte sfx scene that contains all the sfx
        sfxScene = ResourceLoader.Load("res://Scenes/Sfx.tscn") as PackedScene;
        sfx      = sfxScene.Instance();
        AddChild(sfx);

        //Register the hit event for sound feedback on triggering
        HitEvent.RegisterListener(Hit);
        //Register to the rest of the events that could use sounds as quees
    }
Beispiel #25
0
        /// <summary>Adds an instance of <see cref="Item"/> to an <see cref="ItemSlot"/>.</summary>
        /// <param name="slot"><see cref="ItemSlot"/> where the <see cref="Item"/> is to be added</param>
        /// <param name="item"><see cref="Item"/> to be added</param>
        internal static void AddItemInstanceToSlot(ItemSlot slot, Item item)
        {
            PackedScene scene = (PackedScene)ResourceLoader.Load("res://scenes/inventory/InventoryItem.tscn");

            while (slot.GetChildren().Count > 1)
            {
                slot.RemoveChild(slot.GetChild(1));
            }
            InventoryItem invItem = (InventoryItem)scene.Instance();

            slot.AddChild(invItem);
            slot.Item = invItem;
            slot.Item.SetItem(item);
            invItem.Theme = (Theme)ResourceLoader.Load("res://resources/TextureRect.tres");
        }
Beispiel #26
0
    public Enemy SpawnEnemy(string enemySceneName)
    {
        string      fullPath   = string.Format(enemyScenePath, enemySceneName);
        PackedScene enemyScene = GD.Load <PackedScene>(fullPath);

        Vector2 spawnPoint = GetRandomSpawnPoint();

        Enemy enemy = enemyScene.Instance <Enemy>();

        this.parent.AddChild(enemy);
        enemy.GlobalPosition = spawnPlatform.GlobalPosition + spawnPoint;
        GD.Print(enemy.GlobalPosition);

        return(enemy);
    }
    void generateFootballerField(FootballerData data)
    {
        PackedScene scene = (PackedScene)ResourceLoader.Load("Scenes/AdvancedComponents/FootballerShortInfoField.tscn");
        FootballerShortInfoField field = (FootballerShortInfoField)scene.Instance();

        string name    = data.Name;
        string surname = data.Surname;
        int    age     = GameData.CURRENT_YEAR - data.BirthYear;
        int    avg     = data.Average;
        string country = ValidCountries.CountryToString(data.Country);

        field.Initialize(name, surname, age, avg, country);

        footballersList.AddChild(field);
    }
Beispiel #28
0
        public static void LoadSceneCache(List <string> scenes)
        {
            _sceneCache = new Dictionary <string, PackedScene>();
            foreach (string scene in scenes)
            {
                string      path = "res://" + scene + ".tscn";
                PackedScene ps   = GD.Load <PackedScene>(path);
                _sceneCache.Add(scene, ps);

                if (ps == null)
                {
                    Log("Unable to load: " + path);
                }
            }
        }
Beispiel #29
0
        public override void _Ready()
        {
            // set random enemy color on spawn
            var enemyColor     = GameScene.Rand.Next(0, _enemyColors.Length);
            var animatedSprite = (AnimatedSprite)GetNode("AnimatedSprite");

            animatedSprite.Animation = _enemyColors[enemyColor];

            _bulletObject = (PackedScene)ResourceLoader.Load("res://Scenes/Objects/Bullet.tscn");

            Connect("area_entered", this, nameof(EnemyDamaged));

            // start direction
            startDirectionUp = GameScene.Rand.Next(0, 2) == 0;
        }
        private void ChangeScene(PackedScene scene)
        {
            var node = scene.Instance();

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

            AddChild(node);
            // Todo: Verify those signals
            node.Connect("quit", this, nameof(GoToMainMenu));
            node.Connect("replace_main_scene", this, nameof(ReplaceMainScene));
        }