Inheritance: Orbiteer
Exemplo n.º 1
0
        public new void Start()
        {
            _ship = new Ship(GameRef.Game.Content.Load<Texture2D>("ship"), GameRef.Game.Content.Load<Texture2D>("bullet"), this);
            AddEntity(_ship);

            _enemyship = new EnemyShip(GameRef.Game.Content.Load<Texture2D>("enemyship"), GameRef.Game.Content.Load<Texture2D>("bullet"), this);
            AddEntity(_enemyship);

            _ship.Collision.AddPartner(_enemyship);
            _enemyship.Collision.AddPartner(_ship);

            for (var i = 0; i < 10; i++)
            {
                var a = new Asteroid(GameRef.Game.Content.Load<Texture2D>("asteroid"), this);

                while (a.Collision.TestCollision(_ship))
                {
                    a = new Asteroid(GameRef.Game.Content.Load<Texture2D>("asteroid"), this);
                }
                _ship.Collision.AddPartner(a);
                a.Collision.AddPartner(_ship);

                AddEntity(a);
            }

            _font = GameRef.Game.Content.Load<SpriteFont>("font");
        }
Exemplo n.º 2
0
    public void destroyAsteroid(Asteroid asteroid)
    {
        //Update player score
        if (asteroid.smallerRock != null) {
            GameObject rock1 = (GameObject) GameObject.Instantiate(asteroid.smallerRock, asteroid.transform.position, asteroid.transform.rotation);
            GameObject rock2 = (GameObject) GameObject.Instantiate(asteroid.smallerRock, asteroid.transform.position, Quaternion.Inverse(asteroid.transform.rotation));

            rock1.GetComponent<Rigidbody>().velocity = asteroid.GetComponent<Rigidbody>().velocity;
            rock2.GetComponent<Rigidbody>().velocity = asteroid.GetComponent<Rigidbody>().velocity;

            rock1.transform.parent = transform;
            rock2.transform.parent = transform;

            ((Asteroid)rock1.GetComponent("Asteroid")).setAsteroidField(this);
            ((Asteroid)rock2.GetComponent("Asteroid")).setAsteroidField(this);

            numAsteroids += 2;
        }

        GameObject explosion = (GameObject) GameObject.Instantiate(asteroid.asteroidExplosion, asteroid.transform.position, asteroid.transform.rotation);
        explosion.transform.parent = asteroid.transform;
        asteroid.GetComponent<Renderer>().enabled = false;
        asteroid.GetComponent<Collider>().enabled = false;
        asteroid.Invoke("kill", 2.0f);

        score += asteroid.scorePoints;
        numAsteroids--;

        updateGUI();
    }
Exemplo n.º 3
0
		public void CheckBorderCollisionRight()
		{
			var asteroid = new Asteroid(new InteractionLogic());
			asteroid.Get<SimplePhysics.Data>().Velocity = new Vector2D(0.1f,0.0f);
			asteroid.Center = new Vector2D(1.5f,0.5f);
			AdvanceTimeAndUpdateEntities();
			Assert.IsTrue(asteroid.Center.X < 0.0f);
		}
Exemplo n.º 4
0
		public void CheckBorderCollisionBottom()
		{
			var asteroid = new Asteroid(new InteractionLogic());
			asteroid.Get<SimplePhysics.Data>().Velocity = new Vector2D(0.0f, 0.1f);
			asteroid.Center = new Vector2D(0.5f, 1.5f);
			AdvanceTimeAndUpdateEntities();
			Assert.IsTrue(asteroid.Center.Y < ScreenSpace.Current.Viewport.Top);
		}
Exemplo n.º 5
0
        public void Update(Asteroid asteroid)
        {
            _topLeft += _velocity;

            if(asteroid.Hitbox.Contains(new Point((int)_topLeft.X,(int)_topLeft.Y)))
            {
                asteroid.Destroy();
            }
        }
Exemplo n.º 6
0
		public void ShowAsteroidsOfSeveralSizemodsAndFracture()
		{
			var gameLogic = new InteractionLogic();
			var largeAsteroid = new Asteroid(gameLogic);
			new Asteroid(gameLogic, 2);
			new Asteroid(gameLogic, 3);
			largeAsteroid.Fracture();
			Assert.IsFalse(largeAsteroid.IsActive);
		}
Exemplo n.º 7
0
 public AsteroidManager(
     Settings settings, Asteroid.Factory asteroidFactory, LevelHelper level)
 {
     _settings = settings;
     _timeIntervalBetweenSpawns = _settings.maxSpawnTime / (_settings.maxSpawns - _settings.startingSpawns);
     _timeToNextSpawn = _timeIntervalBetweenSpawns;
     _asteroidFactory = asteroidFactory;
     _level = level;
 }
Exemplo n.º 8
0
    private static void CreateAsteroid()
    {
        int x = numberGenerator.Next(Console.WindowWidth);
        int charIndex = numberGenerator.Next(asteroidChars.Length);

        // the enumeration ConsoleColor contains 16 colors, of which the first (black) is not used
        int color = numberGenerator.Next(1, 16);

        Asteroid asteroid = new Asteroid(new Point(x, 0), asteroidChars[charIndex], (ConsoleColor)color);
        asteroids.Add(asteroid);
    }
Exemplo n.º 9
0
        public AsteroidBelt(
            Simulator simulator,
            string name,
            Vector3 basePosition,
            Size size,
            float speed,
            List<string> images,
            int startingPourcentage)
            : base(
                simulator,
                name,
                basePosition,
                Vector3.Zero,
                0,
                size,
                speed,
                null,
                startingPourcentage,
                Preferences.PrioriteSimulationCeintureAsteroides,
                false)
        {
            List<Image> representations = new List<Image>();

            foreach (var image in images)
                representations.Add(new Image(image));

            if (representations.Count == 0)
                representations.Add(new Image("Asteroid"));

            Asteroids = new List<Asteroid>(NbAsteroids);


            for (int i = 0; i < NbAsteroids; i++)
            {
                Asteroid asteroid = new Asteroid()
                {
                    Image = representations[Main.Random.Next(0, representations.Count)].Clone(),
                    TimeOffset = Main.Random.Next((int)(-speed/2), (int)(speed/2)),
                    Offset = new Vector3(Main.Random.Next(-50,50),Main.Random.Next(-50,50 ),0),
                    RotationSpeed = Main.Random.Next(-100, 100) / 10000.0f,
                    MovingSpeed = Main.Random.Next(1, 10)
                };

                asteroid.Image.VisualPriority = Preferences.PrioriteSimulationCeintureAsteroides;
                asteroid.Image.Alpha = 60;
                asteroid.Image.SizeX = (Main.Random.Next(20, 70) / 30.0f) * 3;

                CelestialBody.Move(Speed, (ActualRotationTime + asteroid.TimeOffset) % Speed, ref Path, ref asteroid.Offset, ref RotationMatrix, ref asteroid.Image.position);

                Asteroids.Add(asteroid);
            }
        }
Exemplo n.º 10
0
 public static void DrawHandle( Asteroid a)
 {
     switch (a.popMethod){
     case Asteroid.PopMethod.Sphere:
         Handles.color=Color.green;
         Handles.DrawWireDisc( a.transform.position,Vector3.up  , a.minRadius);
         Handles.DrawWireDisc( a.transform.position,Vector3.left  , a.minRadius);
         Handles.color=Color.red;
         Handles.DrawWireDisc( a.transform.position,Vector3.up  , a.maxRadius);
         Handles.DrawWireDisc( a.transform.position,Vector3.left  , a.maxRadius);
         break;
     }
 }
Exemplo n.º 11
0
        private void CreateAsteroids()
        {
            Random random = new Random();

            for (int i = 0; i < AsteroidCount; i++)
            {
                Asteroid asteroid = new Asteroid();
                asteroid.Init();
                float x = (float)(random.Next(-10, 10) + 1.0f) / 3.0f;
                float y = (float)(random.Next(0, 20) + 1.0f) / 3.0f;
                float z = (float)(random.Next(-20, 20) + 1.0f) / 3.0f;
                asteroid.SetPosition(x, y, z);
                asteroids.Add(asteroid);
            }
        }
