Exemplo n.º 1
0
        /// <summary>
        /// Adds a single bullet to the screen; should only be called from CreateOneWave.
        /// </summary>
        private Bullet CreateBullet(BulletType bulletType, Vector2 spawnPoint, float angle,
                                    float speed, LevelColors colors)
        {
            switch (bulletType)
            {
            case BulletType.Normal:
                return(new Spike(spawnPoint, speed, angle, colors.Normal));

            case BulletType.Normal2:
                return(new Spike(spawnPoint, speed, angle, colors.Normal2));

            case BulletType.Homing:
                throw new ArgumentException("Spawn homing bullets with CreateHomingBullet please");

            case BulletType.Bubble:
                return(new Bubble(spawnPoint, speed, angle, colors.Bubble));

            case BulletType.Heart:
                return(new Heart(spawnPoint, speed, angle));

            case BulletType.Hug:
                return(new Hug(spawnPoint, speed, angle, colors.Hug));

            case BulletType.Error:
                return(new ErrorBullet(spawnPoint, speed, angle));

            default:
                return(new Spike(spawnPoint, speed, angle, colors.Normal));
            }
        }
Exemplo n.º 2
0
        public Shot(XmlNode node, LevelColors colors)
        {
            Time = double.Parse(node.Attributes["time"].Value, Culture) * 1000;
            var enemiesStr = node.Attributes["enemies"].Value.Split(',');

            Enemies    = Array.ConvertAll(enemiesStr, s => int.Parse(s, Culture) - 1);
            BulletType = ParseBulletType(node.Attributes["bulletType"].Value);
            Aim        = ParseAim(node.Attributes["aim"].Value);
            Offset0    = double.Parse(node.Attributes["offset0"].Value, Culture) * MathEx.DegToRad;
            Speed0     = double.Parse(node.Attributes["speed0"].Value, Culture);
            Angle0     = double.Parse(node.Attributes["angle0"].Value, Culture) * MathEx.DegToRad;

            if (node.Attributes["amount0"] is null)
            {
                Amount0 = int.Parse(node.Attributes["amount"].Value, Culture); // special case for streams
            }
            else
            {
                Amount0 = int.Parse(node.Attributes["amount0"].Value, Culture);
            }

            if (BulletType == BulletType.Homing)
            {
                var lifespanAttrib = node.Attributes["lifespan"];
                HomingLifespan = lifespanAttrib is null
                    ? Homing.DefaultLifespan
                    : double.Parse(lifespanAttrib.Value, Culture) / 30 * 1000;
            }

            Color = GetBulletColor(BulletType, colors);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Returns the color of the bullet type in a shot.
 /// </summary>
 private Color GetBulletColor(BulletType type, LevelColors colors)
 {
     return(type switch
     {
         BulletType.Normal => colors.Normal,
         BulletType.Normal2 => colors.Normal2,
         BulletType.Homing => colors.Homing,
         BulletType.Bubble => colors.Bubble,
         BulletType.Hug => colors.Hug,
         BulletType.Heart => Color.Red,
         _ => colors.Normal,
     });
Exemplo n.º 4
0
        public void SetColors(LevelColors colors, Color backgroundColor)
        {
            Circle.FillColor   = backgroundColor;
            Circle.BorderColor = colors.Outline;

            ScoreCircle.Radius      = 0f;
            ScoreCircle.FillColor   = Util.GetActualScoreColor(colors.ScoreCircle);
            ScoreCircle.BorderColor = colors.Outline;

            SongPosCircle.Radius      = 0f;
            SongPosCircle.FillColor   = colors.Background;
            SongPosCircle.BorderColor = colors.Outline;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates one wave of a shot.
        /// </summary>
        public List <Bullet> Create(Vector2 spawnPoint, float spawnerAngle, Vector2 playerCenter,
                                    LevelColors colors)
        {
            var bullets = new List <Bullet>(Amount);

            double waveAngle = spawnerAngle + (90 * MathEx.DegToRad);

            if (Amount > 1)
            {
                waveAngle += Angle / -2;
            }

            if (Aim == Aim.Player)
            {
                float playerAngle = (float)Math.Atan2(
                    spawnPoint.Y - playerCenter.Y,
                    spawnPoint.X - playerCenter.X)
                                    - spawnerAngle;
                waveAngle += playerAngle;
            }

            MathEx.WrapAngle(waveAngle);

            var angleStep = Angle / (Amount - 1);

            for (int i = 0; i < Amount; i++)
            {
                var bulletAngle = waveAngle + Offset;

                if (BulletType == BulletType.Homing)
                {
                    bullets.Add(CreateHomingBullet(spawnPoint, (float)bulletAngle,
                                                   (float)Speed, (float)HomingLifespan, colors));
                }
                else
                {
                    bullets.Add(CreateBullet(BulletType, spawnPoint, (float)bulletAngle,
                                             (float)Speed, colors));
                }
                waveAngle += angleStep;
            }

            return(bullets);
        }
Exemplo n.º 6
0
 private Bullet CreateHomingBullet(Vector2 spawnPoint, float angle, float speed,
                                   float lifespan, LevelColors colors)
 {
     return(new Homing(spawnPoint, speed, angle, lifespan, colors.Homing));
 }