示例#1
0
文件: Game1.cs 项目: ivanoreh/Ripply
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            Touches = TouchPanel.GetState();

            simulator.BeginWrite();

            simulator.SetSourcePosition(-Vector2.One * 2);
            if (Touches.Count > 0)
            {
                HandleInput(Mode);
            }

            //add rain
            //simulator.Write(Pixel, new Rectangle(random.Next(0, simulator.Width), random.Next(0, simulator.Height), 1, 1), new Color(1, 0, 0, 1), WriteMode.Height);

            simulator.EndWrite();

            simulator.Simulate(1f / 120, 4);

            base.Update(gameTime);
        }
示例#2
0
文件: Game1.cs 项目: ivanoreh/Ripply
        private void HandleInput(WriteMode mode)
        {
            simulator.BeginWrite();

            var pos = mouse.Position * simulator.Width / graphics.PreferredBackBufferWidth;

            //point
            if (mouse.LeftClick)
            {
                simulator.SetSourcePosition(pos);
            }
            else
            {
                simulator.SetSourcePosition(Vector2.One * -10);
            }
            if (mouse.RightClick)
            {
                simulator.Write(Pixel, new Rectangle((int)pos.X - 20, (int)pos.Y - 20, 40, 40), WriteMode.Clear);
            }

            //clear
            if (keyboard.KeyPressed(Keys.R))
            {
                simulator.ClearField();
            }

            //half-circle
            if (keyboard.Key(Keys.C))
            {
                simulator.Write(Circle, pos - Vector2.One * Circle.Width / 2, mode);
            }

            //square
            if (keyboard.Key(Keys.S))
            {
                simulator.Write(Pixel, new Rectangle((int)pos.X, (int)pos.Y, 5, 5), mode);
            }

            //horizontal
            if (keyboard.Key(Keys.H))
            {
                simulator.Write(Pixel, new Rectangle((int)pos.X, (int)pos.Y, 200, 2), mode);
            }

            //vertical
            if (keyboard.Key(Keys.V))
            {
                simulator.Write(Pixel, new Rectangle((int)pos.X, (int)pos.Y, 2, 200), mode);
            }

            simulator.EndWrite();
        }