Beispiel #1
0
        /*
         * void MovePhaseBoss(EnemyData ed)
         * {
         *  float speed = 0f;
         *  float duration = 5;
         *  switch (ed.component.Type)
         *  {
         *      case EnemyType.Yoshika:
         *          speed = 3f;
         *          break;
         *  }
         * }
         */

        void ShootPhase(EnemyData ed, float cooldown)
        {
            ed.body.DX          = 0;
            ed.body.DY          = 0;
            ed.component.Timer += ed.seconds;
            if (ed.component.Timer > cooldown)
            {
                ed.component.Timer -= cooldown;
                if (ed.component.Type == EnemyType.BraveFairy)
                {
                    for (int i = 0; i < 12; i++)
                    {
                        double r  = i * Math.PI * 2 / 12;
                        float  dx = (float)Math.Sin(r);
                        float  dy = (float)Math.Cos(r);
                        DanmakuFactory.MakeBullet(scene, BulletType.EnemyShot, ed.body.X, ed.body.Y, dx * 2f, dy * 2f);
                    }
                }
                else
                {
                    DanmakuFactory.MakeDirBullet(scene, BulletType.EnemyShot, ed.body.X, ed.body.Y, ed.playerBody.X, ed.playerBody.Y, 3f);
                }
                ed.component.Phase++;
            }
        }
Beispiel #2
0
        public override void Update(GameTime gameTime)
        {
            sys.LevelScriptComponents.TryGetFirstEnabled(out LevelScriptComponent level);

            sys.PlayerComponents.TryGetFirstEnabled(out PlayerComponent player);
            BodyComponent playerBody = sys.BodyComponents.GetByOwner(player.Owner);
            EnemyData     ed         = new EnemyData()
            {
                playerBody = playerBody, seconds = (float)gameTime.ElapsedGameTime.TotalSeconds
            };

            foreach (EnemyComponent component in sys.EnemyComponents.EnabledList)
            {
                BodyComponent body = sys.BodyComponents.GetByOwner(component.Owner);

                if (level.Story != null && component.Phase > 0)
                {
                    body.DX = 0;
                    body.DY = 0;
                    continue;
                }
                ed.component = component;
                ed.body      = body;
                if (component.Type <= EnemyType.BraveFairy)
                {
                    if (component.Phase == 0)
                    {
                        MovePhase(ed, 3.8f);
                    }
                    else if (component.Phase > 0 && component.Phase < 6)
                    {
                        ShootPhase(ed, 1f);
                    }
                    else if (component.Phase >= 5)
                    {
                        if (component.Type == EnemyType.Fairy)
                        {
                            component.Phase = -1;
                        }
                        else if (component.Type == EnemyType.BraveFairy)
                        {
                            //component.Phase = 1;
                            //if (component.Shield == null) AddShield(component);
                            component.Phase++;
                            if (component.Phase >= 9)
                            {
                                component.Phase = -1;
                            }
                        }
                        else
                        {
                            component.Phase = 1;
                        }
                    }
                    else
                    {
                        body.DY = -2.2f;
                    }
                }
                else if (component.Type == EnemyType.MoneyBag)
                {
                    if (component.Phase == 0)
                    {
                        if (body.X < 0 && body.DX < 0)
                        {
                            body.DX = -body.DX;
                        }
                        if (body.X > Config.LevelWidth && body.DX > 0)
                        {
                            body.DX = -body.DX;
                        }
                        component.Timer += ed.seconds;
                        body.DY          = (float)Math.Sin(component.Timer) / 2;
                        if (Math.Abs(body.X - component.TargetX) < 10)
                        {
                            component.Phase = 1;
                            component.Timer = 0;
                        }
                    }
                    if (component.Phase == 1)
                    {
                        component.Timer += ed.seconds;
                        body.DY          = (float)Math.Sin(component.Timer) / 2;
                        body.DX          = (float)Math.Cos(component.Timer) / 4;
                        if (component.Timer > 12f)
                        {
                            component.Phase = 2;
                            Random r = new Random();
                            body.DX = 0.4f + (float)r.NextDouble() * 0.05f;
                            if (body.X < Config.LevelWidth / 2)
                            {
                                body.DX = -body.DX;
                            }
                            //if (r.NextDouble() < 0.5) body.DX = -body.DX;
                        }
                    }
                    if (component.Phase == 2)
                    {
                        component.Timer += ed.seconds;
                        body.DY          = (float)Math.Sin(component.Timer) / 2;
                    }
                }
                else if (component.Type >= EnemyType.Boss)
                {
                    component.MoneyTimer -= ed.seconds;
                    if (component.MoneyTimer < 0f)
                    {
                        Random r = new Random();
                        float  x = (float)r.NextDouble() * Config.LevelWidth;
                        float  y = (float)r.NextDouble() * Config.LevelHeight / 2 + 20;
                        float  x3;
                        if (x > Config.LevelWidth / 2)
                        {
                            x3 = 0 - 50;
                        }
                        else
                        {
                            x3 = Config.LevelWidth + 50;
                        }
                        DanmakuFactory.MakeEnemy(scene, EnemyType.MoneyBag, x3, y, x, y);
                        component.MoneyTimer = 16f;
                    }
                    if (component.Phase == 0)
                    {
                        if (component.Type == EnemyType.Yoshika)
                        {
                            component.TargetX = playerBody.X;
                            component.TargetY = playerBody.Y - 330;
                        }
                        //MovePhaseBoss(ed);
                        MovePhase(ed, 3.8f, 1.7f, 1.7f);
                    }
                    else if (component.Phase == 1)
                    {
                        if (component.Type == EnemyType.Yoshika)
                        {
                            float wait  = 0.5f;
                            float speed = 0.1f;
                            float accel = 0.01f;
                            WaitPhase(ed, wait);
                            component.Timer2 += ed.seconds;
                            if (component.Timer2 > 0.06f)
                            {
                                component.Timer2 = 0;
                                float dd = ((float)component.Timer / wait - 0.5f) * 2f;
                                float bx = dd * 200f;
                                float by = dd * 100f;
                                DanmakuFactory.MakeDirBullet(scene, BulletType.EnemyShot, ed.body.X + bx, ed.body.Y + 100 + by, ed.playerBody.X, ed.playerBody.Y, speed, accel);
                                DanmakuFactory.MakeDirBullet(scene, BulletType.EnemyShot, ed.body.X - bx, ed.body.Y + 100 + by, ed.playerBody.X, ed.playerBody.Y, speed, accel);
                            }
                        }
                        else if (component.Type == EnemyType.Fuyu)
                        {
                            float wait  = 5f;
                            float speed = 4f;
                            float accel = 0.01f;
                            WaitPhase(ed, wait);
                            component.Timer2 += ed.seconds;
                            if (component.Timer2 > 0.12f)
                            {
                                component.Timer2 = 0;
                                float dd  = (float)component.Timer / wait * 0.8f;
                                float bx  = 0 + (body.X - 0) * dd;
                                float bx2 = Config.LevelWidth + (body.X - Config.LevelWidth) * dd;
                                float by  = -40;
                                DanmakuFactory.MakeDirBullet(scene, BulletType.FBlue, bx, by, bx, by + 1, speed, accel);
                                DanmakuFactory.MakeDirBullet(scene, BulletType.FBlue, bx2, by, bx2, by + 1, speed, accel);
                                DanmakuFactory.MakeDirBullet(scene, BulletType.FRed, ed.body.X, ed.body.Y, ed.playerBody.X, ed.playerBody.Y, speed, accel);
                            }
                        }
                        else
                        {
                            component.Phase = 2;
                        }
                        //DanmakuFactory.MakeBullet(scene, BulletType.EnemyShot, ed.body.X, ed.body.Y, ed.playerBody.X, ed.playerBody.Y, 3f);
                    }
                    else if (component.Phase == 2)
                    {
                        if (component.Type == EnemyType.Fuyu)
                        {
                            Random r = new Random();
                            component.TargetX = (float)r.NextDouble() * Config.LevelWidth;
                            component.TargetY = body.Y;
                            component.Phase   = 0;
                        }
                        component.Phase = 0;
                    }
                    else
                    {
                        Random r = new Random();
                        component.TargetX = (float)r.NextDouble() * Config.LevelWidth;
                        component.TargetY = (float)r.NextDouble() * Config.LevelHeight;
                        component.Phase   = 0;
                    }
                    UpdateSprite(ed);
                }
            }
        }
        public override void Update(GameTime gameTime)
        {
            sys.LevelScriptComponents.TryGetFirstEnabled(out LevelScriptComponent level);
            sys.SpriteComponents.TryGetByOwner("flash", out SpriteComponent flash);

            PlayerComponent component = sys.PlayerComponents.First();
            BodyComponent   body      = sys.BodyComponents.GetByOwner(component.Owner);
            SpriteComponent sprite    = sys.SpriteComponents.GetByOwner(component.Owner);

            component.Invuln -= (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (sys.RenderComponents.TryGetByOwner("hitbox", out RenderComponent hitbox))
            {
                if (InputManager.Held(GameCommand.Action3))
                {
                    hitbox.Enabled = true;
                }
                else
                {
                    hitbox.Enabled = false;
                }
            }

            Vector2 d = new Vector2(0, 0);

            if (InputManager.Held(GameCommand.Up))
            {
                d.Y -= 1;
            }
            if (InputManager.Held(GameCommand.Down))
            {
                d.Y += 1;
            }
            if (InputManager.Held(GameCommand.Left))
            {
                d.X -= 1;
            }
            if (InputManager.Held(GameCommand.Right))
            {
                d.X += 1;
            }
            if (d.Y != 0 || d.X != 0)
            {
                d.Normalize();
            }
            if (InputManager.Held(GameCommand.Action3))
            {
                d *= 2f;
            }
            else
            {
                d *= 6f;
            }
            body.DX = d.X;
            body.DY = d.Y;
            if (d.X < 0)
            {
                sprite.CurrentAnimation = "left";
            }
            else if (d.X > 0)
            {
                sprite.CurrentAnimation = "right";
            }
            else
            {
                sprite.CurrentAnimation = "still";
            }

            if (component.Timer > 0)
            {
                component.Timer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (level.Story == null)
            {
                float holdTime = 0.2f;
                if (component.SpecialState < 3)
                {
                    if (InputManager.JustPressed(GameCommand.Action2) && component.Bombs > 0)
                    {
                        component.SpecialState  = 4;
                        component.SpecialTimer  = 0f;
                        component.SpecialTimer2 = 0f;
                        component.Bombs--;
                        flash.Owner.Enable();
                    }
                    else if (InputManager.JustPressed(GameCommand.Action1))
                    {
                        component.SpecialTimer = 0f;
                    }
                    else if (InputManager.Held(GameCommand.Action1))
                    {
                        component.SpecialTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    if (component.SpecialTimer > 0f && component.SpecialTimer < holdTime && (!InputManager.Held(GameCommand.Action1) || component.SpecialState > 0))
                    {
                        component.SpecialState++;
                        component.SpecialTimer2 = 0f;
                        if (component.SpecialState == 2 && component.Wealth >= 0.5f)
                        {
                            //DanmakuFactory.MakeBullet(scene, 0, body.X, body.Y - 30, 0, -14);
                            //component.SpecialState = 0;
                            component.SpecialState = 3;
                        }
#if DEBUG
                        else if (component.SpecialState == 2)
                        {
                            component.Wealth       = 0.5f;
                            component.SpecialState = 3;
                            flash.Owner.Enable();
                            flash.Color             = Color.Transparent;
                            component.SpecialTimer2 = 0f;
                            component.Power        += 0.25f;
                        }
#endif
                        component.SpecialTimer = 0f;
                    }
                }

                if (component.SpecialState > 0 && component.SpecialState < 3)
                {
                    component.SpecialTimer2 += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (component.SpecialTimer2 >= holdTime)
                    {
                        component.SpecialState = 0;
                    }
                }
                // Power Shot / Wealth
                if (component.SpecialState == 3)
                {
                    component.SpecialTimer  += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    component.SpecialTimer2 += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    float alpha = Math.Min(component.SpecialTimer2 / 6, 0.2f);
                    flash.Color = new Color(alpha, alpha, 0, alpha);
                    if (component.SpecialTimer > 0.1f)
                    {
                        component.SpecialTimer = 0f;
                        component.Wealth      -= 0.05f;
                        Random r = new Random();
                        DanmakuFactory.MakeBullet(scene, BulletType.PowerShot, body.X + ((float)r.NextDouble() - 0.5f) * 40f, body.Y - 30 + ((float)r.NextDouble() - 0.5f) * 40f, 0, -14);
                        DanmakuFactory.MakeBullet(scene, BulletType.PowerShot, body.X + ((float)r.NextDouble() - 0.5f) * 40f, body.Y - 30 + ((float)r.NextDouble() - 0.5f) * 40f, 0, -14);
                        DanmakuFactory.MakeBullet(scene, BulletType.PowerShot, body.X + ((float)r.NextDouble() - 0.5f) * 40f, body.Y - 30 + ((float)r.NextDouble() - 0.5f) * 40f, 0, -14);
                        if (component.Wealth < 0f)
                        {
                            component.Wealth       = 0f;
                            component.SpecialState = 0;
                            component.SpecialTimer = 0f;
                            flash.Owner.Disable();
                        }
                    }
                }
                // Bomb
                if (component.SpecialState >= 4)
                {
                    float alpha = Math.Abs(component.SpecialTimer2 - 0.5f) - 0.5f;
                    if (component.SpecialState == 4 && component.SpecialTimer2 < 0.5f || component.SpecialState == 8 && component.SpecialTimer2 > 0.5f)
                    {
                        alpha = alpha * alpha * 4f * (0.25f / 5f + 0.125f);
                    }
                    else
                    {
                        alpha = alpha * alpha / 5 + 0.125f;
                    }
                    flash.Color             = new Color(alpha, alpha, alpha, alpha);
                    component.SpecialTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (component.SpecialTimer > 0.02f)
                    {
                        component.SpecialTimer = 0f;
                        Vector2 point1, point2;
                        switch (component.SpecialState)
                        {
                        case 4:
                            point1 = starPoint1;
                            point2 = starPoint2;
                            break;

                        case 5:
                            point1 = starPoint2;
                            point2 = starPoint3;
                            break;

                        case 6:
                            point1 = starPoint3;
                            point2 = starPoint4;
                            break;

                        case 7:
                            point1 = starPoint4;
                            point2 = starPoint5;
                            break;

                        default:
                            point1 = starPoint5;
                            point2 = starPoint1;
                            break;
                        }
                        float  x = point1.X + (point2.X - point1.X) * component.SpecialTimer2;
                        float  y = point1.Y + (point2.Y - point1.Y) * component.SpecialTimer2;
                        Random r = new Random();
                        //DanmakuFactory.MakeBullet(scene, 0, x, y, ((float)r.NextDouble() - 0.5f) * 1f, ((float)r.NextDouble() - 0.5f) * 1f);
                        DanmakuFactory.MakeStar(scene, x, y);
                        DanmakuFactory.MakeSlash(scene, 2, x, y);
                        DanmakuFactory.MakeSlash(scene, 2, x, y);
                        if (component.SpecialTimer2 >= 1f)
                        {
                            component.SpecialState++;
                            component.SpecialTimer2 = 0f;
                            if (component.SpecialState > 8)
                            {
                                component.SpecialState = 0;
                                flash.Owner.Disable();
                            }
                        }
                        else
                        {
                            component.SpecialTimer2 += 0.1f;
                        }
                    }
                }
                if (InputManager.Held(GameCommand.Action1) && component.SpecialState < 3 && component.SpecialTimer >= holdTime / 2)
                {
                    if (component.Timer <= 0)
                    {
                        int x = 12;
                        component.Alternate = (component.Alternate + 1) % 16;
                        bool odd = !(component.Alternate % 2 == 0);
                        //bool odd2 = !(component.Alternate / 2 % 2 == 0);
                        if (odd)
                        {
                            x = -x;
                        }
                        DanmakuFactory.MakeBullet(scene, BulletType.PlayerShot, body.X + x, body.Y - 30, 0, -11);
                        component.Timer = 0.16f;
                    }
                    component.Timer2 += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    float loop = 0.48f - component.Power * 0.36f;
                    if (component.Timer2 > loop)
                    {
                        component.Alternate2 = (component.Alternate2 + 1) % 2;
                        bool odd2 = component.Alternate2 == 0;
                        if (odd2)
                        {
                            DanmakuFactory.MakeBullet(scene, BulletType.HomingShot, body.X + 15, body.Y - 30, 1.5f, -7);
                        }
                        else
                        {
                            DanmakuFactory.MakeBullet(scene, BulletType.HomingShot, body.X - 15, body.Y - 30, -1.5f, -7);
                        }
                        component.Timer2 = 0f;
                    }
                }
            }
            else
            {
                // TODO: Crappy instant cutoff when story starts.
                component.SpecialState = 0;
                component.SpecialTimer = 0;
                flash.Owner.Disable();
            }
        }
Beispiel #4
0
        void ProgressLevel(LevelScriptComponent level, LevelScript levelScript)
        {
            List <string> lines = levelScript.Lines;

            while (level.Progress < lines.Count)
            {
                //level.Owner.Scene.GS.Error.DebugPrint(lines[level.Progress]);
                string[] line = lines[level.Progress].Split(' ');
                if (line.Length < 1)
                {
                    level.Progress++;
                    continue;
                }
                switch (line[0])
                {
                case "loop":
                    level.LoopPoint = level.Progress + 1;
                    break;

                case "repeat":
                    level.Progress = level.LoopPoint;     // TODO: This can cause an infinite loop.
                    level.Progress++;
                    continue;

                case "leave":
                    foreach (EnemyComponent enemy in sys.EnemyComponents.EnabledList)
                    {
                        enemy.Phase = -1;
                    }
                    break;

                case "clear":
                    foreach (BulletComponent bullet in sys.BulletComponents.EnabledList)
                    {
                        if (bullet.Type > BulletType.Items)
                        {
                            bullet.Owner.Delete();
                        }
                    }
                    foreach (EnemyComponent enemy in sys.EnemyComponents.EnabledList)
                    {
                        enemy.Owner.Delete();
                    }
                    break;
                }
                if (line.Length < 2)
                {
                    level.Progress++;
                    continue;
                }
                switch (line[0])
                {
                case "summon":
                    Random r  = new Random();
                    float  x  = (float)r.NextDouble() * Config.LevelWidth;
                    float  y  = (float)r.NextDouble() * Config.LevelHeight / 2 + 20;
                    float  x2 = Config.LevelWidth / 2;
                    float  y2 = Config.LevelHeight * 1 / 4;
                    if (line[1] == "fairy")
                    {
                        DanmakuFactory.MakeEnemy(scene, EnemyType.Fairy, x, 0, x, y);
                    }
                    else if (line[1] == "brave_fairy")
                    {
                        DanmakuFactory.MakeEnemy(scene, EnemyType.BraveFairy, x, 0, x, y);
                    }
                    else if (line[1] == "moneybag")
                    {
                        float x3;
                        if (x > Config.LevelWidth / 2)
                        {
                            x3 = 0 - 50;
                        }
                        else
                        {
                            x3 = Config.LevelWidth + 50;
                        }
                        DanmakuFactory.MakeEnemy(scene, EnemyType.MoneyBag, x3, y, x, y);
                    }
                    else if (line[1] == "yoshika")
                    {
                        DanmakuFactory.MakeEnemy(scene, EnemyType.Yoshika, x2, -75, x2, y2);
                    }
                    else if (line[1] == "fuyu")
                    {
                        DanmakuFactory.MakeEnemy(scene, EnemyType.Fuyu, x2, -75, x2, y2);
                    }
                    else if (line[1] == "joon")
                    {
                        DanmakuFactory.MakeEnemy(scene, EnemyType.Joon, x2, -75, x2, y2);
                    }
                    else if (line[1] == "shion")
                    {
                        DanmakuFactory.MakeEnemy(scene, EnemyType.Shion, x2, -75, x2, y2);
                    }
                    break;

                case "wait":
                    if (line[1] == "clear")
                    {
                        level.WaitMode = LevelWaitMode.Clear;
                        level.Progress++;
                        return;
                    }
                    else if (line[1] == "leave")
                    {
                        level.WaitMode = LevelWaitMode.Leave;
                        level.Progress++;
                        return;
                    }
                    else if (float.TryParse(line[1], out float time))
                    {
                        level.WaitMode  = LevelWaitMode.Timer;
                        level.WaitTimer = time;
                        level.Progress++;
                        return;
                    }
                    break;

                case "talk":
                    //sys.GetGameState().Request(lines[level.Progress]);
                    //scene.AddScene(SceneFactory.NewTalkScene(gs, "talk", line[1])).Enable();
                    level.Story         = gs.ResourceManager.Stories.Get(line[1]);
                    level.StoryProgress = -1;
                    level.WaitMode      = LevelWaitMode.Forever;
                    level.Progress++;
                    return;

                case "level":
                    level.Level     = gs.ResourceManager.LevelScripts.Get(line[1]);
                    level.Progress  = 0;
                    level.LoopPoint = 0;
                    level.WaitMode  = LevelWaitMode.Start;
                    return;

                case "music":
                    if (line[1] == "stop")
                    {
                        SoundManager.StopMusic();
                        break;
                    }
                    SoundManager.PlayMusic(line[1]);
                    break;

                case "sound":
                    if (line.Length == 3 && line[2] == "stop")
                    {
                        SoundManager.StopSound(line[1]);
                    }
                    else
                    {
                        SoundManager.PlaySound(line[1]);
                    }
                    break;
                }
                level.Progress++;
            }

            // Reached end of script with no remaining action. Go dormant.
            level.Level     = null;
            level.Progress  = 0;
            level.WaitMode  = LevelWaitMode.Start;
            level.LoopPoint = 0;
            return;
        }
 void DamageEnemy(PlayerComponent player, EnemyComponent enemy, BodyComponent body, BulletComponent component, int mode = 0)
 {
     if (enemy.Shield != null)
     {
         if (component != null && component.Type != BulletType.PowerShot)
         {
             //component.Owner.Delete();
             if (body.DY < 0)
             {
                 body.DY = -body.DY / 2;
             }
             Random r = new Random();
             body.DX        = (float)(r.NextDouble() - 0.5) * 5f;
             component.Type = BulletType.BG;
             return;
         }
     }
     if (mode == 0)
     {
         DanmakuFactory.MakeSlash(scene, 0, body.X, body.Y);
     }
     if (enemy.Type == EnemyType.MoneyBag)
     {
         DanmakuFactory.MakeCoin(scene, body.X, body.Y);
     }
     if (component != null)
     {
         component.Owner.Delete();
         if (enemy.Shield != null)
         {
             enemy.ShieldHealth -= component.Power;
             sys.SpriteComponents.GetByOwner(enemy.Shield).Scale = (enemy.ShieldHealth + 200) / 300;
             if (enemy.ShieldHealth <= 0)
             {
                 enemy.Shield.Delete();
                 enemy.Shield = null;
             }
         }
         else
         {
             enemy.Health -= component.Power;
         }
     }
     if (mode == 1 && enemy.Shield == null)
     {
         enemy.Health -= 30f;
     }
     if (enemy.Health <= 0)
     {
         enemy.Lives--;
         if (enemy.Lives > 0)
         {
             AddShield(enemy);
             enemy.Health = enemy.MaxHealth;
         }
         else
         {
             if (enemy.Type == EnemyType.MoneyBag)
             {
                 DanmakuFactory.MakeCoin(scene, body.X, body.Y);
                 DanmakuFactory.MakeCoin(scene, body.X, body.Y);
                 DanmakuFactory.MakeCoin(scene, body.X, body.Y);
                 DanmakuFactory.MakeCoin(scene, body.X, body.Y);
                 DanmakuFactory.MakeCoin(scene, body.X, body.Y);
                 DanmakuFactory.MakeCoin(scene, body.X, body.Y);
             }
             else
             {
                 DanmakuFactory.MakePointItem(scene, body.X, body.Y);
                 DanmakuFactory.MakePointItem(scene, body.X, body.Y);
                 DanmakuFactory.MakePointItem(scene, body.X, body.Y);
                 DanmakuFactory.MakePowerItem(scene, body.X, body.Y);
                 DanmakuFactory.MakePowerItem(scene, body.X, body.Y);
                 DanmakuFactory.MakePowerItem(scene, body.X, body.Y);
             }
             enemy.Owner.Delete();
             player.Score += 50;
         }
     }
     else
     {
         player.Score += 1;
         //player.Power += 0.1f;
     }
 }
        public override void Update(GameTime gameTime)
        {
            sys.PlayerComponents.TryGetFirstEnabled(out PlayerComponent player);
            //BodyComponent playerBody = sys.BodyComponents.GetByOwner(player.Owner);

            timer += gameTime.ElapsedGameTime.TotalSeconds;
            if (timer > 0.2)
            {
                timer -= 0.2;
                float x  = (float)r.NextDouble() * Config.LevelWidth;
                float dy = (float)r.NextDouble() * 3 + 1;
                //DanmakuFactory.MakeBullet(scene, BulletType.BG, x, 0, 0, dy);
            }

            /*
             * timer2 += gameTime.ElapsedGameTime.TotalSeconds;
             * if (timer2 > 2)
             * {
             *  timer2 -= 2;
             *  float x = (float)r.NextDouble() * Config.LevelWidth;
             *  float y = (float)r.NextDouble() * Config.LevelHeight / 2 + 20;
             *  DanmakuFactory.MakeEnemy(scene, 0, x * 1.5f, -32, x * 0.8f, y);
             * }
             */

            foreach (BodyComponent component in sys.BodyComponents.EnabledList)
            {
                component.X  += component.DX;
                component.Y  += component.DY;
                component.DX += component.DDX;
                component.DY += component.DDY;

                if (component.Pen != Vector4.Zero)
                {
                    float x  = component.Pen.X * Config.LevelWidth;
                    float y  = component.Pen.Y * Config.LevelHeight;
                    float x2 = component.Pen.Z * Config.LevelWidth;
                    float y2 = component.Pen.W * Config.LevelHeight;
                    if (component.Owner.HasTag("player"))
                    {
                        if (component.X < x || component.X > x2)
                        {
                            sys.SpriteComponents.TryGetByOwner(component.Owner, out SpriteComponent sprite);
                            sprite.CurrentAnimation = "still";
                        }
                    }
                    if (component.X < x)
                    {
                        component.X = x;
                    }
                    if (component.X > x2)
                    {
                        component.X = x2;
                    }
                    if (component.Y < y)
                    {
                        component.Y = y;
                    }
                    if (component.Y > y2)
                    {
                        component.Y = y2;
                    }
                }

                float margin = component.DeathMargin;
                if (margin > 0)
                {
                    if (component.X < -margin || component.X > Config.LevelWidth + margin ||
                        component.Y < -margin || component.Y > Config.LevelHeight + margin)
                    {
                        component.Owner.Delete();
                        continue;
                    }
                }

                if (component.Lifespan > 0)
                {
                    component.Age += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (component.Age >= component.Lifespan)
                    {
                        component.Owner.Delete();
                        continue;
                    }
                }

                if (sys.RenderComponents.TryGetEnabled(component.Owner, out RenderComponent renderComponent))
                {
                    renderComponent.X = component.X;
                    renderComponent.Y = component.Y;
                }
            }

            if (player.SpecialState >= 4 && player.SpecialTimer == 0f && player.SpecialTimer2 == 0f)
            {
                foreach (EnemyComponent enemy in sys.EnemyComponents.EnabledList)
                {
                    BodyComponent body = sys.BodyComponents.GetByOwner(enemy.Owner);
                    DamageEnemy(player, enemy, body, null, 1);
                }
            }

            foreach (BulletComponent component in sys.BulletComponents.EnabledList)
            {
                BodyComponent body = sys.BodyComponents.GetByOwner(component.Owner);
                // Check for collisions.
                if (component.Type >= BulletType.EnemyShot && player.SpecialState >= 4)
                {
                    //DanmakuFactory.MakeSlash(scene, 1, body.X, body.Y);
                    component.Owner.Delete();
                    continue;
                }
                float radius = sys.SpriteComponents.GetByOwner(component.Owner).Sprite.CollisionBox.Radius;
                if (component.Type == BulletType.Coin && body.Y > Config.LevelHeight && body.DY > 0)
                {
                    body.DY        = -body.DY * 0.5f;
                    component.Type = BulletType.Coin2;
                }
                if (component.Type == BulletType.Coin || component.Type == BulletType.Coin2)
                {
                    if (body.X < 0 && body.DX < 0)
                    {
                        body.DX = -body.DX;
                    }
                    if (body.X > Config.LevelWidth && body.DX > 0)
                    {
                        body.DX = -body.DX;
                    }
                }
                if (body.X > -radius && body.X < Config.LevelWidth + radius &&
                    body.Y > -radius && body.Y < Config.LevelHeight + radius)
                {
                    if (component.Type <= BulletType.Items && component.Type > BulletType.BG)
                    {
                        BodyComponent targetBody      = sys.BodyComponents.GetByOwner(player.Owner);
                        float         targetRadius    = 100;
                        float         targetRadius2   = sys.SpriteComponents.GetByOwner(player.Owner).Sprite.CollisionBox.Radius;
                        float         dx              = targetBody.X - body.X;
                        float         dy              = targetBody.Y - body.Y;
                        float         dd              = radius + targetRadius;
                        float         dd2             = radius + targetRadius2;
                        float         distanceSquared = dx * dx + dy * dy;
                        if (distanceSquared < dd2 * dd2)
                        {
                            if (component.Type == BulletType.PointItem)
                            {
                                player.Point += 1;
                            }
                            else if (component.Type == BulletType.PowerItem)
                            {
                                player.Power += 0.05f;
                            }
                            else
                            {
                                player.Wealth += 0.05f;
                            }
                            component.Owner.Delete();
                            continue;
                        }
                        if (distanceSquared < dd * dd)
                        {
                            //body.DX = body.DX * 0.7f;
                            //body.DY = body.DY * 0.7f;
                            float speed    = 8f;
                            float distance = (float)Math.Sqrt(distanceSquared) / speed;
                            body.DX = body.DX + (dx / distance - body.DX) * 0.3f;
                            body.DY = body.DY + (dy / distance - body.DY) * 0.3f;
                            continue;
                        }
                        else if (component.Type == BulletType.PointItem || component.Type == BulletType.PowerItem)
                        {
                            body.DX = body.DX * (1 - 0.08f);
                            body.DY = body.DY + (4f - body.DY) * 0.08f;
                        }
                    }
                    if (component.Type == BulletType.PlayerShot || component.Type == BulletType.PowerShot || component.Type == BulletType.HomingShot)
                    {
                        foreach (EnemyComponent enemy in sys.EnemyComponents.EnabledList)
                        {
                            BodyComponent targetBody   = sys.BodyComponents.GetByOwner(enemy.Owner);
                            float         targetRadius = sys.SpriteComponents.GetByOwner(enemy.Owner).Sprite.CollisionBox.Radius;
                            if (enemy.Shield != null)
                            {
                                targetRadius = 100;
                            }
                            float dx = targetBody.X - body.X;
                            float dy = targetBody.Y - body.Y;
                            float dd = radius + targetRadius;
                            float distanceSquared = dx * dx + dy * dy;
                            if (distanceSquared < dd * dd)
                            {
                                DamageEnemy(player, enemy, body, component);
                                continue;
                            }
                        }
                    }
                    if (component.Type >= BulletType.EnemyShot)
                    {
                        BodyComponent targetBody      = sys.BodyComponents.GetByOwner(player.Owner);
                        float         targetRadius    = sys.SpriteComponents.GetByOwner(player.Owner).Sprite.CollisionBox.Radius;
                        float         dx              = targetBody.X - body.X;
                        float         dy              = targetBody.Y - body.Y;
                        float         dd              = radius + targetRadius;
                        float         distanceSquared = dx * dx + dy * dy;
                        if (distanceSquared < dd * dd)
                        {
                            DanmakuFactory.MakeSlash(scene, 1, body.X, body.Y);
                            component.Owner.Delete();
                            if (player.Invuln <= 0)
                            {
                                player.Lives--;
                                BodyComponent playerBody = sys.BodyComponents.GetByOwner(player.Owner);
                                playerBody.X  = Config.LevelWidth / 2;;
                                playerBody.Y  = Config.LevelHeight * 3 / 4;
                                player.Invuln = 1;
                                if (player.Lives < 0)
                                {
                                    player.Lives = 5;
                                    sys.LevelScriptComponents.TryGetFirst(out LevelScriptComponent level);
                                    level.Progress = level.LoopPoint;
                                    foreach (BulletComponent bullet in sys.BulletComponents.EnabledList)
                                    {
                                        if (bullet.Type > BulletType.Items)
                                        {
                                            bullet.Owner.Delete();
                                        }
                                    }
                                    foreach (EnemyComponent enemy in sys.EnemyComponents.EnabledList)
                                    {
                                        enemy.Owner.Delete();
                                    }
                                }
                            }
                            continue;
                        }
                    }
                }
            }

            player.Power  = Math.Min(Math.Max(player.Power, 0), 1);
            player.Wealth = Math.Min(Math.Max(player.Wealth, 0), 1);
        }