Пример #1
0
    private void _SpawnAICars()
    {
        AICar aiCar = (AICar)_aiCarScene.Instance();

        aiCar.Set("Map", _trackTileMap);
        aiCar.Set("Rng", rng);
        aiCar.Position = _GetSpawnLocation(_playerCar.Position, aiCar);
        aiCar.Connect("HitTree", this, nameof(_OnAICarHitTree));

        if (aiCar.Position == Vector2.Zero)
        {
            aiCar.CallDeferred("QueueFree");
            return;
        }
        else
        {
            _aiCars.Add(aiCar);
            aiCar.MaxSpeed = rng.RandfRange(AIMinSpeed, AIMaxSpeed);
            aiCar.Speed    = rng.RandfRange(AIMinSpeed, aiCar.MaxSpeed);
            GetParent().AddChild(aiCar);
            _canSpawn = false;
            _spawnTimer.Start(rng.RandfRange(SpawnTimeMin, SpawnTimeMax));
            _previousSpawnPos = aiCar.Position;
        }
    }
Пример #2
0
 private void _RemoveAICar(AICar aiCar)
 {
     _aiCars.Remove(aiCar);
     aiCar.CallDeferred("QueueFree");
 }