please help with my program
i 'm trying to make a program in which objects(circles) will move around and follow 3 rules:
1. try to fly towards the centre of mass of neighbouring objects.
2. try to keep a small distance away from other objects.
3. try to match velocity with near objects.
the problem is that the objects don't move..
as i am new to java any ideas that might help would be appreciated!!!
Beastly Boids Boldy Blunder
I intended to work on this, have a full day ahead .... won't get much done on it today. HTH:
would seem to be moving the Boids and Beasts
b.currentDirection= b.currentDirection*(float)(0.45 * Math.PI/180);
current direction is += x/y ....
hmm,.. are you doing clean project and full rebuild?
sometimes there are boundary conditions that only show up on special casing like straight ahead and so on. The only fix is to pull short sections of code and do unit testing. This would have to focus on the results of Math.cosine() / sine() ... there are obscure compiler "optimizations" that are not even remotely optimizations, I have one of these I intend to get back to on a grapics UI where I coded probably ten lines to force the double or float to an int and got typing error.
Suggest try new Float(currentDirection).toInt();
which can be
or something like that.
Float nextPosition = new Float((Math.cos(currentDirection) * currentSpeed));
x += nextPosition.toInteger();
custom code looks bizzare.
It is normal to have bulky code and snip parts for posting, what helped? I looked at the code and seems to me it should run without having to do major modifications. Here's a few lines away from where I am talking about in my code:
I could tell it was not your original code, it has the hallmarks of sample code. Try taking a few lines and doing the System.out.println(value); approach in a modular fashion...gets things working better than any other approach.
// else, do some testing and set some reasonable size values if Dimensions sound screwy
/****** 2.71828 18284 59045 23536 ******/
ww = Math.min(screenSize.getWidth(),horzMax);
hh = Math.min(screenSize.getHeight(),vertMax);//
// ww and hh have been set but not used
www = (ww / 2.71828);// Gives pleasing scaling factor
hhh = (hh / 2.71828);// for Border Layout manager - 0.36787968862663154641905911090837
wwww = (ww - www );//
hhhh = (hh - hhh );//
super.setSize((Dimension)adjustedSize);// end fancy sizing
windowSize.setSize(super.getSize());// = ;
You find things like this:
and discover where your move() is going null on 0.00
Cyrus.this.pointGenerator = new Random(Seytem.currentTimeMillis());// ..
When and if you get to a commercial code shop, be SURE to make your comments a great deal clearer than what I have here. The comments here are solely a fast copy-paste buffer for me....the code is self documenting. That only comes from writing a lot of code,....what happens in a commercial code shop is comments do not get changed to tell what people did - but for posting I suggest copious commenting to save people trying to guess what is needed by poster.