Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows Phone
Hi all;
 
I'm make the Windows Phone Application.But I can't used to Accelerometer.
 
I want make this program in the Windows Phone.
http://oyunda.mynet.com/topu-kacir
 

Blue Ball is move with Accelerometer and I used to this code;
if (e.X < 0 && blue_ball.Margin.Left > 0)
                blue_ball.Margin = new Thickness(blue_ball.Margin.Left + e.X * 1.7, blue_ball.Margin.Top, blue_ball.Margin.Right, blue_ball.Margin.Bottom);
            else if (e.X > 0 && blue_ball.Margin.Left < ContentPanel.Width - blue_ball.Width)
                blue_ball.Margin = new Thickness(blue_ball.Margin.Left + e.X * 1.7, blue_ball.Margin.Top, blue_ball.Margin.Right, blue_ball.Margin.Bottom);
 
            if (e.Y < 0 && blue_ball.Margin.Top < ContentPanel.Height - blue_ball.Height)
                blue_ball.Margin = new Thickness(blue_ball.Margin.Left, blue_ball.Margin.Top + (-e.Y * 1.7), blue_ball.Margin.Right, blue_ball.Margin.Bottom);
            else if (e.Y > 0 && blue_ball.Margin.Top > 0)
                blue_ball.Margin = new Thickness(blue_ball.Margin.Left, blue_ball.Margin.Top + (-e.Y * 1.7), blue_ball.Margin.Right, blue_ball.Margin.Bottom);
 
RedBall is move random in Grid.
 
How can I determine collision with Red and Blue ball?
Posted 13-Dec-12 10:10am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

private bool CheckCollision(FrameworkElement ctl1,FrameworkElement ctl2) 
{ 
     bool retval = false; 
     Point ptTopLeft = new Point(Convert.ToDouble(ctl1.GetValue(Canvas.LeftProperty)), Convert.ToDouble(ctl1.GetValue(Canvas.TopProperty))); 
     Point ptBottomRight = new Point(Convert.ToDouble(ctl1.GetValue(Canvas.LeftProperty)) + ctl1.Width, Convert.ToDouble(ctl1.GetValue(Canvas.TopProperty)) + ctl1.Height); 
     Rect r1 = new Rect(ptTopLeft, ptBottomRight); 
 
    //System.Diagnostics.Debug.WriteLine("+++x:" + ptTopLeft.X.ToString() + " Y " + ptTopLeft.Y.ToString() + " " + ptBottomRight.X.ToString() + " " + ptBottomRight.Y.ToString()); 

    Point ptTopLeft2 = new Point(Convert.ToDouble(ctl2.GetValue(Canvas.LeftProperty)), Convert.ToDouble(ctl2.GetValue(Canvas.TopProperty))); 
 
    Point ptBottomRight2 = new Point(Convert.ToDouble(ctl2.GetValue(Canvas.LeftProperty)) + ctl2.Width, Convert.ToDouble(ctl2.GetValue(Canvas.TopProperty)) + ctl2.Height); 
 
    Rect r2 = new Rect(ptTopLeft2, ptBottomRight2); 
 
    r1.Intersect(r2); 
    if (!r1.IsEmpty) 
    { 
       retval = true; 
    } 
    return retval; 
} 
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Zoltán Zörgő 265
1 /\jmot 205
2 CHill60 145
3 Peter Leow 145
4 Sergey Alexandrovich Kryukov 115
0 Sergey Alexandrovich Kryukov 9,353
1 OriginalGriff 6,881
2 Peter Leow 4,577
3 Zoltán Zörgő 4,129
4 Richard MacCutchan 2,882


Advertise | Privacy | Mobile
Web01 | 2.8.150129.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100