private void ThunderAnimation() { UI.Element elementByName = null; Form_Fidget squareCnt = this; squareCnt.SquareCnt = squareCnt.SquareCnt + 1; Form_Fidget redCnt = this; redCnt.RedCnt = redCnt.RedCnt + 1; Form_Fidget blueCnt1 = this; blueCnt1.BlueCnt1 = blueCnt1.BlueCnt1 + 1; Form_Fidget blueCnt2 = this; blueCnt2.BlueCnt2 = blueCnt2.BlueCnt2 + 1; if (this.FireAniEn) { Form_Fidget fireButtonCnt = this; fireButtonCnt.FireButtonCnt = fireButtonCnt.FireButtonCnt + 1; } if (this.SquareCnt == 8) { elementByName = this.myUI.GetElementByName("Square1"); elementByName.isDisplayFore = false; elementByName = this.myUI.GetElementByName("Square2"); elementByName.isDisplayFore = false; elementByName = this.myUI.GetElementByName("Square3"); elementByName.isDisplayFore = false; } else if (this.SquareCnt == 16) { elementByName = this.myUI.GetElementByName("Square1"); elementByName.isDisplayFore = false; elementByName = this.myUI.GetElementByName("Square2"); elementByName.isDisplayFore = false; elementByName = this.myUI.GetElementByName("Square3"); elementByName.isDisplayFore = true; } else if (this.SquareCnt == 24) { elementByName = this.myUI.GetElementByName("Square1"); elementByName.isDisplayFore = false; elementByName = this.myUI.GetElementByName("Square2"); elementByName.isDisplayFore = true; elementByName = this.myUI.GetElementByName("Square3"); elementByName.isDisplayFore = true; } else if (this.SquareCnt >= 32) { elementByName = this.myUI.GetElementByName("Square1"); elementByName.isDisplayFore = true; elementByName = this.myUI.GetElementByName("Square2"); elementByName.isDisplayFore = true; elementByName = this.myUI.GetElementByName("Square3"); elementByName.isDisplayFore = true; this.SquareCnt = 0; } if (this.FireButtonCnt == this.SpeedCnt) { elementByName = this.myUI.GetElementByName("Fire"); elementByName.ImageForeground = this.FirePic1; elementByName.isDisplayFore = true; } else if (this.FireButtonCnt == this.SpeedCnt * 2) { elementByName = this.myUI.GetElementByName("Fire"); elementByName.ImageForeground = this.FirePic2; elementByName.isDisplayFore = true; } else if (this.FireButtonCnt == this.SpeedCnt * 3) { elementByName = this.myUI.GetElementByName("Fire"); elementByName.ImageForeground = this.FirePic3; elementByName.isDisplayFore = true; } else if (this.FireButtonCnt >= this.SpeedCnt * 4) { elementByName = this.myUI.GetElementByName("Fire"); elementByName.ImageForeground = this.FirePic0; elementByName.isDisplayFore = false; this.FireButtonCnt = 0; } if (this.RedCnt > this.RedRandCnt) { elementByName = this.myUI.GetElementByName("RedRect1"); elementByName.isDisplayFore = !elementByName.isDisplayFore; this.RedCnt = 0; if (elementByName.isDisplayFore) { this.RedRandCnt = this.Rand.Next(20, 50); } else { this.RedRandCnt = this.Rand.Next(10, 20); } } if (this.BlueCnt1 > this.BlueRandCnt1) { elementByName = this.myUI.GetElementByName("BlueRect1"); elementByName.isDisplayFore = !elementByName.isDisplayFore; this.BlueCnt1 = 0; if (elementByName.isDisplayFore) { this.BlueRandCnt1 = this.Rand.Next(30, 70); } else { this.BlueRandCnt1 = this.Rand.Next(5, 20); } } if (this.BlueCnt2 > this.BlueRandCnt2) { elementByName = this.myUI.GetElementByName("BlueRect2"); elementByName.isDisplayFore = !elementByName.isDisplayFore; this.BlueCnt2 = 0; if (elementByName.isDisplayFore) { this.BlueRandCnt2 = this.Rand.Next(50, 120); } else { this.BlueRandCnt2 = this.Rand.Next(5, 10); } } this.myUI.myPictureBox.Invalidate(); }
private void CMDHandle(byte[] Data) { byte num; num = (this.VersionProfile != 1 ? Data[1] : Data[2]); this.Current_Status = num; if (this.Firing && (num & 16) == 16) { this.DelayStop = true; this.timerCnt = 0; } if (this.Fired && (num & 16) == 0) { Form_Fidget fireTimeCnt = this; fireTimeCnt.FireTimeCnt = fireTimeCnt.FireTimeCnt + 1; if (this.FireTimeCnt > 25) { this.myUI.GetElementByName("Fire").isDisplayFore = false; this.myUI.myPictureBox.Invalidate(); this.Fired = false; } } if (this.ReSet) { if (this.ReSet_Status == 0) { if ((num & 1) == 1) { this.ReSet_Status = 2; } else { this.SendUSBData(this.DOWN); this.CurrentAction = Form_Fidget.STATUS.DOWN_LIMIT; this.ReSet_Status = 1; this.ResetTimeout = 0; } } if (this.ReSet_Status == 1 && (num & 1) == 1) { this.ReSet_Status = 2; this.ResetTimeout = 0; } if (this.ReSet_Status == 2) { if ((num & 4) == 4) { this.ReSet_Status = 4; } else { this.SendUSBData(this.LEFT); this.CurrentAction = Form_Fidget.STATUS.LEFT_LIMIT; this.ReSet_Status = 3; this.ResetTimeout = 0; } } if (this.ReSet_Status == 3 && (num & 4) == 4) { this.ReSet_Status = 4; this.ResetTimeout = 0; } if (this.ReSet_Status == 4) { this.ReSet_Status = 5; this.SendUSBData(this.RIGHT); this.CurrentAction = Form_Fidget.STATUS.RIGHT_LIMIT; this.start = DateTime.Now; this.ResetTimeout = 0; } if (this.ReSet_Status == 5 && (num & 8) == 8) { this.ReSet_Status = 6; this.Horizon = DateTime.Now.Subtract(this.start); this.Horizon = TimeSpan.FromMilliseconds(this.Horizon.TotalMilliseconds / 2 * 0.9); this.ResetTimeout = 0; } if (this.ReSet_Status == 6) { this.ReSet_Status = 7; this.SendUSBData(this.LEFT); this.CurrentAction = Form_Fidget.STATUS.LEFT_LIMIT; this.ResetTimeout = 0; } if (this.ReSet_Status == 7 && (num & 4) == 4) { this.ReSet_Status = 8; this.start = DateTime.Now; this.SendUSBData(this.RIGHT); this.CurrentAction = Form_Fidget.STATUS.RIGHT_LIMIT; this.ResetTimeout = 0; } if (this.ReSet_Status == 8) { this.stop = DateTime.Now.Subtract(this.start); if (this.stop > this.Horizon) { this.ReSet_Status = 9; this.SendUSBData(this.UP); this.CurrentAction = Form_Fidget.STATUS.UP_LIMIT; this.start = DateTime.Now; this.ResetTimeout = 0; } } if (this.ReSet_Status == 9 && (num & 2) == 2) { this.ReSet_Status = 10; this.Vertical = DateTime.Now.Subtract(this.start); this.Vertical = TimeSpan.FromMilliseconds(this.Vertical.TotalMilliseconds / 2); this.ResetTimeout = 0; } if (this.ReSet_Status == 10) { this.ReSet_Status = 11; this.SendUSBData(this.DOWN); this.CurrentAction = Form_Fidget.STATUS.DOWN_LIMIT; this.ResetTimeout = 0; } if (this.ReSet_Status == 11 && (num & 1) == 1) { this.ReSet_Status = 12; this.start = DateTime.Now; this.SendUSBData(this.UP); this.CurrentAction = Form_Fidget.STATUS.UP_LIMIT; this.ResetTimeout = 0; } if (this.ReSet_Status == 12) { this.stop = DateTime.Now.Subtract(this.start); if (this.stop > this.Vertical) { this.SendUSBData(this.STOP); this.CurrentAction = Form_Fidget.STATUS.FIRED; this.ResetTimeout = 0; this.ReSet = false; this.ReSeted = true; } } } }
private void KeyHandle(bool IsDown, KeyEventArgs e) { UI.Element elementByName = null; if (!IsDown) { this.Action = false; this.CurrentAction = Form_Fidget.STATUS.IDLE; if (!this.Firing && !this.nFire && !this.ReSet && !this.Calibrate) { switch (e.KeyCode) { case Keys.Left: { elementByName = this.myUI.GetElementByName("Left"); break; } case Keys.Up: { this.UpPress = false; elementByName = this.myUI.GetElementByName("Up"); break; } case Keys.Right: { elementByName = this.myUI.GetElementByName("Right"); break; } case Keys.Down: { this.DownPress = false; elementByName = this.myUI.GetElementByName("Down"); break; } } if (elementByName != null) { if (this.SoundOn) { this.Wavplayer.Stop(); } elementByName.isDisplayFore = false; this.myUI.myPictureBox.Invalidate(); } this.SendUSBData(this.STOP); DateTime now = DateTime.Now; this.TestTime[this.TestTimeCnt] = now.Subtract(this.start); Form_Fidget testTimeCnt = this; testTimeCnt.TestTimeCnt = testTimeCnt.TestTimeCnt + 1; if (this.TestTimeCnt >= 10) { this.TestTimeCnt = 0; } } } else { Keys keyCode = e.KeyCode; if (keyCode != Keys.Return) { switch (keyCode) { case Keys.Space: { if (!this.Firing && !this.Fired && !this.nFire && !this.ReSet && this.DevicePresent) { if (this.SoundOn) { this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "firing.wav"); this.Wavplayer.PlayLooping(); } elementByName = this.myUI.GetElementByName("Fire"); this.Firing = true; this.FireCheck = false; this.FireTimeout = 0; this.SendUSBData(this.FIRE); this.FireCnt = 0; this.FireAniEn = true; this.SpeedCnt = 2; } this.Action = true; break; } case Keys.Left: { if ((this.Current_Status & 4) != 4 && !this.Firing && !this.Fired && !this.Action && !this.ReSet && this.DevicePresent) { Thread.Sleep(100); this.Action = true; elementByName = this.myUI.GetElementByName("Left"); if (this.SoundOn) { this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav"); this.Wavplayer.PlayLooping(); } this.SendUSBData(this.LEFT); this.CurrentAction = Form_Fidget.STATUS.LEFT_LIMIT; } this.Action = true; break; } case Keys.Up: { if ((this.Current_Status & 2) != 2 && !this.Firing && !this.Fired && !this.Action && !this.ReSet && this.DevicePresent) { this.UpPress = true; this.UpCnt = 0; this.Action = true; elementByName = this.myUI.GetElementByName("Up"); if (this.SoundOn) { this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav"); this.Wavplayer.PlayLooping(); } this.SendUSBData(this.UP); Thread.Sleep(40); this.SendUSBData(this.STOP); this.start = DateTime.Now; this.CurrentAction = Form_Fidget.STATUS.UP_LIMIT; } this.Action = true; break; } case Keys.Right: { if ((this.Current_Status & 8) != 8 && !this.Firing && !this.Fired && !this.Action && !this.ReSet && this.DevicePresent) { Thread.Sleep(100); this.Action = true; elementByName = this.myUI.GetElementByName("Right"); if (this.SoundOn) { this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav"); this.Wavplayer.PlayLooping(); } this.SendUSBData(this.RIGHT); this.CurrentAction = Form_Fidget.STATUS.RIGHT_LIMIT; } this.Action = true; break; } case Keys.Down: { if ((this.Current_Status & 1) != 1 && !this.Firing && !this.Fired && !this.Action && !this.ReSet && this.DevicePresent) { this.DownPress = true; this.DownCnt = 0; this.Action = true; elementByName = this.myUI.GetElementByName("Down"); if (this.SoundOn) { this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "move.wav"); this.Wavplayer.PlayLooping(); } this.SendUSBData(this.DOWN); Thread.Sleep(40); this.SendUSBData(this.STOP); this.start = DateTime.Now; this.CurrentAction = Form_Fidget.STATUS.DOWN_LIMIT; } this.Action = true; break; } } } if (elementByName != null) { elementByName.isDisplayFore = true; this.myUI.myPictureBox.Invalidate(); return; } } }
private void timer1_Tick(object sender, EventArgs e) { Point position = Cursor.Position; position.X = position.X - base.Left; position.Y = position.Y - (base.Top - 20); this.myUI.ShowToolTip(position); Form_Fidget formFidget = this; formFidget.timerCnt = formFidget.timerCnt + 1; if (this.timerCnt > 1) { this.timerCnt = 0; if (this.DelayStop) { this.DelayStop = false; this.SendUSBData(this.STOP); this.FireTimeCnt = 0; this.Firing = false; this.Fired = true; this.FireCheck = false; if (this.VersionProfile == 0) { if (this.SoundOn) { this.Wavplayer.Stop(); this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "fired.wav"); this.Wavplayer.Play(); } this.FireAniEn = false; this.FireButtonCnt = 1000; } else if (this.VersionProfile == 1 && this.SoundOn && (this.FireTimeout < 30 || this.FireTimeout > 125)) { this.Wavplayer.Stop(); } } if (this.Firing) { Form_Fidget fireTimeout = this; fireTimeout.FireTimeout = fireTimeout.FireTimeout + 1; if (this.FireTimeout < 15 && this.FireTimeout % 2 == 0) { this.SendUSBData(this.FIRE); } if (this.FireTimeout == 33 && this.VersionProfile == 1) { if (this.SoundOn) { this.Wavplayer.Stop(); this.Wavplayer.SoundLocation = Path.Combine(this.uiPath, "fired.wav"); this.Wavplayer.Play(); } this.FireAniEn = false; this.FireButtonCnt = 1000; } if (this.FireTimeout > 125) { this.DelayStop = true; } } if (this.ReSet) { Form_Fidget resetTimeout = this; resetTimeout.ResetTimeout = resetTimeout.ResetTimeout + 1; if (this.ResetTimeout > 1500) { this.CurrentAction = Form_Fidget.STATUS.FIRED; this.ReSet = false; this.ReSeted = true; } } if (this.ReSeted) { this.ReSeted = false; this.myUI.GetElementByName("Reset").isDisplayFore = false; this.myUI.myPictureBox.Invalidate(); } if (this.Firing || this.Fired || this.Action || this.ReSet) { this.SendUSBData(this.GET_STATUS); } } if (!this.Action) { bool reSet = this.ReSet; } bool firing = this.Firing; if (this.UpPress) { Form_Fidget upCnt = this; upCnt.UpCnt = upCnt.UpCnt + 1; if (this.UpCnt == 8) { this.SendUSBData(this.UP); } } if (this.DownPress) { Form_Fidget downCnt = this; downCnt.DownCnt = downCnt.DownCnt + 1; if (this.DownCnt == 8) { this.SendUSBData(this.DOWN); } } this.ThunderAnimation(); }