예제 #1
0
            public void Activate(Spaceship spaceship, SpaceshipBody body, SpaceshipBrain brain)
            {
                base.Activate(spaceship, body);
                this.obj.Reset(brain);
                var shipBody = (SpaceshipBody)obj.body;
                var main     = shipBody.energyEmitter.main;

                main.maxParticles = 20;
                ShieldDown();
            }
예제 #2
0
            public void RegisterSpaceship(SpaceshipBody body, SpaceshipBrain brain)
            {
                var spaceship        = Space.spaceshipsPool.Borrow();
                var spaceshipMutable = Space.spaceshipMutablesPool.Borrow();

                spaceshipMutable.Activate(spaceship, body, brain);
                DebugUtils.Log("RegisterSpaceship " + spaceship.Name);

                Space.spaceships.Add(spaceship);
                Space.spaceshipMutables.Add(spaceshipMutable);
            }
예제 #3
0
파일: Game.cs 프로젝트: yoellevy/StarWars
        protected void Start()
        {
            // Create all spaceships.
            var secondaryColorIndex = 0;
            var type2colors         = new Dictionary <SpaceshipBody.Type, HashSet <Color> >();
            var nameCount           = new Dictionary <string, int>();
            var spaceships          = FindObjectsOfType <SpaceshipBody>();

            DebugUtils.Assert(0 < spaceships.Length, "Define spaceship names at 'Game'");
            DebugUtils.Assert(spaceships.Length <= 6, "Max 6 spaceships allowed!");

            foreach (var body in spaceships)
            {
                var spawnPoint = Space.GetSpawnPoint();
                var angle      = UnityEngine.Random.Range(1, 360 / Spaceship.ROTATION_PER_ACTION) * Spaceship.ROTATION_PER_ACTION;
                body.Activate(spawnPoint, angle, space);

                // Check for duplicate type and color.
                var bodyType = body.spaceshipType;
                // Further normaliziation of color to distinguish between similar colors.
                var color = SpaceshipBody.NormalizeColor(body.primaryColor, 0x20);
                if (!type2colors.ContainsKey(bodyType))
                {
                    type2colors[bodyType] = new HashSet <Color>();
                    type2colors[bodyType].Add(color);
                }
                else if (type2colors[bodyType].Contains(color))
                {
                    // Color clash! Set secondary color.
                    body.SetSecondaryColor(secondaryColors[secondaryColorIndex++]);
                }
                else
                {
                    type2colors[bodyType].Add(color);
                }

                var brain = body.Brain;
                if (nameCount.ContainsKey(brain.DefaultName))
                {
                    ++nameCount[brain.DefaultName];
                    brain.Name = brain.DefaultName + " " + nameCount[brain.DefaultName];
                }
                else
                {
                    nameCount[brain.DefaultName] = 1;
                }

                // Register to score board.
                scoreBoard.Add(brain.Name, color, body.secondaryColor);
            }

            deaths = 0;
        }