Exemplo n.º 12
0
    public void AsteroidHit(Asteroid _hit)
    {
        List<Asteroid> temp = new List<Asteroid>();
        foreach (Asteroid asteroid in m_Asteroids)
        {
            if (asteroid.GetInstanceID() == _hit.GetInstanceID())
            {
                if (asteroid.m_Splits < 2)
                {
                    Asteroid ast = Instantiate(m_AsteroidPrefab) as Asteroid;
                    float rotation = Random.Range(0.0f, 360.0f);
                    Transform trans = this.gameObject.transform;
                    trans.Rotate(new Vector3(0.0f, 0.0f, 1.0f), rotation);
                    Vector3 pos = asteroid.transform.position;
                    ast.Spawn(Random.Range(-1.0f, 1.0f), pos, Quaternion.AngleAxis(45, Vector3.Cross(asteroid.Velocity, Vector3.up)) * asteroid.Velocity, asteroid.m_Splits + 1, this);
                    temp.Add(ast);

                    ast = Instantiate(m_AsteroidPrefab) as Asteroid;
                    rotation = Random.Range(0.0f, 360.0f);
                    trans = this.gameObject.transform;
                    trans.Rotate(new Vector3(0.0f, 0.0f, 1.0f), rotation);
                    pos = asteroid.transform.position;
                    ast.Spawn(Random.Range(-1.0f, 1.0f), pos, Quaternion.AngleAxis(45, Vector3.Cross(asteroid.Velocity, -Vector3.up)) * asteroid.Velocity, asteroid.m_Splits + 1, this);
                    temp.Add(ast);
                }
                if (asteroid.m_Splits == 0)
                {
                    m_PC.AddScore(20);
                }
                else if (asteroid.m_Splits == 1)
                {
                    m_PC.AddScore(50);
                }
                else
                {
                    m_PC.AddScore(100);
                }

                Destroy(asteroid.gameObject);
            }
            else
            {
                temp.Add(asteroid);
            }
        }
        m_Asteroids = temp;
    }
Exemplo n.º 13
0
    void Spawn()
    {
        //Spawns a number of asteroids (i)
        for (int i = 0; i < amount; i++)
        {
            GameObject newAsteroid = (GameObject)Instantiate(asteroid, RandomPos(), Quaternion.identity);
            asteroidList.Add(newAsteroid);
        }

        //Set the velocity for each asteroid in the asteroids array
        foreach (GameObject ast in asteroidList)
        {
            asteroidScript = ast.GetComponent<Asteroid>();
            asteroidScript.Velocity = RandomVel();
            asteroidScript.Size = 1;
        }
    }
Exemplo n.º 14
0
    public static void AsteroidProperties(Asteroid a)
    {
        #region Header
        EditorGUILayout.BeginHorizontal();
        Color crossColor = Color.red;

        int width = Screen.width-90;
        if (a.isWaitToDelte){
            crossColor= Color.white;
            width =  Screen.width-134;
        }

        // Delete
        if (GuiTools.Button("X",crossColor,19)){
            a.isWaitToDelte = !a.isWaitToDelte;
        }
        if (a.isWaitToDelte){
            if (GuiTools.Button("Delete",Color.red,50)){
                DestroyImmediate( a.gameObject );
                return;
            }
        }

        bool showProperties = GuiTools.ChildFoldOut( a.inspectorShowProperties,"Asteroid " + a.popMethod.ToString(),new Color(183f/255f,230f/255f,252f/255f),width);
        if (showProperties !=a.inspectorShowProperties){
            a.inspectorShowProperties = showProperties;
            if (showProperties){
                SelectAsteroid( a);
            }
        }

        GUI.backgroundColor = Color.green;
        if (GUILayout.Button (new GUIContent("S"),GUILayout.Width(19))){
            SelectAsteroid(a);
        }
        GUI.backgroundColor = Color.white;
        EditorGUILayout.EndHorizontal();
        #endregion

        if (a.inspectorShowProperties){
            EditorGUI.indentLevel++;
            AsteroidInspector.Inspector( a );
            EditorGUI.indentLevel--;
        }
    }
Exemplo n.º 15
0
	// Update is called once per frame
	void Update () 
	{
		//This makes sure asteroids don't spawn all the time.
		if (coolDown > 0) 
		{
			coolDown -= Time.deltaTime;
		}

		//This spawns asteroids and makes them fly toward the center
		//TODO: Make them disappear when they strike earth.
		//TODO: Separate asteroids and enemies so that inheritance is easier later
		if (coolDown <= 0) {
			coolDown = COOL_DOWN;
			int y = Random.Range(5, 8);
			int x = Random.Range(0, 7+y);
			Vector3 pos = new Vector3((x-3.0f-0.5f*y)*0.5f, (y+6.0f)*0.5f, 0);
			GameObject enemy = (GameObject) Instantiate(asteroidPrefab, pos, Quaternion.identity);
			enemy.transform.parent = transform;
			asteroidScript = (Asteroid) enemy.GetComponent("Asteroid");
			asteroidScript.setVelocity(new Vector2(-1*enemy.transform.position.x/2, -1*enemy.transform.position.y/2));
		}

	}
Exemplo n.º 16
0
        public override void LoadContent()
        {
            if (Content == null)
            {
                Content = new ContentManager(ScreenManager.Game.Services, "Content");
            }

            #region loaded content

            myModel    = Content.Load <Model>("Model\\fighter");
            Asteroid1  = Content.Load <Model>("Model\\Asteroid1");
            Asteroid2  = Content.Load <Model>("Model\\Asteroid2");
            Asteroid3  = Content.Load <Model>("Model\\Asteroid3");
            ammo       = Content.Load <Model>("Model\\ammo");
            globeModel = Content.Load <Model>("Model\\globe");

            Explosion = Content.Load <SoundEffect>("Audio\\explosion3");

            dataScreen   = Content.Load <Texture2D>("Images\\DataScreen");
            BackGround   = Content.Load <Texture2D>("Images\\background");
            panel        = Content.Load <Texture2D>("Images\\panel");
            hypButton    = Content.Load <Texture2D>("Images\\p1hyp");
            hypButtonClk = Content.Load <Texture2D>("Images\\p1hypclk");

            Engine     = Content.Load <SoundEffect>("Audio\\engine_3");
            WeaponFire = Content.Load <SoundEffect>("Audio\\pdp1_fire");

            defaultFont = Content.Load <SpriteFont>("Fonts\\defaultFont");
            HyperSpace  = Content.Load <SoundEffect>("Audio\\hax2_fire_alt");

            play = new Player(myModel, Initial, 0.0f, 3);
            Projectile bullet = new Projectile(ammo, Initial, 0.0f, Initial, false, Initial);
            BulletList    = new Projectile[noBullets];
            GlobePosition = new Vector3(-2500, -1500, 1050);

            #endregion

            #region Graphic Device and screen elements
            screenWidth  = ScreenManager.GraphicsDevice.PresentationParameters.BackBufferWidth;
            screenHeight = ScreenManager.GraphicsDevice.PresentationParameters.BackBufferHeight;

            aspectRatio = ScreenManager.GraphicsDevice.Viewport.AspectRatio;
            #endregion

            #region initialise Asteroids
            AP1.X = -2000;
            AP1.Y = screenHeight;

            AP2.X = -screenWidth;
            AP2.Y = -2000;

            AP3.X = -300;
            AP3.Y = -900;

            AP4.X = -300;
            AP4.Y = -400;

            asteroid1List[0] = new Asteroid(Asteroid1, AP1, 0.005f, true, 5);
            asteroid1List[1] = new Asteroid(Asteroid1, AP2, 0.5f, true, 5);

            asteroid3List[0] = new Asteroid(Asteroid3, AP3, 1.005f, true, 1);
            asteroid3List[1] = new Asteroid(Asteroid3, AP4, 2.005f, true, 1);

            for (int i = 0; i < NumAsteroid2; i++)
            {
                asteroid2List[i] = new Asteroid(Asteroid2, new Vector3(8000, 8000, 0), 0.005f, false, 3);
            }

            for (int i = 2; i < NumAsteroid3; i++)
            {
                asteroid3List[i] = new Asteroid(Asteroid3, new Vector3(8000, 8000, 0), 0.005f, false, 1);
            }


            #endregion

            #region initialise bullet list
            for (int i = 0; i < noBullets; i++)
            {
                BulletList[i] = new Projectile(ammo, new Vector3(5000, 5000, 0), 0.0f, Initial, false, Initial);
            }
            #endregion
        }
Exemplo n.º 17
0
 void showAsteriodTarget(Asteroid Aster)
 {
     Aster.GetComponent <Asteroid>().showTarget();
     //distance = Vector3.Distance (transform.position, Aster.position);
 }
