
-----------------------------------
Reality Check
Tue Jun 03, 2008 6:27 pm

Some suggestion
-----------------------------------
So I was playing around with some particle stuff and just physics and general and I made some random crap (isn't random crap the best kind of crap  :P ).  I have an ISU coming up (gr.12) in about two weeks and I thought I might as well make something out of this.  Firstly, any suggestions to improve my code?  Do the particles move too fast or is their motion flawed?  I know I haven't used buffer but that can easily be added in and I know the collision isn't perfect (just threw it together today).  Biggest thing though, any game suggestions based on this crap?  ISU is almost due and I'm too lazy to make something else.  The core for this is already made so I might as well use it.

-----------------------------------
Reality Check
Tue Jun 03, 2008 6:35 pm

Re: Some suggestion
-----------------------------------
Aw man I probably should have commented this thing...well just ask if you guys need clarification on anything.

-----------------------------------
Reality Check
Wed Jun 04, 2008 2:00 pm

Re: Some suggestion
-----------------------------------
So I made some improvements minor improvements:

Background is now black with random coloured boxes appearing.
The calculation for the velocity is improved (before the particles would get kind of crazy).  They are now more uniform (resembles a black whole I guess)
Your ball on string now starts with a size of 1 and grows as you consume more particles and eventually it explodes into particles (after a size of 150).
As your ball grows, more weight ofcourse is added to the string making it harder to whip the ball about.  

Still haven't really thought of a game though...

-----------------------------------
wtd
Wed Jun 04, 2008 2:42 pm

RE:Some suggestion
-----------------------------------
Better code style.  Indenting and spacing is just weird in your code.

-----------------------------------
wtd
Wed Jun 04, 2008 2:54 pm

RE:Some suggestion
-----------------------------------
// Your code.

public double angle(double x1, double y1, double x2, double y2) {
    double theta = 0;
	
    if (x1 == x2) {
        if (y2 > y1) {
            theta = 90;
        }
	else {
            theta = 270;
	}
    }
    else {
        theta = Math.toDegrees(Math.atan((y1 - y2) / (x1 - x2)));
	    
	if (x2 > x1) {
            if (y2 > y1) {
                theta += 360;
            }
        }
        else {
            theta += 180;
        }
    }
    
    return theta;
}

// Eliminate unnecessary nesting.

public double angle(double x1, double y1, double x2, double y2) {
    double theta = 0;
	
    if (x1 == x2) {
        if (y2 > y1) {
            theta = 90;
        }
	else {
            theta = 270;
	}
    }
    else {
        theta = Math.toDegrees(Math.atan((y1 - y2) / (x1 - x2)));
	    
	if (x2 > x1 && y2 > y1) {
            theta += 360;
        }
        else {
            theta += 180;
        }
    }
    
    return theta;
}

// Translate to ternary operator expression.

public double angle(double x1, double y1, double x2, double y2) {
    double theta = 0;
	
    if (x1 == x2) {
        if (y2 > y1) {
            theta = 90;
        }
	else {
            theta = 270;
	}
    }
    else {
        theta = Math.toDegrees(Math.atan((y1 - y2) / (x1 - x2)));
	    
	theta += (x2 > x1 && y2 > y1) ? 360 : 180;
    }
    
    return theta;
}

// Eliminate unnecessary addition as second step.

public double angle(double x1, double y1, double x2, double y2) {
    double theta = 0;
	
    if (x1 == x2) {
        if (y2 > y1) {
            theta = 90;
        }
	else {
            theta = 270;
	}
    }
    else {
        theta = Math.toDegrees(Math.atan((y1 - y2) / (x1 - x2))) + (x2 > x1 && y2 > y1) ? 360 : 180;
    }
    
    return theta;
}

// Use multiple exit points.

public double angle(double x1, double y1, double x2, double y2) {
    if (x1 == x2) {
        if (y2 > y1) {
            return 90;
        }
	else {
            return 270;
	}
    }
    else {
        return Math.toDegrees(Math.atan((y1 - y2) / (x1 - x2))) + (x2 > x1 && y2 > y1) ? 360 : 180;
    }
}

-----------------------------------
Reality Check
Wed Jun 04, 2008 4:02 pm

Re: Some suggestion
-----------------------------------
Oh the indenting is like that because I use Ready (my school forces me) and I just use their auto indent (f2).  Thanks for the suggestions though.  Does make my code look a lot cleaner.

-----------------------------------
michaelp
Wed Jun 04, 2008 8:42 pm

RE:Some suggestion
-----------------------------------
One thing that I like to do that I think adds to code cleanliness and readability is putting the braces on separate lines. 
Like this C++ thing:

int main()
{ //it's on a new line
  string yourMom = "hot";
  if ( yourMom == "hot" )
  { //new line
    cout 