// Called when the node enters the scene tree for the first time. public override void _Ready() { creatureGenerator = (PackedScene)GD.Load("res://Scenes/Creature.tscn"); // create some initial food foodGenerator_ = (PackedScene)GD.Load("res://Scenes/Food.tscn"); for (int i = 0; i < 20; i++) { Food food = (Food)foodGenerator_.Instance(); this.AddChild(food); this.foods.Add(food); float randomX = (float)GD.RandRange(0, this.width); float randomZ = (float)GD.RandRange(0, this.height); food.Translation = new Vector3(randomX, 0, randomZ); } // create food timer (spawns food periodically) foodTimer_ = new Timer(); this.AddChild(foodTimer_); foodTimer_.WaitTime = 1; foodTimer_.Connect("timeout", this, nameof(OnSpawnFood)); foodTimer_.Start(); // create stat timer (periodically reclaculates stats) statTimer_ = new Timer(); this.AddChild(statTimer_); statTimer_.WaitTime = 1; statTimer_.Connect("timeout", this, nameof(OnCalculateStats)); statTimer_.Start(); // connect gui GUI gui = (GUI)this.GetNode("GUI"); gui.Connect(nameof(GUI.CreateCreatures), this, nameof(OnCreateCreatures)); gui.Connect(nameof(GUI.SetFoodSpawnRate), this, nameof(OnSetFoodSpawnRate)); gui.Connect(nameof(GUI.SetTimeScale), this, nameof(OnSetTimeScale)); gui.Connect(nameof(GUI.SetWorldBounds), this, nameof(OnUpdateBounds)); gui.Connect(nameof(GUI.SetPaintFoodMode), this, nameof(OnSetFoodPaintMode)); gui.Connect(nameof(GUI.SetCreatureCreatureMode), this, nameof(OnSetCreateCreatureMode)); gui.Connect(nameof(GUI.SelectCreature), this, nameof(OnSelectCreaturePressed)); Menu menu = this.GetNode <Menu>(nameof(Menu)); menu.Connect(nameof(Menu.QuitApp), this, nameof(OnGUIQuit)); FoodPainter foodPainter = this.GetNode <FoodPainter>("FoodPainter"); foodPainter.Connect(nameof(FoodPainter.SpawnFood), this, nameof(OnFoodPainterSpawnFood)); CreatureSpawner creatureSpawner = this.GetNode <CreatureSpawner>("CreatureSpawner"); creatureSpawner.Connect(nameof(CreatureSpawner.SpawnCreature), this, nameof(OnCreateSingleCreature)); }
void OnSetFoodPaintMode() { FoodPainter foodPainter = this.GetNode <FoodPainter>("FoodPainter"); foodPainter.On = true; Texture image = GD.Load <Texture>("res://Art/foodCursor.png"); Vector2 imageCenter = new Vector2(image.GetWidth() / 2, image.GetHeight() / 2); Input.SetCustomMouseCursor(image, Input.CursorShape.Arrow, imageCenter); }