Exemplo n.º 18
0
 private void Start()
 {
     myAsteroid            = gameObject.GetComponent <Asteroid>();
     myAsteroidChargeGauge = myAsteroid.chargeGauge;
 }
Exemplo n.º 19
0
        public void SetupRocks()
        {
            var rnd       = StrategyGame.Random;
            var settings  = _game.GameSettings;
            var asteroids = new List <Asteroid>();
            var centerPos = new Point(StrategyGame.ScreenWidth / 2, StrategyGame.ScreenHeight / 2);

            foreach (var sector in Sectors)
            {
                var rockSize = 60;
                var radiusX  = 400;
                var radiusY  = 300;
                // Rocks
                for (var i = 0; i < settings.RocksPerSectorGeneral; i++)
                {
                    var a = new Asteroid(_game, rnd, rockSize, rockSize, sector.Id);
                    a.CenterX = rnd.Next(centerPos.X - radiusX, centerPos.X + radiusX);
                    a.CenterY = rnd.Next(centerPos.Y - radiusY, centerPos.Y + radiusY);
                    for (var t = 0; t < _game.NumTeams; t++)
                    {
                        a.SetVisibleToTeam(t, settings.RocksVisible);
                    }
                    asteroids.Add(a);
                    _game.BuildableAsteroids.Add(a);
                }

                // Tech
                rockSize = 70;
                radiusX  = 200;
                radiusY  = 100;
                List <Asteroid> rockOptions = new List <Asteroid>();
                for (var i = 0; i < settings.RocksPerSectorTech; i++)
                {
                    if (rockOptions.Count == 0)
                    {
                        rockOptions.Add(new TechCarbonAsteroid(_game, rnd, rockSize, rockSize, sector.Id));
                        rockOptions.Add(new TechSiliconAsteroid(_game, rnd, rockSize, rockSize, sector.Id));
                        rockOptions.Add(new TechUraniumAsteroid(_game, rnd, rockSize, rockSize, sector.Id));
                    }
                    var a = rockOptions[rnd.Next(0, rockOptions.Count)];

                    a.CenterX = rnd.Next(centerPos.X - radiusX, centerPos.X + radiusX);
                    a.CenterY = rnd.Next(centerPos.Y - radiusY, centerPos.Y + radiusY);
                    asteroids.Add(a);
                    for (var t = 0; t < _game.NumTeams; t++)
                    {
                        a.SetVisibleToTeam(t, settings.RocksVisible);
                    }
                    _game.BuildableAsteroids.Add(a);
                    rockOptions.Remove(a);
                }

                // Resources
                rockSize = 40;
                radiusX  = 300;
                radiusY  = 200;
                for (var i = 0; i < settings.RocksPerSectorResource; i++)
                {
                    var a = new ResourceAsteroid(_game, rnd, rockSize, rockSize, sector.Id);
                    a.CenterX = rnd.Next(centerPos.X - radiusX, centerPos.X + radiusX);
                    a.CenterY = rnd.Next(centerPos.Y - radiusY, centerPos.Y + radiusY);
                    for (var t = 0; t < _game.NumTeams; t++)
                    {
                        a.SetVisibleToTeam(t, settings.RocksVisible);
                    }
                    _game.ResourceAsteroids.Add(a);
                    asteroids.Add(a);
                }
            }
            _game.AllAsteroids.AddRange(asteroids);
        }
Exemplo n.º 20
0
 public void StartMining(Asteroid Target)
 {
     this.Target = Target;
     CurrentState = State.Enabled;
 }
Exemplo n.º 21
0
 public void AsteroidSpawned(Asteroid asteroid)
 {
     asteroids.Add(asteroid);
 }
Exemplo n.º 22
0
 private void Update()
 {
     if (!End)
     {
         absorbTime = Mathf.Max(absorbTime - Time.deltaTime, 0.0f);
         bool hasShieldActif = false;
         for (int j = 0; j < shields.Count; j++)
         {
             if (shields[j].HasShield)
             {
                 hasShieldActif = true;
                 break;
             }
         }
         Shield.SetActive(hasShieldActif);
         Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, (scale + 1.0f * absorbTime), layer.value);
         for (int i = 0; i < colliders.Length; i++)
         {
             int dmg = 1;
             if (colliders[i].gameObject == this.gameObject)
             {
                 continue;
             }
             Planete pl = colliders[i].gameObject.GetComponent <Planete>();
             if (pl)
             {
                 bool isPinky = colliders[i].gameObject.GetComponent <Pinky>() != null;
                 if (isPinky)
                 {
                     GameManager.Instance.SpawnPlanete();
                 }
                 pl.Dead(true);
             }
             Asteroid at = colliders[i].gameObject.GetComponent <Asteroid>();
             if (at)
             {
                 GameManager.Instance.AddScore(-at.maxLife);
                 if (at.Big)
                 {
                     dmg++;
                 }
             }
             Destroy(colliders[i].gameObject);
             if (hasShieldActif)
             {
                 for (int j = 0; j < shields.Count; j++)
                 {
                     if (shields[j].HasShield)
                     {
                         shields[j].UseShield();
                         dmg--;
                         if (dmg <= 0)
                         {
                             break;
                         }
                     }
                 }
             }
             if (dmg > 0)
             {
                 absorbTime += dmg;
                 scale      += dmg;
                 if (scale >= 20)
                 {
                     WarningUI.SetActive(true);
                     if (AudioCritique.isPlaying == false)
                     {
                         AudioCritique.Play();
                     }
                     float pct = (scale - 20.0f) / 10.0f;
                     AudioCritique.pitch = 1 + pct * 0.5f;
                 }
                 End = scale >= 30.0f;
                 if (End)
                 {
                     timer = Time.time;
                     AudioCritique.Stop();
                 }
             }
         }
         transform.localScale = Vector3.one * (scale + 1.0f * absorbTime);
         UpdateAnimation();
     }
     else
     {
         float pct = Time.time - timer;
         scale = endCurve.Evaluate(pct > 1.5f ? 1.5f : pct) * 1.5f;
         transform.localScale = Vector3.one * scale;
         Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, scale, layer.value);
         for (int i = 0; i < colliders.Length; i++)
         {
             if (colliders[i].gameObject == this.gameObject)
             {
                 continue;
             }
             Destroy(colliders[i].gameObject);
         }
         if (pct >= 0.5f && AudioEnd.isPlaying == false && PanelEnd.Instance.IsVisible == false)
         {
             AudioEnd.Play();
         }
         float pc = (pct - 1.5f) / 0.5f;
         pc = Mathf.Clamp01(pc);
         GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f - pc);
         if (pct > 2.0f)
         {
             if (PanelEnd.Instance.IsVisible == false)
             {
                 GameSettings.AddScore();
                 PanelEnd.Instance.Show();
             }
         }
     }
 }
Exemplo n.º 23
0
    /// <summary>
    /// Sets up the asteroids of a given size 
    /// </summary>
    /// <param name="asteroidType">The prefab type to set up</param>
    /// <param name="count">The number of asteroids to set up for this type</param>
    private void InitializeAsteroidGroup(Asteroid.ASTEROID_TYPE asteroidType, int count)
    {
        for (int i=0; i<count; i++)
        {
            // activate a SwarmItem from the manager
            Asteroid asteroid = (Asteroid)ActivateItem((int)asteroidType);

            if (asteroid != null)
            {
                // set asteroid with random spin, velocity, and position
                asteroid.Set(this, asteroidType, GetRandomSpin(), GetRandomVelocity(), GetRandomPosition());
            }
        }
    }
Exemplo n.º 24
0
 void Start()
 {
     asteroid = GameObject.Find("Asteroid").GetComponent <Asteroid>();
     InvokeRepeating("Mine", 0, speed);
 }
