Exemplo n.º 1
0
        private void fillField()
        {
            int i = (int)(((Boundary.Width + Boundary.Height) / 2) / (20 * Density));

            do
            {
                Vector2 asteroidPos      = new Vector2(rand.Next(Boundary.X, Boundary.X + Boundary.Width), rand.Next(Boundary.Y, Boundary.Y + Boundary.Height));
                float   asteroidSpeed    = rand.NextFloat(MinSpeed, MaxSpeed);
                float   asteroidRotation = 0.025f;
                Asteroids.Add(new Asteroid(asteroidPos, asteroidSpeed, asteroidRotation));
            }while (--i > 0);
        }
Exemplo n.º 2
0
        private void GenerateLevel()
        {
            var maxAsteroids = Level * 1.2f;

            Ship.Respawn();
            for (int i = 0; i < maxAsteroids; i++)
            {
                var asteroid = new Asteroid();
                asteroid.GenerateLargeAsteroid(LargeAsteroidTextures, Ship, Random);
                Asteroids.Add(asteroid);
            }
        }
Exemplo n.º 3
0
 private void Model_OnFrameUpdate(object sender, FrameEventArgs e)
 {
     Application.Current?.Dispatcher.Invoke(() =>
     {
         Asteroids.Clear();
         var sec     = e.Seconds % 60;
         var min     = e.Seconds / 60;
         ElapsedTime = min.ToString().PadLeft(2, '0') + ":" + sec.ToString().PadLeft(2, '0');
         foreach (Asteroid asteroid in e.Asteroids)
         {
             Asteroids.Add(asteroid);
         }
         Player = e.Player;
     });
 }
