Page 1 of 1 [ 4 posts ] 


Are c# Gods sent?
Y 67%  67%  [ 2 ]
N 33%  33%  [ 1 ]
Total votes : 3

Autisttypid
Tufted Titmouse
Tufted Titmouse

User avatar

Joined: 14 Sep 2007
Gender: Male
Posts: 49
Location: Aarhus

19 Sep 2007, 9:45 am

using System;


//////////////////////////////////////////////////////////////////
///checkBallCollision : Check for a collision with another ball
///
///In : ball2 - the ball to check collision with
///
///Return : True if there was a collision with another ball
//////////////////////////////////////////////////////////////////
bool Ball::checkBallCollision(ball &ball2)
{
///The radius of the balls
int radius1 = diameter / 2;
int radius2 = ball2.diameter / 2;

///The center point of the first ball
POINT center1;
center1.x = radius1 + bounds.left;
center1.y = radius1 + bounds.top;

///The center point of the second ball
POINT center2;
center2.x = radius2 + ball2.bounds.left;
center2.y = radius2 + ball2.bounds.top;

///The distance between the two balls' center
double distance = sqrt(SQUARE(center2.x - center1.x) +
SQUARE(center2.y - center1.y));

///See if thay have collided
if ( distance <= radius1 + radius2)
return true;
return false;
}


_________________
+----------------------+
| ____ __ __ ___ |
+|_ _| | |_| | |__|+
| |_| |_|_|_| |__ |
+----------------------+


Fuzzy
Veteran
Veteran

User avatar

Joined: 30 Mar 2006
Age: 52
Gender: Male
Posts: 5,223
Location: Alberta Canada

23 Sep 2007, 6:08 am

Whats that got to do with bill gates?



Autisttypid
Tufted Titmouse
Tufted Titmouse

User avatar

Joined: 14 Sep 2007
Gender: Male
Posts: 49
Location: Aarhus

23 Sep 2007, 3:04 pm

Fuzzy wrote:
Whats
! !! (--) ! !!
If you have to ask, this is c++ code in an c# shell
Fuzzy wrote:
that got to do
Hopefully this shut work
Fuzzy wrote:
with
But it doesent
Fuzzy wrote:
bill gates?
And there are no chance of so...right now


_________________
+----------------------+
| ____ __ __ ___ |
+|_ _| | |_| | |__|+
| |_| |_|_|_| |__ |
+----------------------+


Last edited by Autisttypid on 24 Sep 2007, 6:54 am, edited 1 time in total.

-Main
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 10 May 2007
Age: 36
Gender: Male
Posts: 69

24 Sep 2007, 2:48 am

Quote:
bool Ball::checkBallCollision(ball &ball2)


I don't think '::' is allowed in method names in C#. I assume it's something from C++.

Also, for this to even have a chance of working, I'm assuming:
1) That there's a ball class, that this code is a member of, that defines diameter and bounds as properties of the ball class.
2) That you've written you own code for SQUARE and POINT, and named them with all caps (because C# is case-sensitive and .NET code uses CamelCase for everything), as well as defined sqrt. You should really be using 'Math.Sqrt'.