Exemplo n.º 25
0
        /// <summary>
        /// Executes behavior with given context
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public override BehaviorReturnCode Behave(IBehaviorContext context)
        {
            UnitBehaviorContext unitContext = context as UnitBehaviorContext;

            if (unitContext == null)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            BaseEnvironment envi = unitContext.Unit.Environment;

            if (envi == null)
            {
                returnCode = BehaviorReturnCode.Failure;
                return(returnCode);
            }

            unitContext.EnvironmentTarget = null;
            float    maxInfluence = float.MinValue;
            Asteroid bestAsteroid = null;

            foreach (var body in envi.EnvironmentMap.Values)
            {
                Asteroid asteroid = body as Asteroid;
                if (asteroid == null)
                {
                    continue;
                }

                if (EnableUnscannedCheck && unitContext.Unit.Owner.ScannedStarSystemBodies.Contains(asteroid.GlobalKey))
                {
                    continue;
                }

                if (EnableIsExtractedCheck && asteroid.IsExtracted)
                {
                    continue;
                }

                HexElement infElem;
                if (!envi.EnvironmentInfluenceMap.TryGetValue(asteroid.HexMapKey, out infElem))
                {
                    continue;
                }

                float            asteroidInfluence = 0;
                InfluenceElement influence         = infElem as InfluenceElement;
                if (influence != null)
                {
                    asteroidInfluence = influence.Value;
                }
                else
                {
                    MultiLayerElement layer = infElem as MultiLayerElement;
                    if (layer == null)
                    {
                        continue;
                    }

                    asteroidInfluence = layer.Values.Sum(i => ((InfluenceElement)i).Value);
                }

                if (asteroidInfluence > maxInfluence)
                {
                    maxInfluence = asteroidInfluence;
                    bestAsteroid = asteroid;
                }
            }

            unitContext.EnvironmentTarget = bestAsteroid;
            if (bestAsteroid != null)
            {
                returnCode = BehaviorReturnCode.Success;
                return(returnCode);
            }

            returnCode = BehaviorReturnCode.Failure;
            return(returnCode);
        }
Exemplo n.º 26
0
	public void AddAsteroid(Asteroid asteroid) {
		while (true) {
			if (asteroids.ContainsKey (asteroidIndex)) {
				asteroidIndex--;
			} else {
				break;
			}
		}

		asteroid.id = asteroidIndex;
		asteroids.Add (asteroidIndex--, asteroid);
		asteroid.gameObject.SetActive(true);

		FlagAsteroid(asteroid);
	}
Exemplo n.º 27
0
        protected override void SolvePartTwo()
        {
            Asteroid twohundredthAsteroid = bestAVSet.NthAsteroidHitByLaser(199);

            resultPartTwo = (twohundredthAsteroid.X * 100 + twohundredthAsteroid.InvertedY).ToString();
        }
Exemplo n.º 28
0
 static void CollideWithImpl(Spaceship x, Asteroid y)
 {
     Console.WriteLine("Spaceship collides with Asteroid");
 }
Exemplo n.º 29
0
            // Generates the system prefab from the configuration
            void IParserEventSubscriber.PostApply(ConfigNode node)
            {
                // Dictionary of bodies generated
                Dictionary <string, Body> bodies = new Dictionary <string, Body>();

                // Load all of the bodies
                foreach (ConfigNode bodyNode in node.GetNodes(bodyNodeName))
                {
                    // Create a logger for this body
                    Logger bodyLogger = new Logger(bodyNode.GetValue("name") + ".Body");
                    bodyLogger.SetAsActive();

                    // Attempt to create the body
                    try
                    {
                        currentBody = new Body();
                        Parser.LoadObjectFromConfigurationNode(currentBody, bodyNode);
                        bodies.Add(currentBody.name, currentBody);
                        Logger.Default.Log("[Kopernicus]: Configuration.Loader: Loaded Body: " + currentBody.name);
                    }
                    catch (Exception e)
                    {
                        bodyLogger.LogException(e);
                        Logger.Default.Log("[Kopernicus]: Configuration.Loader: Failed to load Body: " + bodyNode.GetValue("name"));
                    }

                    // Restore default logger
                    bodyLogger.Flush();
                    Logger.Default.SetAsActive();
                }

                // Load all of the asteroids
                foreach (ConfigNode asteroidNode in node.GetNodes(asteroidNodeName))
                {
                    // Create a logger for this asteroid
                    Logger logger = new Logger(asteroidNode.GetValue("name") + ".Asteroid");
                    logger.SetAsActive();

                    // Attempt to create the Asteroid
                    try
                    {
                        Asteroid asteroid = Parser.CreateObjectFromConfigNode <Asteroid>(asteroidNode);
                        DiscoverableObjects.asteroids.Add(asteroid);
                        Logger.Default.Log("[Kopernicus]: Configuration.Loader: Loaded Asteroid: " + asteroid.name);
                    }
                    catch (Exception e)
                    {
                        logger.LogException(e);
                        Logger.Default.Log("[Kopernicus]: Configuration.Loader: Failed to load Asteroid: " + asteroidNode.GetValue("name"));
                    }

                    // Restore default logger
                    logger.Flush();
                    Logger.Default.SetAsActive();
                }

                // Glue all the orbits together in the defined pattern
                foreach (KeyValuePair <string, Body> body in bodies)
                {
                    // If this body is in orbit around another body
                    if (body.Value.orbit != null)
                    {
                        // Get the Body object for the reference body
                        Body parent = null;
                        if (!bodies.TryGetValue(body.Value.orbit.referenceBody, out parent))
                        {
                            throw new Exception("\"" + body.Value.orbit.referenceBody + "\" not found.");
                        }

                        // Setup the orbit of the body
                        parent.generatedBody.children.Add(body.Value.generatedBody);
                        body.Value.generatedBody.orbitDriver.referenceBody       = parent.generatedBody.celestialBody;
                        body.Value.generatedBody.orbitDriver.orbit.referenceBody = parent.generatedBody.celestialBody;
                    }

                    // Parent the generated body to the PSystem
                    body.Value.generatedBody.transform.parent = systemPrefab.transform;
                }

                // Elect root body
                systemPrefab.rootBody = bodies.First(p => p.Value.orbit == null).Value.generatedBody;

                // Sort by distance from parent (discover how this effects local bodies)
                RecursivelySortBodies(systemPrefab.rootBody);

                // Fix doubled flightGlobals
                List <int> numbers = new List <int>()
                {
                    0
                };
                int index = bodies.Sum(b => b.Value.generatedBody.flightGlobalsIndex);

                PatchFGI(ref numbers, ref index, systemPrefab.rootBody);
            }
Exemplo n.º 30
0
 public void RemoveAsteroidFromObjectList(Asteroid asteroid)
 {
     asteroids.Remove(asteroid);
 }
    private Asteroid CreateAsteroidGameObject(RawAsteroid rawAsteroid, Transform parent)
    {
        Asteroid asteroidPrefab = AppManager.DebugSprites ? debugAsteroidPrefab : this.asteroidPrefab;

        return(asteroidPrefab.CreateInstance(parent, rawAsteroid));
    }
