public MainPage() { InitializeComponent(); // // Multitouch TUIO / Standard Win 7 / Silverlight3 Multitouch / Mouse mapped as a single touch // _touchlistener = new TouchListener(LayoutRoot); // // Micrososft Kinect / PrimeSense Sensor - based on OpenNI NITE middleware // _kinectlistener = new KinectListener(LayoutRoot); Kinect.SetKinectListener(_kinectlistener.MIGListener as MIG.Client.Devices.NiteKinect.Kinect); // // Nintendo Wii Remote - based on MonoWiiUse included in monoMIG project // _wiiremotelistener = new WiiRemoteListener(LayoutRoot); WiiRemote.SetWiiRemoteListener(_wiiremotelistener.MIGListener as MIG.Client.Devices.Wii.Remote); // _migclient = new MIGClient(); _migclient.AddListener("MT0", _touchlistener.MIGListener); _migclient.AddListener("KN0", _kinectlistener.MIGListener); _migclient.AddListener("WI0", _wiiremotelistener.MIGListener); _migclient.Connect(); // Gallery.PhotoList.ElementTapped += new MIRIA.UIKit.ScrollView.ElementTappedHandler(PhotoList_ElementTapped); // Gallery.ButtonClose.Tapped += new MIRIA.UIKit.TButton.TappedHandler(ApplicationButtonClose_Tapped); MultiScaleDemo.ButtonClose.Tapped += new MIRIA.UIKit.TButton.TappedHandler(ApplicationButtonClose_Tapped); VirtualEarth.ButtonClose.Tapped += new MIRIA.UIKit.TButton.TappedHandler(ApplicationButtonClose_Tapped); Kinect.ButtonClose.Tapped += new MIRIA.UIKit.TButton.TappedHandler(ApplicationButtonClose_Tapped); WiiRemote.ButtonClose.Tapped += new MIRIA.UIKit.TButton.TappedHandler(ApplicationButtonClose_Tapped); Leggimi.ButtonClose.Tapped += new MIRIA.UIKit.TButton.TappedHandler(LeggimiButtonClose_Tapped); ContactsAndLinks.ButtonClose.Tapped += new MIRIA.UIKit.TButton.TappedHandler(ContactsAndLinksClose_Tapped); }
public Page() { InitializeComponent(); // set width / height this.Width = Double.Parse(System.Windows.Browser.HtmlPage.Document.Body.GetProperty("clientWidth").ToString()); this.Height = Double.Parse(System.Windows.Browser.HtmlPage.Document.Body.GetProperty("clientHeight").ToString()); // we get a reference to the main canvas and add the Canvas maincanvas = (Canvas)this.FindName("Main"); // myCanvas.Background = new SolidColorBrush(Colors.White); // and then we instantiate a new Touch Listener on our main Canvas // so that contained objects can receive events from // multitouch and/or mouse input _wiimotelistener = new Remote(); //maincanvas); _wiimotelistener.AccelerationUpdate += new Remote.AccelerationUpdateHandler(_wiimotelistener_AccelerationUpdate); //new TouchListener.AccelerationUpdateHandler(multiTouchInput_AccelerationUpdate); // _migclient = new MIGClient(); _migclient.ServiceReady += new MIGClient.ServiceReadyHandler(_migclient_ServiceReady); _migclient.AddListener("WII0", _wiimotelistener); _migclient.Connect(); // _cursor = (Canvas)maincanvas.FindName("cursor"); _cursortr = new TransformHelper(_cursor); // _cursor.TransformHelper; _cursortr.Delay = 2.0; _cursortr.Translate = new Point((this.Width / 2) - 100, (this.Height) - 50); Point _balldirection = new Point(3, 6); Ellipse _ball = (Ellipse)maincanvas.FindName("ball"); TransformHelper _balltr = new TransformHelper(_ball); _balltr.Delay = 0.0; TextBlock _scoreText = (TextBlock)maincanvas.FindName("score"); _scoreText.Width = this.Width; int _score = 0; DispatcherTimer _timer = new DispatcherTimer(); _timer.Tick += (sender2, e2) => { _balltr.Translate = new Point(_balltr.Translate.X + _balldirection.X, _balltr.Translate.Y + _balldirection.Y); if (_balltr.Translate.X <= 0) { _balldirection.X = -_balldirection.X; } else if (_balltr.Translate.X + 50 >= this.Width) { _balldirection.X = -_balldirection.X; } if (_balltr.Translate.Y <= 0) { _balldirection.Y = -_balldirection.Y; } else if (_balltr.Translate.Y + 50 >= this.Height) { //_balldirection.Y = -_balldirection.Y; _balltr.Translate = new Point(_balltr.Translate.X, 1); _score = 0; _balldirection = new Point(5, 5); } IEnumerable<UIElement> hits = VisualTreeHelper.FindElementsInHostCoordinates(new Point(_balltr.Translate.X + 25, _balltr.Translate.Y + 50), this); foreach (UIElement uiel in hits) { if (uiel.Equals(_cursor)) { _balltr.Translate = new Point(_balltr.Translate.X + _balldirection.X, _balltr.Translate.Y - _balldirection.Y); _balldirection = new Point(_balldirection.X * 1.025, _balldirection.Y * 1.025); _balldirection.Y = -_balldirection.Y; _score += 10; } } _scoreText.Text = _score + ""; }; _timer.Interval = new TimeSpan(0, 0, 0, 0, 5); _timer.Start(); }