コード例 #1
0
        public Space(Hero hero, List<Enemy> enemies, float leftEdge)
            : base()
        {
            this.hero = hero;

            powerups = new List<PowerUp>();
            dyepacks = new List<DyePack>();
            debris = new List<Debris>();
            trail = new Trail(hero);

            float height = GameWorld.topEdge;
            float position = (width * 0.5f) + leftEdge;

            space = new XNACS1Rectangle(new Vector2(position, height/2), width, height);
            space.Visible = false;

            // add dyepacks to space region
            List<Color> colors = Game.randomColorSet(Game.colorCount);
            float rightEdge = space.CenterX + space.Width / 2;
            float region = (rightEdge - leftEdge) / dyepackCount;
            for (int i = 0; i < dyepackCount; i++)
            {
                float regionLeft = leftEdge + (i * region);
                float regionRight = regionLeft + region;
                dyepacks.Add(new DyePack(hero, regionLeft, regionRight, colors[i % Game.colorCount]));
            }

            region = (rightEdge - leftEdge) / powerupCount;
            for (int i = 0; i < powerupCount; i++)
            {
                float regionLeft = leftEdge + (i * region);
                float regionRight = regionLeft + region;
                powerups.Add(PowerUp.randomPowerUp(hero, regionLeft, regionRight));
            }

            // offset the region to pad the space before the next element
            // this makes the region slightly smaller than it actually should be otherwise
            int offset = 1;
            region = (rightEdge - leftEdge) / (debrisCount + offset);
            for (int i = 0; i < debrisCount; i++) {
                float regionLeft = leftEdge + (i * region);
                float regionRight = regionLeft + region;
                debris.Add(new Debris(hero, enemies, regionLeft, regionRight));
            }
        }