Exemplo n.º 32
0
    public void AddObject(Asteroid asteroid, int type)
    {
        List <Vector3> vertices = new List <Vector3>();

        switch (type)
        {
        case 1:
        {
            Vector3 p1  = new Vector3(-0.5f, -1.0f, 0.0f);
            Vector3 p2  = new Vector3(-1.0f, -0.5f, 0.0f);
            Vector3 p3  = new Vector3(-1.0f, 0.5f, 0.0f);
            Vector3 p4  = new Vector3(-0.5f, 1.0f, 0.0f);
            Vector3 p5  = new Vector3(0.0f, 0.5f, 0.0f);
            Vector3 p6  = new Vector3(0.5f, 1.0f, 0.0f);
            Vector3 p7  = new Vector3(1.0f, 0.75f, 0.0f);
            Vector3 p8  = new Vector3(0.75f, 0.1f, 0.0f);
            Vector3 p9  = new Vector3(1.0f, -0.5f, 0.0f);
            Vector3 p10 = new Vector3(0.5f, -1.0f, 0.0f);


            vertices.Add(p1);
            vertices.Add(p2);
            vertices.Add(p3);
            vertices.Add(p4);
            vertices.Add(p5);
            vertices.Add(p6);
            vertices.Add(p7);
            vertices.Add(p8);
            vertices.Add(p9);
            vertices.Add(p10);
        }
        break;

        case 2:
        {
            Vector3 p1  = new Vector3(-0.5f, -1.0f, 0.0f);
            Vector3 p2  = new Vector3(-1.0f, -0.5f, 0.0f);
            Vector3 p3  = new Vector3(-0.75f, 0.0f, 0.0f);
            Vector3 p4  = new Vector3(-1.0f, 0.5f, 0.0f);
            Vector3 p5  = new Vector3(-0.5f, 1.0f, 0.0f);
            Vector3 p6  = new Vector3(0.0f, 0.75f, 0.0f);
            Vector3 p7  = new Vector3(0.5f, 1.0f, 0.0f);
            Vector3 p8  = new Vector3(1.0f, 0.5f, 0.0f);
            Vector3 p9  = new Vector3(0.5f, 0.25f, 0.0f);
            Vector3 p10 = new Vector3(1.0f, -0.25f, 0.0f);
            Vector3 p11 = new Vector3(0.5f, -1.0f, 0.0f);
            Vector3 p12 = new Vector3(-0.25f, -0.75f, 0.0f);

            vertices.Add(p1);
            vertices.Add(p2);
            vertices.Add(p3);
            vertices.Add(p4);
            vertices.Add(p5);
            vertices.Add(p6);
            vertices.Add(p7);
            vertices.Add(p8);
            vertices.Add(p9);
            vertices.Add(p10);
            vertices.Add(p11);
            vertices.Add(p12);
        }
        break;

        case 3:
        {
            Vector3 p1  = new Vector3(-0.5f, -1.0f, 0.0f);
            Vector3 p2  = new Vector3(-1.0f, -0.25f, 0.0f);
            Vector3 p3  = new Vector3(-0.5f, 0.0f, 0.0f);
            Vector3 p4  = new Vector3(-1.0f, 0.25f, 0.0f);
            Vector3 p5  = new Vector3(-0.5f, 1.0f, 0.0f);
            Vector3 p6  = new Vector3(0.5f, 1.0f, 0.0f);
            Vector3 p7  = new Vector3(1.0f, 0.25f, 0.0f);
            Vector3 p8  = new Vector3(0.5f, -1.0f, 0.0f);
            Vector3 p9  = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 p10 = new Vector3(0.0f, -0.25f, 0.0f);

            vertices.Add(p1);
            vertices.Add(p2);
            vertices.Add(p3);
            vertices.Add(p4);
            vertices.Add(p5);
            vertices.Add(p6);
            vertices.Add(p7);
            vertices.Add(p8);
            vertices.Add(p9);
            vertices.Add(p10);
        }
        break;

        case 4:
        {
            Vector3 p1  = new Vector3(-0.5f, -1.0f, 0.0f);
            Vector3 p2  = new Vector3(-1.0f, -0.25f, 0.0f);
            Vector3 p3  = new Vector3(-1.0f, 0.5f, 0.0f);
            Vector3 p4  = new Vector3(-0.25f, 0.5f, 0.0f);
            Vector3 p5  = new Vector3(-0.5f, 1.0f, 0.0f);
            Vector3 p6  = new Vector3(0.25f, 1.0f, 0.0f);
            Vector3 p7  = new Vector3(1.0f, 0.5f, 0.0f);
            Vector3 p8  = new Vector3(0.25f, 0.0f, 0.0f);
            Vector3 p9  = new Vector3(1.0f, -0.5f, 0.0f);
            Vector3 p10 = new Vector3(0.25f, -1.0f, 0.0f);

            vertices.Add(p1);
            vertices.Add(p2);
            vertices.Add(p3);
            vertices.Add(p4);
            vertices.Add(p5);
            vertices.Add(p6);
            vertices.Add(p7);
            vertices.Add(p8);
            vertices.Add(p9);
            vertices.Add(p10);
        }
        break;
        }
        asteroids_vertices_.Add(vertices);
        asteroids_.Add(asteroid);
    }
Exemplo n.º 33
0
 public void StopMining()
 {
     Target = null;
     CurrentState = State.Disabled;
 }
Exemplo n.º 34
0
 private void onAsteroidClicked(Asteroid asteroid, PointerEventData data, ref bool allow)
 {
     UpdatePoints();
     asteroid.Handler.OnClickRequested -= onAsteroidClicked;
 }
Exemplo n.º 35
0
 static void CollideWithImpl(Asteroid x, Spaceship y)
 {
     Console.WriteLine("Asteroid collides with Spaceship");
 }
