using Godot; using System; public partial class game : Node2D { public Node Lasers = null; public CharacterBody2D Player = null; public Node Asteroids = null; private readonly PackedScene AsteroidScene = GD.Load("res://scenes/asteroid.tscn"); public override void _Ready() { Asteroids = GetNode("Asteroids"); var a = new asteroid(); for (int i = 0; i == Asteroids.GetChildCount() - 1; i++){ a = (asteroid)Asteroids.GetChild(i); a.Exploded += OnAsteroidExploded; } Lasers = GetNode("Lasers"); Player = GetNode("Player"); var p = new player(); p.LaserShot += OnPlayerLaserShot; } public void SpawnAsteroid(Vector2 position, int size) { var a = new asteroid(); a = AsteroidScene.Instantiate(); a.GlobalPosition = position; a.size = (asteroid.AsteroidSize)size; a.Exploded += OnAsteroidExploded; Asteroids.CallDeferred("add_child", a); } //Signals and Connections public void OnPlayerLaserShot(Area2D Laser) { Lasers.AddChild(Laser); GD.Print(Laser.Position); GD.Print(Player.Position); } public void OnAsteroidExploded(Vector2 pos, int size) { GD.Print(size); for(int i = 0; i < 2; i++){ if (size == 0){ SpawnAsteroid(pos, (int)asteroid.AsteroidSize.MEDIUM); } else if (size == 1){ SpawnAsteroid(pos, (int)asteroid.AsteroidSize.SMALL); } } } }