1. Member
Join Date
Nov 2008
Posts
12
Rep Power
0

hello!

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!!!
Last edited by x_maria; 11-22-2008 at 10:31 PM.

2. Suggestion: break the big problem into lots of little problems and try to solve each one, one at a time. If you run into a block with a "little" problem, then try to solve it in isolation of the rest of your program -- create a small program just to solve the small problem. If you still are not getting any where, then come back with this code. Good luck.

3. Member
Join Date
Nov 2008
Posts
12
Rep Power
0
yes,you are right..it's just i don't have much time left and i am desperate!i will try only the first rule and ,if need be,i post again...thanks

4. Member
Join Date
Nov 2008
Posts
12
Rep Power
0
hello again!
now i am having another problem..my groups of objects go only from left to right whereas i want them to move from one point to another to all directions.
how am i able to do that?can anyone help me please??
Last edited by x_maria; 11-29-2008 at 01:23 PM.

5. Vector Points = new Vector();

for ( ...... )
{
}

Grossly oversimplified, you could just place the Random.nextPoint() in the Shapes code but one would have to scale the ints down to something in the scale of:
Java Code:
```    double cx=0;
double cy=0;```
in the void near() method......

The approach is known, this code is likely sample code and if you have not worked out the movement yet LOL on getting it running tonight.

Can be done, if you write hundreds of lines of code every day for fun. Remember, you have to do delta-X, delta-Y to get 2D movement. ( delta is fancy word for change of position )

6. Originally Posted by scherukumalli
Hi

I need 2nd hand Bike

9243067072
Buy it in the 2nd hand shop,got to ebay shop

7. Member
Join Date
Nov 2008
Posts
12
Rep Power
0
Hi!
Thanks very much for the reply.!Yes,but if i do that ( use Random.nextInt() ), how am i going to check if one is close to each other(near method)?Is it possible for them to move to all directions by doing something with the variable direction or cos/sin?
Last edited by x_maria; 11-24-2008 at 01:15 AM.

8. Member
Join Date
Nov 2008
Posts
12
Rep Power
0
hello!!

can anybody tell me what's wrong with the program and it doesn't run?
it appears the following message:

java.lang.InstantiationException: Beast\$boids
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
Last edited by x_maria; 12-07-2008 at 08:14 PM.

9. Member
Join Date
Nov 2008
Posts
12
Rep Power
0
i fix that..now it can run.
thanks

10. Member
Join Date
Nov 2008
Posts
12
Rep Power
0
Hi!
In the following program there is an obstacle(ball) and some shapes that move around..
Does anybody know how am i going to add collision detection between the shapes and the obstacle??
Last edited by x_maria; 12-13-2008 at 10:12 PM.

11. I havn't looked at the code but the general idea is your shape will have an area it takes up. Just check if the obstacle(x,y coords) is in bounds then a collision occurred.

12. Member
Join Date
Nov 2008
Posts
12
Rep Power
0
Could you be more specific?From what i have read i know that there is the " Rectangle getBounds()" and the "boolean intersects(Rectangle2D r)" but i am not able to use them in the code attached.So any help will be appreciated!
Last edited by x_maria; 12-13-2008 at 12:58 AM.

13. Member
Join Date
Nov 2008
Posts
12
Rep Power
0
I tried to add collision detection but the shapes that fly straight do not follow the rule checkCollision()..Any ideas?What is that i am doing wrong?
Last edited by x_maria; 01-13-2009 at 11:37 AM.

14. Member
Join Date
Nov 2008
Posts
12
Rep Power
0
Thanks very much for the reply!
the thing is that I use the methods getBounds() and intersects() but when shapes move straight ahead they do not turn in order to avoid the obstacle(method checkCollision)..

15. ## Beastly Boids Boldy Blunder

I intended to work on this, have a full day ahead .... won't get much done on it today. HTH:
Java Code:
`b.currentDirection= b.currentDirection*(float)(0.45 * Math.PI/180);`
would seem to be moving the Boids and Beasts

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
Java Code:
```Float nextPosition = new Float((Math.cos(currentDirection) * currentSpeed));
x += nextPosition.toInteger();```
or something like that.

16. Member
Join Date
Nov 2008
Posts
12
Rep Power
0
Actually the code posted is not my "original" code.Mine is quite big that 's why I have this (smaller) one where I just try things and then put them in the original one..
Thanks again
Last edited by x_maria; 12-15-2008 at 09:19 AM.

17. ## 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:
Java Code:
```            // else, do some testing and set some reasonable size values if Dimensions sound screwy
else
{
/****** 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 );//

windowSize.setSize(super.getSize());// = ;
}```
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.

You find things like this:
Java Code:
`Cyrus.this.pointGenerator = new Random(Seytem.currentTimeMillis());// ..`
and discover where your move() is going null on 0.00

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.

they're gonna laugh at my code, here - have some hotlinks:Try last one first as the college profs do a better job at making understandable work available.

19. Member
Join Date
Nov 2008
Posts
3
Rep Power
0
hello may i know this program

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•