Esempio n. 1
0
        private void movePaddes()
        {
            Invoke(new MethodInvoker(delegate
            {
                //Process input from the IR sensor in the range 8 to 30
                //Translate it to movement from of the paddles
                //8 to 19   -> translate to y positions of 0   to 165
                //20 to 30  -> translate to y positions of 166 to 330
                reAnalog1 = (int)analog1;
                reAnalog2 = (int)analog2;
                reAnalog1 = (reAnalog1 - 8) * (165 / 11);
                reAnalog2 = (reAnalog2 - 8) * (165 / 11);
                if (reAnalog1 > 330)
                {
                    reAnalog1 = 330;
                }
                if (reAnalog2 > 330)
                {
                    reAnalog2 = 330;
                }

                this.pictureBox1.Location = new System.Drawing.Point(12, reAnalog1);
                this.pictureBox2.Location = new System.Drawing.Point(503, reAnalog2);
                DisplayPanel.Refresh();
            }));
        }
Esempio n. 2
0
 private void UpdateFrame()
 {
     Invoke(new MethodInvoker(delegate
     {
         //textBox1.Text = textToDisplay;
         textBox1.Enabled = false;
         DisplayPanel.Refresh();
     }));
 }
Esempio n. 3
0
        public AlternatePongExperiment()
        {
            InitializeComponent();


            sensors = new DistanceSensors();
            sensors.DistancesChanged += new DistanceSensors.DistancesChangedHandler(sensors_DistancesChanged);
            sensors.Connect();

            sound1 = new SoundPlayer("sounds/pong.wav"); sound1.Load();
            sound2 = new SoundPlayer("sounds/pong2.wav"); sound2.Load();
            sound3 = new SoundPlayer("sounds/pong3.wav"); sound3.Load();

            paddle1   = 0.5f; paddle2 = 0.5f;
            ball      = new PointF(DisplayPanel.Width / 2, DisplayPanel.Height / 2);
            rand      = new Random();
            ballSpeed = new PointF((rand.NextDouble() <= 0.5 ? -1 : 1) * BALL_SPEED_FACTOR, (float)(rand.NextDouble() * 2 * BALL_SPEED_FACTOR) - BALL_SPEED_FACTOR);

            Task.Factory.StartNew(() =>
            {
                DateTime startTime = DateTime.Now;
                ballStartTimer     = BALL_START_TIMER;
                while (!IsDisposed)
                {
                    try
                    {
                        DateTime currTime = DateTime.Now;
                        UpdatePositions((float)(currTime - startTime).TotalSeconds);
                        Invoke(new MethodInvoker(delegate { DisplayPanel.Refresh(); }));
                        startTime = currTime;
                        Thread.Sleep(20);
                    }
                    catch { }
                }
            });
        }
Esempio n. 4
0
 private void frm_Load(object sender, EventArgs e)
 {
     DisplayPanel.Refresh();
     Paint();
 }