Exemplo n.º 36
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Boundary" || other.tag == "MineralPickup" || other.tag == "Capsule" || other.tag == "Edge" || other.tag == "BoostHit" || other.tag == "AutoTurret")
     {
         //Debug.Log("hit boundary/mineralpickup/capsule/edge");
         return;
     }
     else if (other.tag == "Player1(Black)" || other.tag == "Player2(White)" || other.tag == "Player3" || other.tag == "Player4")
     {
         //Debug.Log("SniperHit " + other.tag);
         enemyHealthScript = other.GetComponent <PlayerHealth>();
         if (enemyHealthScript.teamCount != teamCount)
         {
             enemyHealthScript.Damage(lineSniperShotDamage, false);
             DestroyThis();
         }
     }
     else if (other.tag == "Enemy")
     {
         aiHealthScript = other.GetComponent <EnemyHealth>();
         aiHealthScript.DamageEnemy(lineSniperShotDamage);
         DestroyThis();
     }
     else if (other.tag == "PlayerPhysicsCollider")
     {
         //Debug.Log("SniperHit " + other.tag);
         enemyHealthScript = other.GetComponentInParent <PlayerHealth>();
         if (enemyHealthScript.teamCount != teamCount)
         {
             enemyHealthScript.Damage(lineSniperShotDamage, false);
             DestroyThis();
         }
     }
     else if (other.tag == "RocketAmmo")
     {
         rocketScript = other.GetComponent <RemoteLauncherShot>();
         if (rocketScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "SniperBullet")
     {
         bulletScript = other.GetComponent <LineSniperShot>();
         if (bulletScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "Shot")
     {
         shotScript = other.GetComponent <ProtoShotPrefab>();
         if (shotScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "ShieldMine")
     {
         mineScript = other.GetComponent <ShieldMine>();
         if (mineScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "Asteroid")
     {
         //Debug.Log("hit asteroid");
         asteroidScript = other.GetComponent <Asteroid>();
         asteroidScript.DamageAsteroid(lineSniperShotDamage);
         pierceCount                -= 1;
         instance                    = Instantiate(deathParticles, transform.position, Quaternion.identity) as GameObject;
         deathParticleSys            = instance.GetComponent <ParticleSystem>();
         deathParticleSys.startColor = color;
         if (pierceCount < 1)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "Plasma")
     {
     }
     else if (other.tag == "PhaseBlast")
     {
     }
     else
     {
         //Debug.Log("hit " + other.tag);
         DestroyThis();
     }
 }
Exemplo n.º 37
0
 public void AsteroidDestroyed(Asteroid asteroid)
 {
     asteroids.Remove(asteroid);
 }
Exemplo n.º 38
0
	public void RemoveAsteroid(Asteroid asteroid) {
		if (asteroid.id < 0) {
			asteroids.Remove (asteroid.id);
			flaggedAsteroids.Remove(asteroid.id);
		} else {
			asteroids[asteroid.id] = null;
		}
	}
Exemplo n.º 39
0
        // Spawn the actual asteroid
        public void SpawnAsteroid(Asteroid asteroid, uint seed)
        {
            // Create Default Orbit
            Orbit         orbit = null;
            CelestialBody body  = null;

            // Select Orbit Type
            int type = Random.Range(0, 3);

            if (type == 0 && asteroid.location.around.Count != 0)
            {
                // Around
                IEnumerable <Location.AroundLoader> arounds = GetProbabilityList(asteroid.location.around, asteroid.location.around.Select(a => a.probability.value));
                Location.AroundLoader around = arounds.ElementAt(Random.Range(0, arounds.Count()));
                body = PSystemManager.Instance.localBodies.Find(b => b.name == around.body);
                if (!body)
                {
                    return;
                }
                if (around.reached && !ReachedBody(body))
                {
                    return;
                }
                orbit = new Orbit();
                orbit.referenceBody       = body;
                orbit.eccentricity        = around.eccentricity;
                orbit.semiMajorAxis       = around.semiMajorAxis;
                orbit.inclination         = around.inclination;
                orbit.LAN                 = around.longitudeOfAscendingNode;
                orbit.argumentOfPeriapsis = around.argumentOfPeriapsis;
                orbit.meanAnomalyAtEpoch  = around.meanAnomalyAtEpoch;
                orbit.epoch               = around.epoch;
                orbit.Init();
            }
            else if (type == 1 && asteroid.location.nearby.Count != 0)
            {
                // Nearby
                IEnumerable <Location.NearbyLoader> nearbys = GetProbabilityList(asteroid.location.nearby, asteroid.location.nearby.Select(a => a.probability.value));
                Location.NearbyLoader nearby = nearbys.ElementAt(Random.Range(0, nearbys.Count()));
                body = PSystemManager.Instance.localBodies.Find(b => b.name == nearby.body);
                if (!body)
                {
                    return;
                }
                if (nearby.reached && !ReachedBody(body))
                {
                    return;
                }
                orbit = new Orbit();
                orbit.eccentricity        = body.orbit.eccentricity + nearby.eccentricity;
                orbit.semiMajorAxis       = body.orbit.semiMajorAxis * nearby.semiMajorAxis;
                orbit.inclination         = body.orbit.inclination + nearby.inclination;
                orbit.LAN                 = body.orbit.LAN * nearby.longitudeOfAscendingNode;
                orbit.argumentOfPeriapsis = body.orbit.argumentOfPeriapsis * nearby.argumentOfPeriapsis;
                orbit.meanAnomalyAtEpoch  = body.orbit.meanAnomalyAtEpoch * nearby.meanAnomalyAtEpoch;
                orbit.epoch               = body.orbit.epoch;
                orbit.referenceBody       = body.orbit.referenceBody;
                orbit.Init();
            }
            else if (type == 2 && asteroid.location.flyby.Count != 0)
            {
                // Flyby
                IEnumerable <Location.FlybyLoader> flybys = GetProbabilityList(asteroid.location.flyby, asteroid.location.flyby.Select(a => a.probability.value));
                Location.FlybyLoader flyby = flybys.ElementAt(Random.Range(0, flybys.Count()));
                body = PSystemManager.Instance.localBodies.Find(b => b.name == flyby.body);
                if (!body)
                {
                    return;
                }
                if (flyby.reached && !ReachedBody(body))
                {
                    return;
                }
                orbit = Orbit.CreateRandomOrbitFlyBy(body, Random.Range(flyby.minDuration, flyby.maxDuration));
            }

            // Check
            if (orbit == null)
            {
                Debug.Log("[Kopernicus]: No new objects this time. (Probablility is " + asteroid.probability.value + "%)");
                return;
            }

            // Name
            string name = DiscoverableObjectsUtil.GenerateAsteroidName();

            // Lifetime
            double lifetime    = Random.Range(asteroid.minUntrackedLifetime, asteroid.maxUntrackedLifetime) * 24d * 60d * 60d;
            double maxLifetime = asteroid.maxUntrackedLifetime * 24d * 60d * 60d;

            // Size
            UntrackedObjectClass size = (UntrackedObjectClass)((int)(asteroid.size.curve.Evaluate(Random.Range(0f, 1f)) * Enum.GetNames(typeof(UntrackedObjectClass)).Length));

            // Spawn
            ConfigNode vessel = ProtoVessel.CreateVesselNode(
                name,
                VesselType.SpaceObject,
                orbit,
                0,
                new[]
            {
                ProtoVessel.CreatePartNode(
                    "PotatoRoid",
                    seed,
                    new ProtoCrewMember[0]
                    )
            },
                new ConfigNode("ACTIONGROUPS"),
                ProtoVessel.CreateDiscoveryNode(
                    DiscoveryLevels.Presence,
                    size,
                    lifetime,
                    maxLifetime
                    )
                );

            OverrideNode(ref vessel, asteroid.vessel);
            ProtoVessel protoVessel = new ProtoVessel(vessel, HighLogic.CurrentGame);

            if (asteroid.uniqueName && FlightGlobals.Vessels.Count(v => v.vesselName == protoVessel.vesselName) != 0)
            {
                return;
            }
            protoVessel.Load(HighLogic.CurrentGame.flightState);
            GameEvents.onNewVesselCreated.Fire(protoVessel.vesselRef);
            Debug.Log("[Kopernicus]: New object found near " + body.name + ": " + protoVessel.vesselName + "!");
        }
Exemplo n.º 40
0
    public static void Inspector(Asteroid a)
    {
        a.render2SkyBox = GuiTools.Toggle("Render to skybox",a.render2SkyBox,true);
        EditorGUILayout.Space();

        a.parent = (Transform)EditorGUILayout.ObjectField("Cosmos parent",a.parent, typeof(Transform),true);

        if (a.parent == AsteroidSystem.instance.transform){
            a.transform.position = EditorGUILayout.Vector3Field("Position",a.transform.position);
        }

        a.transform.eulerAngles = EditorGUILayout.Vector3Field("Rotation",a.transform.eulerAngles);

        EditorGUILayout.Space();

        GUI.backgroundColor = new Color(33f/255f,180f/255f,252f/255f);
        a.popMethod = (Asteroid.PopMethod)EditorGUILayout.EnumPopup( "Method",a.popMethod);
        GUI.backgroundColor = Color.white;

        EditorGUILayout.Space();

        a.minRadius = EditorGUILayout.FloatField("Min radius",a.minRadius);
        a.maxRadius = EditorGUILayout.FloatField("Max radius",a.maxRadius);
        if (a.popMethod == Asteroid.PopMethod.Ring){
            a.height = EditorGUILayout.FloatField("Height",a.height);
        }

        EditorGUILayout.Space();

        a.minScale = EditorGUILayout.FloatField("Min scale", a.minScale);
        a.maxScale = EditorGUILayout.FloatField("Max scale", a.maxScale);

        GuiTools.DrawSeparatorLine(25);

        a.cloneCount = EditorGUILayout.IntField("Number of copies", a.cloneCount);

        EditorGUILayout.Space();

        // Reference element
        SerializedObject ast = new SerializedObject(a);
        SerializedProperty objReference = ast.FindProperty("gameobjectReference");
        bool go=true;
        while (go){
            go = EditorGUILayout.PropertyField(objReference, true, null);
                go = objReference.NextVisible(go);
        }
        ast.ApplyModifiedProperties();

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(14);
        if (GUILayout.Button(new GUIContent("Generate",CosmosInspector.GetIcon(18)),GUILayout.Width(100))){
            a.Clear();
            a.Generate();
        }
        if (GUILayout.Button(new GUIContent("Clear",CosmosInspector.GetIcon(12)),GUILayout.Width(100))){
            a.Clear();
        }
        EditorGUILayout.EndHorizontal();

        GuiTools.DrawSeparatorLine(25);

        a.enableRotation = GuiTools.Toggle("Enable rotation",a.enableRotation,true);
        a.rotationSpeed = EditorGUILayout.Vector3Field("Rotation speed",a.rotationSpeed);
        if (a.enableRotation) a.render2SkyBox = false;
    }
Exemplo n.º 41
0
 public void LoadAsteroid(Asteroid asteroid)
 {
     LoadAsset(asteroid);
     //Packet.Builder.BattleStationNoClanUiInitializationCommand(World.StorageManager.GetGameSession(Player.Id), asteroid);
 }
Exemplo n.º 42
0
 /// <summary>
 /// Add an element to the dictionary
 /// </summary>
 /// <param name="id">Key of the element added</param>
 /// <param name="ast">Element added</param>
 public void add(int id, Asteroid ast)
 {
     asteroidInUse.Add(id, ast);
 }
Exemplo n.º 43
0
        //Detect Collisions for everything
        private void DetectCollisions()
        {
            #region Player vs Asteroids
            if (spawntimer >= spawninterval)
            {
                #region Asteroid1
                for (int i = 0; i <= NumAsteroid1 - 1; i++)
                {
                    collide = collision.playerCollide(myModel, Asteroid1, asteroid1List[i].position, play.position, Content);
                    if (collide == true)
                    {
                        spawntimer = 0;
                        while (collide == true)
                        {
                            Random x = new Random();
                            Random y = new Random();
                            play.position.X = x.Next(-2000, 2000);
                            play.position.Y = y.Next(-2000, 2000);
                            collide         = collision.playerCollide(myModel, Asteroid1, asteroid1List[i].position, play.position, Content);
                        }
                        collide     = false;
                        play.Lives -= 1;
                        if (play.Lives == 0)
                        {
                            dead = true;
                        }
                    }
                }
                #endregion
            }
            if (spawntimer >= spawninterval)
            {
                #region Asteroid2
                for (int i = 0; i <= NumAsteroid2 - 1; i++)
                {
                    collide = collision.playerCollide(myModel, Asteroid2, asteroid2List[i].position, play.position, Content);
                    if (collide == true)
                    {
                        spawntimer = 0;
                        while (collide == true)
                        {
                            Random x = new Random();
                            Random y = new Random();
                            play.position.X = x.Next(-2000, 2000);
                            play.position.Y = y.Next(-2000, 2000);
                            collide         = collision.playerCollide(myModel, Asteroid2, asteroid2List[i].position, play.position, Content);
                        }
                        collide     = false;
                        play.Lives -= 1;
                        if (play.Lives == 0)
                        {
                            dead = true;
                        }
                    }
                }
                #endregion
            }
            if (spawntimer >= spawninterval)
            {
                #region Asteroid3
                for (int i = 0; i <= NumAsteroid3 - 1; i++)
                {
                    collide = collision.playerCollide(myModel, Asteroid3, asteroid3List[i].position, play.position, Content);
                    if (collide == true)
                    {
                        spawntimer = 0;
                        while (collide == true)
                        {
                            Random x = new Random();
                            Random y = new Random();
                            play.position.X = x.Next(-2000, 2000);
                            play.position.Y = y.Next(-2000, 2000);
                            collide         = collision.playerCollide(myModel, Asteroid3, asteroid3List[i].position, play.position, Content);
                        }
                        collide     = false;
                        play.Lives -= 1;
                        if (play.Lives == 0)
                        {
                            dead = true;
                        }
                    }
                }
                #endregion
            }

            #endregion

            #region Asteroids vs Bullets

            #region Asteroid1
            for (int i = 0; i <= NumAsteroid1 - 1; i++)
            {
                bulletCollide = collision.BulletsCollide(ammo, Asteroid1, asteroid1List[i].position, BulletList[0].AmmoModelPosition, Content);
                if (bulletCollide == true)
                {
                    Score += 10;
                    #region Remove bullets
                    bulletCollide = false;
                    BulletList[0].AmmoModelPosition = new Vector3(-5000, -5000f, 0.0f);
                    BulletList[0].AmmoFlying        = false;
                    asteroid1List[i].lives         -= 1;
                    #endregion

                    #region Out of lives
                    if (asteroid1List[i].lives == 0)
                    {
                        Score += 100;

                        asteroidsonscreen -= 1;
                        Explosion.Play(0.5F);
                        SpawnAsteroids(asteroid1List[i].asteroidModel, asteroid1List[i].position);

                        asteroid1List[i] = new Asteroid(Asteroid1, new Vector3(8000, 8000, 0), 0.0f, false, 0);
                    }
                    #endregion
                }
            }
            #endregion

            #region Asteroid 2
            for (int i = 0; i <= NumAsteroid2 - 1; i++)
            {
                bulletCollide2 = collision.BulletsCollide(ammo, Asteroid2, asteroid2List[i].position, BulletList[0].AmmoModelPosition, Content);
                if (bulletCollide2 == true)
                {
                    Score += 10;
                    #region Remove bullets
                    BulletList[0].AmmoModelPosition = new Vector3(-5000f, -5000f, 0.0f);
                    BulletList[0].AmmoFlying        = false;
                    bulletCollide2          = false;
                    asteroid2List[i].lives -= 1;
                    #endregion


                    #region Out of lives
                    if (asteroid2List[i].lives == 0)
                    {
                        Score += 50;

                        Explosion.Play(0.5F);
                        SpawnAsteroids(asteroid2List[i].asteroidModel, asteroid2List[i].position);

                        asteroid2List[i]   = new Asteroid(Asteroid2, new Vector3(8000, 8000, 0), 0.0f, false, 0);
                        asteroidsonscreen -= 1;
                    }
                    #endregion
                }
            }
            #endregion

            #region Asteroid3
            for (int i = 0; i <= NumAsteroid3 - 1; i++)
            {
                bulletCollide3 = collision.BulletsCollide(ammo, Asteroid3, asteroid3List[i].position, BulletList[0].AmmoModelPosition, Content);
                if (bulletCollide3 == true)
                {
                    Score += 10;
                    #region Remove bullets
                    BulletList[0].AmmoModelPosition = new Vector3(-5000f, -5000f, 0.0f);
                    BulletList[0].AmmoFlying        = false;
                    bulletCollide3          = false;
                    asteroid3List[i].lives -= 1;
                    #endregion


                    #region Out of lives
                    if (asteroid3List[i].lives == 0)
                    {
                        Score             += 20;
                        asteroid3List[i]   = new Asteroid(Asteroid3, new Vector3(8000, 8000, 0), 0.0f, false, 0);
                        asteroidsonscreen -= 1;
                        //just using asteroidlist1 at the moment, adapt for all models


                        Explosion.Play(0.5F);
                    }
                    #endregion
                }
            }
            #endregion

            #endregion
        }
Exemplo n.º 44
0
 public void generateAsteroid()
 {
     MovableGameEntity newAsteroid = new Asteroid(playerShip, this);
     asteroidCollection.Add(newAsteroid);
     drawAsteroid(newAsteroid);
 }
Exemplo n.º 45
0
 /// <summary>
 /// Remove an asteroid from the set
 /// </summary>
 /// <param name="instance"></param>
 public void RemoveAsteroid(Asteroid instance)
 {
     asteroidInstanceSet.Remove(instance);
 }
Exemplo n.º 46
0
    public void killPlayer(Asteroid asteroid)
    {
        asteroidCollection.Remove(asteroid);
        this.gameCanvas.Children.Remove(asteroid.entityShape);
        if (this.playerShip != null)
        {
            this.gameCanvas.Children.Remove(this.playerShip.entityShape);
            this.playerShip.setEntityCenterX(500);
            this.playerShip.setEntityCenterY(500);
            this.playerShip.setEntityHeading(0);
            this.playerLives -= 1;
        }

        if (this.playerLives > 0)
        {
            this.gameCanvas.Children.Add(this.playerShip.getEntityShape());
        }
        else { this.playerShip = null; }
    }
Exemplo n.º 47
0
 public MineAsteroidCommand(Asteroid target, UserDrone uDrone)
 {
     this.target = target;
     this.uDrone = uDrone;
 }
Exemplo n.º 48
0
 public void killAsteroid(Asteroid asteroid)
 {
     this.asteroidCollection.Remove(asteroid);
     this.gameCanvas.Children.Remove(asteroid.entityShape);
     this.asteroidsKilled += 1;
 }
    void Start()
    {
        GameObject configureObj = GameObject.FindGameObjectWithTag(Constants.AsteroidConfigureTag);

        asteroidConfigure = configureObj.GetComponent <Asteroid>();

        GameObject requestObj = GameObject.FindGameObjectWithTag(Constants.AsteroidRequestTag);

        asteroidRequest = requestObj.GetComponent <Asteroid>();

        GameObject playObj = GameObject.FindGameObjectWithTag(Constants.AsteroidPlayTag);

        asteroidPlay = playObj.GetComponent <Asteroid>();

        // Only configure asteroid is available at start.
        asteroidConfigure.Show();
        asteroidRequest.Hide();
        asteroidPlay.Hide();

        // ----- AdColony Ads -----

        AdColony.Ads.OnConfigurationCompleted += (List <AdColony.Zone> zones_) => {
            Debug.Log("AdColony.Ads.OnConfigurationCompleted called");

            if (zones_ == null || zones_.Count <= 0)
            {
                // Show the configure asteroid again.
                asteroidConfigure.Show();
            }
            else
            {
                IsAdInitialized = true;

                // Successfully configured... show the request ad asteroid.
                asteroidRequest.Show();
            }
        };

        AdColony.Ads.OnRequestInterstitial += (AdColony.InterstitialAd ad_) => {
            Debug.Log("AdColony.Ads.OnRequestInterstitial called");
            Ad            = ad_;
            IsAdAvailable = true;

            // Successfully requested ad... show the play ad asteroid.
            asteroidPlay.Show();
        };

        AdColony.Ads.OnRequestInterstitialFailedWithZone += (string zoneId) => {
            Debug.Log("AdColony.Ads.OnRequestInterstitialFailedWithZone called, zone: " + zoneId);
            IsAdAvailable = false;

            // Request Ad failed... show the request ad asteroid.
            asteroidRequest.Show();
        };

        AdColony.Ads.OnOpened += (AdColony.InterstitialAd ad_) => {
            Debug.Log("AdColony.Ads.OnOpened called");
            IsAdAvailable = false;

            // Ad started playing... show the request ad asteroid for the next ad.
            asteroidRequest.Show();
        };

        AdColony.Ads.OnClosed += (AdColony.InterstitialAd ad_) => {
            Debug.Log("AdColony.Ads.OnClosed called, expired: " + ad_.Expired);
            IsAdAvailable = false;
        };

        AdColony.Ads.OnExpiring += (AdColony.InterstitialAd ad_) => {
            Debug.Log("AdColony.Ads.OnExpiring called");
            Ad            = null;
            IsAdAvailable = false;

            // Current ad expired... show the request ad asteroid.
            asteroidRequest.Show();
            asteroidPlay.Hide();
        };

        AdColony.Ads.OnIAPOpportunity += (AdColony.InterstitialAd ad_, string iapProductId_, AdColony.AdsIAPEngagementType engagement_) => {
            Debug.Log("AdColony.Ads.OnIAPOpportunity called");
        };

        AdColony.Ads.OnRewardGranted += (string zoneId, bool success, string name, int amount) => {
            Debug.Log(string.Format("AdColony.Ads.OnRewardGranted called\n\tzoneId: {0}\n\tsuccess: {1}\n\tname: {2}\n\tamount: {3}", zoneId, success, name, amount));
        };

        AdColony.Ads.OnCustomMessageReceived += (string type, string message) => {
            Debug.Log(string.Format("AdColony.Ads.OnCustomMessageReceived called\n\ttype: {0}\n\tmessage: {1}", type, message));
        };
    }
Exemplo n.º 50
0
    void ScaleRandomly(ref Asteroid _asteroidToScale)
    {
        float randomScale = Random.Range(minScale, maxScale);

        _asteroidToScale.transform.localScale = new Vector3(randomScale, randomScale, 1);
    }
Exemplo n.º 51
0
    /// <summary>
    /// Creates new asteroids of a smaller size where the old asteroid was,
    /// giving the illusion of a crumbling rock
    /// </summary>
    /// <param name="asteroidType">The type of prefab for the old asteroid</param>
    /// <param name="position">The position of the old asteroid</param>
    public void BreakUpAsteroid(Asteroid.ASTEROID_TYPE asteroidType, Vector3 position)
    {
        Asteroid asteroid;

        switch (asteroidType)
        {
        case Asteroid.ASTEROID_TYPE.Large:
            // break large asteroid into two medium ones at the old asteroid's position

            asteroid = (Asteroid)ActivateItem((int)Asteroid.ASTEROID_TYPE.Medium);
            if (asteroid != null)
                asteroid.Set(this, Asteroid.ASTEROID_TYPE.Medium, GetRandomSpin(), GetRandomVelocity(), position);

            asteroid = (Asteroid)ActivateItem((int)Asteroid.ASTEROID_TYPE.Medium);
            if (asteroid != null)
                asteroid.Set(this, Asteroid.ASTEROID_TYPE.Medium, GetRandomSpin(), GetRandomVelocity(), position);
            break;

        case Asteroid.ASTEROID_TYPE.Medium:
            // break medium asteroid into two small ones at the old asteroid's position

            asteroid = (Asteroid)ActivateItem((int)Asteroid.ASTEROID_TYPE.Small);
            if (asteroid != null)
                asteroid.Set(this, Asteroid.ASTEROID_TYPE.Small, GetRandomSpin(), GetRandomVelocity(), position);

            asteroid = (Asteroid)ActivateItem((int)Asteroid.ASTEROID_TYPE.Small);
            if (asteroid != null)
                asteroid.Set(this, Asteroid.ASTEROID_TYPE.Small, GetRandomSpin(), GetRandomVelocity(), position);
            break;

        case Asteroid.ASTEROID_TYPE.Small:
            // do nothing here since small asteroids are the last and smallest size
            break;
        }
    }
Exemplo n.º 52
0
 /// <summary>
 /// Add an Asteroid to the stack of unused asteroids
 /// We make sure that all the changes required to have a disabled asteroid are done before
 /// </summary>
 /// <param name="ast"></param>
 public void push(Asteroid ast)
 {
     asteroidNotInUse.Push(ast);
     ast.gameObject.SetActive(false);
 }
Exemplo n.º 53
0
    private static void SelectAsteroid(Asteroid a)
    {
        Asteroid[] asteroids = AsteroidSystem.instance.GetComponentsInChildren<Asteroid>();
        int j=0;
        while (j<asteroids.Length){
            asteroids[j].inspectorShowProperties = false;
            j++;
        }

        a.inspectorShowProperties = true;
        CosmosInspector.asteroid = a;

        GuiTools.SetSceneCamera(45,-45, new Vector3(600,600,-600),1000);
    }
Exemplo n.º 54
0
        public MainGame(Scene container) : base(container)
        {
            Elements = new List <Element>();

            ship = new Ship(
                new int[] { 0, 135, 225 },
                10,
                new Point(Size.Width / 2, Size.Height / 2),
                0,
                0,
                Color.Blue);

            Elements.Add(ship);
            Elements.AddRange(Asteroid.CreateAsteroids(10, 10, 60, 15, Color.SandyBrown, Size));

            Commands = new List <Command>()
            {
                new Command()
                {
                    Name  = "RotateLeft",
                    Key   = Keys.A,
                    Event = ((Rotate) =>
                    {
                        if (Rotate)
                        {
                            ship.Rotate(-5);
                        }
                    })
                },
                new Command()
                {
                    Name  = "RotateRight",
                    Key   = Keys.D,
                    Event = ((Rotate) =>
                    {
                        if (Rotate)
                        {
                            ship.Rotate(5);
                        }
                    })
                },
                new Command()
                {
                    Name  = "ChangeSpeed",
                    Key   = Keys.W,
                    Event = ((Acelerar) =>
                    {
                        if (Acelerar)
                        {
                            ship.ChangeSpeed(.5f);
                        }
                        else
                        {
                            ship.ChangeSpeed(-.5f);
                        }
                    })
                },
                new Command()
                {
                    Name  = "Shoot",
                    Key   = Keys.Space,
                    Event = ((Atirar) =>
                    {
                        if (Atirar)
                        {
                            Elements.Add(ship.Shoot());
                        }
                    })
                },
                new Command()
                {
                    Name  = "Pause",
                    Key   = Keys.Escape,
                    Event = ((Pause) =>
                    {
                        foreach (var l in Parent.Layers)
                        {
                            l.CanUpdate = !Pause;
                        }
                    })
                }
            };
        }
Exemplo n.º 55
0
		public void FractureAsteroid()
		{
			var asteroid = new Asteroid(new InteractionLogic());
			asteroid.Fracture();
			Assert.IsFalse(asteroid.IsActive);
		}
Exemplo n.º 56
0
	public void FlagAsteroid(Asteroid asteroid) {
		if (flaggedAsteroids.ContainsKey(asteroid.id))
		    return;

		asteroid.flagged = true;
		AsteroidData ad = new AsteroidData();
		ad.index = asteroid.id;
		flaggedAsteroids.Add(ad.index, ad);
	}
Exemplo n.º 57
0
		public void CreateAsteroidAtDefinedPosition()
		{
			var asteroid = new Asteroid(Vector2D.Zero, new InteractionLogic());
			Assert.AreEqual(Vector2D.Zero, asteroid.Center);
		}
Exemplo n.º 58
0
 public void ReturnAsteroidToPool(Asteroid asteroid)
 {
     _asteroidPool.DisablePoolObject(asteroid);
 }
Exemplo n.º 59
0
        private void old_LoadContent(GameplayScreen screen)
        {
            Pieces = new List<VisualObject3D>();

            BackgroundResourceName = "Textures\\Space_BackGround";
            BackgroundTexture = GameScreen.ScreenManager.Game.Content.Load<Texture2D>(BackgroundResourceName);
            string modelResourceName = "Models\\asteroid1";
            Model AsteroidModel = GameScreen.ScreenManager.Game.Content.Load<Model>(modelResourceName);
            Random Rand = new Random();

            //create 10 asteroids with some random stats.
            int numOfAsteroids = 10;
            for (int i = 0; i < numOfAsteroids; i++)
            {
                Asteroid newAsteroid = new Asteroid(GameScreen)
                {
                    ObjectModel = AsteroidModel,
                    ModelResourceName = modelResourceName,
                    BSphere = AsteroidModel.Meshes[0].BoundingSphere,
                    ReferenceCamera = screen.Camera1,
                    Velocity = (new Vector2(Rand.nextSignedFloat(), Rand.nextSignedFloat())).getDirectedVector(0.3f),
                    RotationVelocity = Rand.nextVector3Interval(new Vector3(-0.1f, -0.1f, -0.1f), new Vector3(0.1f, 0.1f, 0.1f))
                };
                Pieces.Add(newAsteroid);
            }
        }
Exemplo n.º 60
0
 void ReturnUnabledToSpawnAsteroid(Asteroid _asteroidToReturn)
 {
     PoolsManager.Instance.ReleaseObjectToPool <Asteroid>(_asteroidToReturn);
 }