Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
AnswerRe: Collision detection between a circle and rectangle Pin
Abhinav S29-Apr-12 16:36
Abhinav S29-Apr-12 16:36 
GeneralRe: Collision detection between a circle and rectangle Pin
lethula30-Apr-12 13:20
lethula30-Apr-12 13:20 
AnswerRe: Collision detection between a circle and rectangle Pin
BobJanova29-Apr-12 23:18
BobJanova29-Apr-12 23:18 
GeneralRe: Collision detection between a circle and rectangle Pin
lethula30-Apr-12 13:27
lethula30-Apr-12 13:27 
GeneralRe: Collision detection between a circle and rectangle Pin
BobJanova30-Apr-12 22:19
BobJanova30-Apr-12 22:19 
GeneralRe: Collision detection between a circle and rectangle Pin
lethula1-May-12 22:17
lethula1-May-12 22:17 
GeneralRe: Collision detection between a circle and rectangle Pin
BobJanova2-May-12 0:46
BobJanova2-May-12 0:46 
GeneralRe: Collision detection between a circle and rectangle Pin
lethula2-May-12 8:36
lethula2-May-12 8:36 
hi, here is how i tried putting all this in code. and i got the error
{"Object reference not set to an instance of an object."}
Im sure that has something to do with my code here it is
C#
public class Ball
   {
       Player square;
       public float x, y, yvel, radius;
       public Brush brush;
       public Ball(int gameWidth,int gameHeight,Random r)

       {

           x = r.Next(gameWidth);
           y = r.Next(gameHeight);

           yvel = r.Next(2) + 2;

           radius = r.Next(10) + 5;
           brush = new SolidBrush(Color.Blue);

       }

       public void Move(int gameHeight)
       {
           //Part that moves the circle verticall across the screen
           if (y + radius >= gameHeight - 315)
           {
               y = 0;
           }
           y += yvel;
           //This is where collision function is called
           if ((y + radius) > gameHeight - 315 && collision(square))
           {
               MessageBox.Show("Collision");

           }

       }

       public void Draw(Graphics g)
       {

           g.FillEllipse(brush, new RectangleF(x-radius,y - radius, radius * 2, radius * 2));

       }


       //The part for checking collision between the circle and the square. The square radius and height is 15
       public bool collision(Player player)
       {
           float X = (x - (player.x + 15));

           float Y = y - (player.y + 15);

           return (!(-(radius + 15) < X || X < (radius + 15) || -(radius + 15) < Y || Y < (radius + 15)));


       }

   }

GeneralRe: Collision detection between a circle and rectangle Pin
BobJanova3-May-12 0:30
BobJanova3-May-12 0:30 
QuestionHow to get video frames from usb cam buffer Pin
bunyamin_28-Apr-12 22:58
bunyamin_28-Apr-12 22:58 
Questionhow to Encrypting Class Library Pin
jojoba201128-Apr-12 17:55
jojoba201128-Apr-12 17:55 
AnswerRe: how to Encrypting Class Library Pin
Richard MacCutchan28-Apr-12 21:28
mveRichard MacCutchan28-Apr-12 21:28 
AnswerRe: how to Encrypting Class Library Pin
OriginalGriff28-Apr-12 21:45
mveOriginalGriff28-Apr-12 21:45 
AnswerRe: how to Encrypting Class Library Pin
jschell29-Apr-12 6:20
jschell29-Apr-12 6:20 
GeneralRe: how to Encrypting Class Library Pin
BobJanova29-Apr-12 23:11
BobJanova29-Apr-12 23:11 
GeneralRe: how to Encrypting Class Library Pin
jschell30-Apr-12 8:04
jschell30-Apr-12 8:04 
AnswerRe: how to Encrypting Class Library Pin
harold aptroot29-Apr-12 6:43
harold aptroot29-Apr-12 6:43 
QuestionHow to draw two parallel curves with variable width? Pin
Adnan Yaseen28-Apr-12 13:44
Adnan Yaseen28-Apr-12 13:44 
AnswerRe: How to draw two parallel curves with variable width? Pin
RobCroll28-Apr-12 15:16
RobCroll28-Apr-12 15:16 
GeneralRe: How to draw two parallel curves with variable width? Pin
Adnan Yaseen29-Apr-12 1:41
Adnan Yaseen29-Apr-12 1:41 
GeneralRe: How to draw two parallel curves with variable width? Pin
RobCroll29-Apr-12 12:20
RobCroll29-Apr-12 12:20 
QuestionMoving an object on the form using keyboard Pin
Qobacha27-Apr-12 22:13
Qobacha27-Apr-12 22:13 
AnswerRe: Moving an object on the form using keyboard Pin
OriginalGriff27-Apr-12 23:24
mveOriginalGriff27-Apr-12 23:24 
JokeRe: Moving an object on the form using keyboard Pin
Richard MacCutchan27-Apr-12 23:27
mveRichard MacCutchan27-Apr-12 23:27 
GeneralRe: Moving an object on the form using keyboard Pin
OriginalGriff27-Apr-12 23:30
mveOriginalGriff27-Apr-12 23:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.