Exemplo n.º 4
0
    private void SpawnAsteroids()
    {
        if (AsteroidCount <= 0)
        {
            return;
        }

        if (m_AsteroidTemplates.Count == 0)
        {
            Debug.LogError("No Asteroid Templates!");
            return;
        }

        var prng = new System.Random();

        for (int i = 0; i < AsteroidCount; i++)
        {
            Vector3 newPosition = Vector3.zero;
            bool    badPosition = true;
            while (badPosition)
            {
                float magnitude = (Random.value * WorldRadius * 0.6f) + WorldRadius * 0.4f;
                newPosition  = Random.onUnitSphere;
                newPosition *= magnitude;

                // Check that the new asteroid is far enough away from other asteroids
                badPosition = false;
                for (int j = 0; j < Asteroids.Count; j++)
                {
                    if (Vector3.Distance(newPosition, Asteroids[j].transform.position) < 20.0f)
                    {
                        badPosition = true;
                        break;
                    }
                }
            }

            int templateIndex = prng.Next(0, AsteroidTemplates.Count - 1);
            var newAsteroid   = Instantiate(AsteroidTemplates[templateIndex], newPosition, Quaternion.identity) as Asteroid;
            newAsteroid.transform.parent = transform;
            Asteroids.Add(newAsteroid);
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Spawns an asteroid and sets up all required values and listeners
    /// </summary>
    public Asteroid SpawnAsteroid(Asteroid prefab)
    {
        var new_asteroid = Instantiate(prefab);

        // Setup lisenters for the asteroid's event
        new_asteroid.EventLaunched += OnAsteroidLaunched;
        new_asteroid.EventReturned += OnAsteroidReturned;
        new_asteroid.EventCollided += OnAsteroidCollided;

        Asteroids.Add(new_asteroid);
        //asteroidQueue.Enqueue(new_asteroid);
        asteroidQueue.AddLast(new_asteroid);

        if (EventAsteroidSpawned != null)
        {
            EventAsteroidSpawned.Invoke(new_asteroid);
        }


        return(new_asteroid);
    }
Exemplo n.º 6
0
        /// <summary>
        /// Спавнит/респавнит астероиды и аптечки
        /// </summary>
        private void Repopulate()
        {
            if (ASTEROIDS_COUNTER <= 0)
            {
                Asteroids.Clear();
                ASTEROIDS_COUNTER = ASTEROIDS_INITIAL_AMOUNT + 3;

                for (int i = 0; i <= ASTEROIDS_COUNTER; i++)
                {
                    int r = rnd.Next(5, 50);
                    Asteroids.Add(new Asteroid(new Point(Width + ASTEROIDS_X_SPAWNPOINT, rnd.Next(0, Height)), new Point(-r / 5, r), new Size(r, r)));
                }
            }


            if (_medKit == null)
            {
                Point p = new Point(40, rnd.Next(100, game.Height - 100));
                _medKit = new MedKit(p, new Point(), new Size(10, 10));
                GameLogger(console, "New medKit spawned at " + p);
            }
        }
Exemplo n.º 7
0
        public StarSystem(UniverseIni universe, Section section, FreelancerData data)
            : base(data)
        {
            if (universe == null)
            {
                throw new ArgumentNullException("universe");
            }
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }
            string file = null;

            foreach (Entry e in section)
            {
                switch (e.Name.ToLowerInvariant())
                {
                case "nickname":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (Nickname != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    Nickname = e[0].ToString();
                    break;

                case "file":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (file != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    file = e[0].ToString();
                    break;

                case "pos":
                    if (e.Count != 2)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (Pos != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    Pos = new Vector2(e[0].ToSingle(), e[1].ToSingle());
                    break;

                case "msg_id_prefix":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (MsgIdPrefix != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    MsgIdPrefix = e[0].ToString();
                    break;

                case "visit":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (Visit != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    Visit = e[0].ToInt32();
                    break;

                case "strid_name":
                    if (e.Count == 0)
                    {
                        break;
                    }
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (IdsName != 0)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    IdsName = e[0].ToInt32();
                    break;

                case "ids_info":
                    if (e.Count == 0)
                    {
                        break;
                    }
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (IdsInfo != 0)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    IdsInfo = e[0].ToInt32();
                    break;

                case "navmapscale":
                    if (e.Count != 1)
                    {
                        throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count);
                    }
                    if (NavMapScale != null)
                    {
                        throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name);
                    }
                    NavMapScale = e[0].ToSingle();
                    break;

                default:
                    throw new Exception("Invalid Entry in " + section.Name + ": " + e.Name);
                }
            }

            if (file == null)               //TODO: MultiUniverse
            {
                FLLog.Warning("Ini", "Unimplemented: Possible MultiUniverse system " + Nickname);
                MultiUniverse = true;
                return;
            }

            foreach (Section s in ParseFile(GameData.Freelancer.DataPath + "universe\\" + file))
            {
                switch (s.Name.ToLowerInvariant())
                {
                case "systeminfo":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "name":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (Name != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            Name = e[0].ToString();
                            break;

                        case "space_color":
                            if (e.Count != 3)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (SpaceColor != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            SpaceColor = new Color4(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f, 1f);
                            break;

                        case "local_faction":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (LocalFaction != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            LocalFaction = e[0].ToString();
                            break;

                        case "rpop_solar_detection":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (RpopSolarDetection != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            RpopSolarDetection = e[0].ToBoolean();
                            break;

                        case "space_farclip":
                            if (SpaceFarClip != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            SpaceFarClip = e[0].ToSingle();
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + section.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "music":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "space":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (MusicSpace != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            MusicSpace = e[0].ToString();
                            break;

                        case "danger":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (MusicDanger != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            MusicDanger = e[0].ToString();
                            break;

                        case "battle":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (MusicBattle != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            MusicBattle = e[0].ToString();
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + section.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "archetype":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "ship":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (ArchetypeShip == null)
                            {
                                ArchetypeShip = new List <string>();
                            }
                            ArchetypeShip.Add(e[0].ToString());
                            break;

                        case "simple":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (ArchetypeSimple == null)
                            {
                                ArchetypeSimple = new List <string>();
                            }
                            ArchetypeSimple.Add(e[0].ToString());
                            break;

                        case "solar":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (ArchetypeSolar == null)
                            {
                                ArchetypeSolar = new List <string>();
                            }
                            ArchetypeSolar.Add(e[0].ToString());
                            break;

                        case "equipment":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (ArchetypeEquipment == null)
                            {
                                ArchetypeEquipment = new List <string>();
                            }
                            ArchetypeEquipment.Add(e[0].ToString());
                            break;

                        case "snd":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (ArchetypeSnd == null)
                            {
                                ArchetypeSnd = new List <string>();
                            }
                            ArchetypeSnd.Add(e[0].ToString());
                            break;

                        case "voice":
                            if (ArchetypeVoice == null)
                            {
                                ArchetypeVoice = new List <List <string> >();
                            }
                            ArchetypeVoice.Add(new List <string>());
                            foreach (IValue i in e)
                            {
                                ArchetypeVoice[ArchetypeVoice.Count - 1].Add(i.ToString());
                            }
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + s.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "dust":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "spacedust":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (Spacedust != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            Spacedust = e[0].ToString();
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + s.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "nebula":
                    if (Nebulae == null)
                    {
                        Nebulae = new List <Nebula>();
                    }
                    Nebulae.Add(new Nebula(this, s, GameData));
                    break;

                case "asteroids":
                    if (Asteroids == null)
                    {
                        Asteroids = new List <AsteroidField>();
                    }
                    Asteroids.Add(new AsteroidField(this, s, GameData));
                    break;

                case "ambient":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "color":
                            if (e.Count != 3)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (AmbientColor != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            AmbientColor = new Color4(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f, 1f);
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + s.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "lightsource":
                    if (LightSources == null)
                    {
                        LightSources = new List <LightSource>();
                    }
                    LightSources.Add(new LightSource(s, GameData));
                    break;

                case "object":
                    if (Objects == null)
                    {
                        Objects = new List <SystemObject>();
                    }
                    Objects.Add(new SystemObject(universe, this, s, GameData));
                    break;

                case "encounterparameters":
                    if (EncounterParameters == null)
                    {
                        EncounterParameters = new List <EncounterParameter>();
                    }
                    EncounterParameters.Add(new EncounterParameter(s));
                    break;

                case "texturepanels":
                    TexturePanels = new TexturePanelsRef(s, GameData);
                    break;

                case "background":
                    foreach (Entry e in s)
                    {
                        switch (e.Name.ToLowerInvariant())
                        {
                        case "basic_stars":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (BackgroundBasicStarsPath != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            BackgroundBasicStarsPath = VFS.GetPath(GameData.Freelancer.DataPath + e [0].ToString());
                            break;

                        case "complex_stars":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            if (BackgroundComplexStarsPath != null)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            BackgroundComplexStarsPath = VFS.GetPath(GameData.Freelancer.DataPath + e [0].ToString());
                            break;

                        case "nebulae":
                            if (e.Count != 1)
                            {
                                throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count);
                            }
                            string temp = VFS.GetPath(GameData.Freelancer.DataPath + e[0].ToString(), false);
                            if (BackgroundNebulaePath != null && BackgroundNebulaePath != temp)
                            {
                                throw new Exception("Duplicate " + e.Name + " Entry in " + s.Name);
                            }
                            BackgroundNebulaePath = temp;
                            break;

                        default:
                            throw new Exception("Invalid Entry in " + s.Name + ": " + e.Name);
                        }
                    }
                    break;

                case "zone":
                    if (Zones == null)
                    {
                        Zones = new List <Zone>();
                    }
                    Zones.Add(new Zone(s, GameData));
                    break;

                case "field":
                    Field = new Field(s);
                    break;

                case "asteroidbillboards":
                    AsteroidBillboards = new AsteroidBillboards(s);
                    break;

                default:
                    throw new Exception("Invalid Section in " + file + ": " + s.Name);
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Adds a new <see cref="Asteroid"/> to <see cref="Asteroids"/> and
 /// updates <see cref="Belt"/>.
 /// </summary>
 public void AddAsteroid(Asteroid asteroid)
 {
     Asteroids.Add(new CachedObject <Asteroid>(asteroid));
     Belt.SetAsteroids(Asteroids.Select(c => c.ScreenObject).ToList());
 }