コード例 #1
0
        public override void update(GameTime gameTime)
        {
            MouseState msState       = Mouse.GetState();
            Point      mousePosition = new Point(msState.X, msState.Y);

            #region Particle Mashine
            int    dy = (int)(2.5f * Math.Sin(gameTime.TotalGameTime.TotalMilliseconds / 200));
            Random r  = new Random();
            for (int i = 0; i < 150; i++)
            {
                ParticleMashine.Particle p1 = particleMashine.particles[i];
                if (p1.l <= 0.1)
                {
                    p1.p = new Vector2(viewport.Width / 2, viewport.Height / 2 - 75); p1.s = 3 + (int)(3 * r.NextDouble()); p1.l = 13;
                    p1.c = Color.Red;
                }
                p1.p.X = viewport.Width / 2 + (float)Math.Sin(gameTime.TotalGameTime.TotalMilliseconds / 700) * 200 + (float)r.NextDouble() * 20 * p1.v.X;
                p1.p.Y = viewport.Height / 2 + (float)Math.Cos(gameTime.TotalGameTime.TotalMilliseconds / 700) * 200 + (float)r.NextDouble() * 20 * p1.v.Y + dy;
                p1.v.X = -3 + 6.0f * (float)r.NextDouble();
                p1.v.Y = -2f + 4.0f * (float)r.NextDouble();
                p1.l  -= 0.02f + 0.9f * (float)r.NextDouble();
                p1.c   = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());

                particleMashine.particles[i] = p1;
            }
            #endregion

            #region Interference
            if (gameTime.TotalGameTime.TotalMilliseconds - lastTime > 100)
            {
                Color[] arr = new Color[200 * 200];
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = Color.Black;
                }
                Random a = new Random();
                for (int t = 0; t < 10; t++)
                {
                    int y = (int)((interferenceTexture.Height - 3) * a.NextDouble());
                    for (int i = 0; i < interferenceTexture.Width; i++)
                    {
                        for (int j = y; j < y + 2; j++)
                        {
                            arr[j * interferenceTexture.Width + i] = new Color(50, 50, 50, (int)(250 * a.NextDouble()));
                        }
                    }
                }
                interferenceTexture.SetData(arr);
                lastTime = gameTime.TotalGameTime.TotalMilliseconds;
            }
            #endregion
        }
コード例 #2
0
        public void Update(GameTime gametime, Vector2 direction, Viewport viewport)
        {
            if (game.mousePos.X > game.Window.ClientBounds.Width / 2)
            {
                flip = false;
            }
            else if (game.mousePos.X < game.Window.ClientBounds.Width / 2)
            {
                flip = true;
            }
            if (!flip)
            {
                RectangleCollide = new Rectangle(Rectangle.X, Rectangle.Y, Rectangle.Width - Rectangle.Width / 3, Rectangle.Height);
            }
            else
            {
                RectangleCollide = new Rectangle(Rectangle.X + 60, Rectangle.Y, Rectangle.Width - Rectangle.Width / 3, Rectangle.Height);
            }
            float elapsed = (float)gametime.ElapsedGameTime.TotalSeconds;

            direction.Y = -direction.Y;

            Viewport = viewport;
            scale    = ((float)Viewport.Height / 3 / texture.Height);

            Vector2 distance = direction * Speed * elapsed;

            Position += distance;
            score     = Math.Max(score, (int)(Position.Y * 10));
            highscore = Math.Max(highscore, score);

            #region Particle Mashine
            Random r = new Random();
            for (int i = 0; i < pmS.count; i++)
            {
                ParticleMashine.Particle ps = pmS.particles[i];
                if (ps.l <= 0.1)
                {
                    if (!flip)
                    {
                        ps.p.X = 30 + Viewport.Width / 2 - Viewport.Width / 18 + (float)r.NextDouble() * Viewport.Width / 16;
                    }
                    else
                    {
                        ps.p.X = 90 + Viewport.Width / 2 - Viewport.Width / 18 + (float)r.NextDouble() * Viewport.Width / 16;
                    }
                    ps.p.Y = Viewport.Height / 2 + 80;
                    ps.s   = 16 + (int)(32 * r.NextDouble());
                    ps.c   = new Color(Color.LightGray, 155 + (int)(100 * r.NextDouble()));
                    ps.l   = 8;
                }

                ps.p.X          += ps.v.X; ps.p.Y += ps.v.Y;
                ps.v.X           = -10 + 20 * (float)r.NextDouble() - 10 * direction.X * (float)r.NextDouble();
                ps.v.Y           = 5 + 2 * direction.Y * (float)r.NextDouble();
                ps.l            -= (float)r.NextDouble();
                pmS.particles[i] = ps;
            }

            for (int i = 0; i < pmF.count; i++)
            {
                ParticleMashine.Particle pf = pmF.particles[i];
                if (pf.l <= 0.1)
                {
                    if (!flip)
                    {
                        pf.p.X = 30 + Viewport.Width / 2 - Viewport.Width / 18 + (float)r.NextDouble() * Viewport.Width / 16;
                    }
                    else
                    {
                        pf.p.X = 90 + Viewport.Width / 2 - Viewport.Width / 18 + (float)r.NextDouble() * Viewport.Width / 16;
                    }
                    pf.p.Y = Viewport.Height / 2 + 100;
                    pf.s   = 10 + (int)(20 * r.NextDouble());
                    pf.c   = new Color(Color.Red, 55 + (int)(200 * r.NextDouble()));
                    pf.l   = 8;
                }

                pf.p.X          += pf.v.X; pf.p.Y += pf.v.Y;
                pf.v.X           = -5 + 10 * (float)r.NextDouble() - 5 * direction.X * (float)r.NextDouble();
                pf.v.Y           = 3 - direction.Y * (float)r.NextDouble();
                pf.l            -= (float)r.NextDouble();
                pmF.particles[i] = pf;
            }

            #endregion
        }
コード例 #3
0
        public override void update(GameTime gameTime)
        {
            MouseState msState       = Mouse.GetState();
            Point      mousePosition = new Point(msState.X, msState.Y);

            #region Particle Mashine
            int    dy = (int)(2.5f * Math.Sin(gameTime.TotalGameTime.TotalMilliseconds / 200));
            Random r  = new Random();
            for (int i = 0; i < 150; i++)
            {
                ParticleMashine.Particle p1 = particleMashine1.particles[i];
                ParticleMashine.Particle p2 = particleMashine2.particles[i];
                ParticleMashine.Particle p3 = particleMashine3.particles[i];
                ParticleMashine.Particle p4 = particleMashine4.particles[i];
                ParticleMashine.Particle p5 = particleMashine5.particles[i];
                ParticleMashine.Particle p6 = particleMashine6.particles[i];
                ParticleMashine.Particle p7 = particleMashine7.particles[i];
                if (p1.l <= 0.1)
                {
                    p1.p = new Vector2(viewport.Width / 2, viewport.Height / 2 - 75); p1.s = 3 + (int)(3 * r.NextDouble()); p1.l = 13;
                    p1.c = Color.Red;
                }
                if (p2.l <= 0.1)
                {
                    p2.p = new Vector2(viewport.Width / 2, viewport.Height / 2 - 52); p2.s = 3 + (int)(3 * r.NextDouble()); p2.l = 13;
                    p2.c = Color.Orange;
                }
                if (p3.l <= 0.1)
                {
                    p3.p = new Vector2(viewport.Width / 2, viewport.Height / 2 - 25); p3.s = 3 + (int)(3 * r.NextDouble()); p3.l = 13;
                    p3.c = Color.Yellow;
                }

                if (p4.l <= 0.1)
                {
                    p4.p = new Vector2(viewport.Width / 2, viewport.Height / 2); p4.s = 3 + (int)(3 * r.NextDouble()); p4.l = 13;
                    p4.c = Color.Green;
                }

                if (p5.l <= 0.1)
                {
                    p5.p = new Vector2(viewport.Width / 2, viewport.Height / 2 + 25); p5.s = 3 + (int)(3 * r.NextDouble()); p5.l = 13;
                    p5.c = Color.DeepSkyBlue;
                }
                if (p6.l <= 0.1)
                {
                    p6.p = new Vector2(viewport.Width / 2, viewport.Height / 2 + 50); p6.s = 3 + (int)(3 * r.NextDouble()); p6.l = 13;
                    p6.c = Color.Blue;
                }
                if (p7.l <= 0.1)
                {
                    p7.p = new Vector2(viewport.Width / 2, viewport.Height / 2 + 75); p7.s = 3 + (int)(3 * r.NextDouble()); p7.l = 13;
                    p7.c = Color.DarkViolet;
                }

                p1.p.X += p1.v.X; p1.p.Y += p1.v.Y + dy;
                p1.v.X  = -6 - 2.0f * (float)r.NextDouble();
                p1.v.Y  = -2f + 4.0f * (float)r.NextDouble();
                p1.l   -= 0.02f + 0.9f * (float)r.NextDouble();

                p2.p.X += p2.v.X; p2.p.Y += p2.v.Y + dy;
                p2.v.X  = -6 - 2.0f * (float)r.NextDouble();
                p2.v.Y  = -2f + 4.0f * (float)r.NextDouble();
                p2.l   -= 0.02f + 0.9f * (float)r.NextDouble();

                p3.p.X += p3.v.X; p3.p.Y += p3.v.Y + dy;
                p3.v.X  = -6 - 2.0f * (float)r.NextDouble();
                p3.v.Y  = -2f + 4.0f * (float)r.NextDouble();
                p3.l   -= 0.02f + 0.9f * (float)r.NextDouble();

                p4.p.X += p4.v.X; p4.p.Y += p4.v.Y + dy;
                p4.v.X  = -6 - 2.0f * (float)r.NextDouble();
                p4.v.Y  = -2f + 4.0f * (float)r.NextDouble();
                p4.l   -= 0.02f + 0.9f * (float)r.NextDouble();

                p5.p.X += p5.v.X; p5.p.Y += p5.v.Y + dy;
                p5.v.X  = -6 - 2.0f * (float)r.NextDouble();
                p5.v.Y  = -2f + 4.0f * (float)r.NextDouble();
                p5.l   -= 0.02f + 0.9f * (float)r.NextDouble();

                p6.p.X += p6.v.X; p6.p.Y += p6.v.Y + dy;
                p6.v.X  = -6 - 2.0f * (float)r.NextDouble();
                p6.v.Y  = -2f + 4.0f * (float)r.NextDouble();
                p6.l   -= 0.02f + 0.9f * (float)r.NextDouble();

                p7.p.X += p7.v.X; p7.p.Y += p7.v.Y + dy;
                p7.v.X  = -6 - 2.0f * (float)r.NextDouble();
                p7.v.Y  = -2f + 4.0f * (float)r.NextDouble();
                p7.l   -= 0.02f + 0.9f * (float)r.NextDouble();

                particleMashine1.particles[i] = p1;
                particleMashine2.particles[i] = p2;
                particleMashine3.particles[i] = p3;
                particleMashine4.particles[i] = p4;
                particleMashine5.particles[i] = p5;
                particleMashine6.particles[i] = p6;
                particleMashine7.particles[i] = p7;
            }
            #endregion

            #region Interference
            if (gameTime.TotalGameTime.TotalMilliseconds - lastTime > 100)
            {
                Color[] arr = new Color[200 * 200];
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = Color.Black;
                }
                Random a = new Random();
                for (int t = 0; t < 10; t++)
                {
                    int y = (int)((interferenceTexture.Height - 3) * a.NextDouble());
                    for (int i = 0; i < interferenceTexture.Width; i++)
                    {
                        for (int j = y; j < y + 2; j++)
                        {
                            arr[j * interferenceTexture.Width + i] = new Color(50, 50, 50, (int)(250 * a.NextDouble()));
                        }
                    }
                }
                interferenceTexture.SetData(arr);
                lastTime = gameTime.TotalGameTime.TotalMilliseconds;
            }
            #endregion

            KeyboardState kbState = Keyboard.GetState();
            if (kbState.IsKeyDown(Keys.Enter) && !oldKbState.IsKeyDown(Keys.Enter))
            {
                game.changeLayoutTo(new GameLayout(game, playerSkinNum));
            }
            else if (oldKbState.IsKeyDown(Keys.Enter))
            {
            }
        }