Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Some suggestion
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Reality Check




PostPosted: Tue Jun 03, 2008 6:27 pm   Post subject: 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 Razz ). 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.


P.java
 Description:

Download
 Filename:  P.java
 Filesize:  743 Bytes
 Downloaded:  136 Time(s)


Pbox.java
 Description:

Download
 Filename:  Pbox.java
 Filesize:  694 Bytes
 Downloaded:  97 Time(s)


Particle1.java
 Description:
main class

Download
 Filename:  Particle1.java
 Filesize:  4.73 KB
 Downloaded:  148 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Reality Check




PostPosted: Tue Jun 03, 2008 6:35 pm   Post subject: Re: Some suggestion

Aw man I probably should have commented this thing...well just ask if you guys need clarification on anything.
Reality Check




PostPosted: Wed Jun 04, 2008 2:00 pm   Post subject: 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




PostPosted: Wed Jun 04, 2008 2:42 pm   Post subject: RE:Some suggestion

Better code style. Indenting and spacing is just weird in your code.
wtd




PostPosted: Wed Jun 04, 2008 2:54 pm   Post subject: RE:Some suggestion

Java:
// 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




PostPosted: Wed Jun 04, 2008 4:02 pm   Post subject: 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




PostPosted: Wed Jun 04, 2008 8:42 pm   Post subject: 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:
code:

int main()
{ //it's on a new line
  string yourMom = "hot";
  if ( yourMom == "hot" )
  { //new line
    cout << "Sweet!";
  }
  else //all on new lines
  {
    cout << "Sucks for you!";
  }
  return 0;
}


Just a suggestion.
wtd




PostPosted: Thu Jun 05, 2008 1:18 am   Post subject: RE:Some suggestion

It's generally against the current to use that style with Java code.
Sponsor
Sponsor
Sponsor
sponsor
Reality Check




PostPosted: Thu Jun 05, 2008 7:16 am   Post subject: Re: Some suggestion

I actually prefer it the more conventional way. It just looks better to me but if I do it that way, my teacher will deduct marks for indentation. He wants it done the ready to program way so I am forced to use the F2 command. Not much I can do about that...
wtd




PostPosted: Thu Jun 05, 2008 11:51 am   Post subject: RE:Some suggestion

Tell a school administrator that your teacher is making you do things in a way that is clearly wrong?
Reality Check




PostPosted: Thu Jun 05, 2008 11:52 am   Post subject: Re: Some suggestion

He is our school admin...lol.

Yea my school doesn't have a very good CS program.
jeffgreco13




PostPosted: Thu Jun 05, 2008 12:10 pm   Post subject: Re: Some suggestion

Hooray for counter-production.

I only got 79% in my CS class in high school because I chose to develop good habits rather than what my poser of a comp sci teach wanted.

Programming is like creative writing, you develop a style and stick to it....

but at the same time if you need help you should make it as plausible as possible to others lol Razz
Reality Check




PostPosted: Thu Jun 05, 2008 12:23 pm   Post subject: Re: Some suggestion

While I do not agree with his teachings (he's barely touched on methods and objects and I highly doubt we'll ever even touch things such as inheritance or polymorphism) I am not prepared to go against his convention rule at the deduction of marks. I'd like to get the CS award at the school and while it may develop bad habits for the other students in my class, I'm pretty sure it won't effect me since I know the proper conventions and can easily revert to them after I am done gr12.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: