Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default please help with my program

    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 11:31 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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. #3
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default

    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. #4
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default

    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 02:23 PM.

  5. #5
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Vector Points = new Vector();

    for ( ...... )
    {
    Points.add(Random.nextInt(),Random.nextInt());
    }

    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 )
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  6. #6
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Quote Originally Posted by scherukumalli View Post
    Hi

    I need 2nd hand Bike

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

  7. #7
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default

    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 02:15 AM.

  8. #8
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default

    hello!!

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

    load: Beast$boids.class can't be instantiated.
    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.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Last edited by x_maria; 12-07-2008 at 09:14 PM.

  9. #9
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default

    i fix that..now it can run.
    thanks

  10. #10
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default

    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??
    Thanks in advance!
    Last edited by x_maria; 12-13-2008 at 11:12 PM.

  11. #11
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    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. #12
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default

    Thanks for the quick reply!!
    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 01:58 AM.

  13. #13
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default

    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 12:37 PM.

  14. #14
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  15. #15
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default

    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)..

  16. #16
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Red face 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.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  17. #17
    x_maria is offline Member
    Join Date
    Nov 2008
    Posts
    12
    Rep Power
    0

    Default

    Thanks for the reply!It helped!
    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 10:19 AM.

  18. #18
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Smile 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 );//
    
                    adjustedSize.setSize(wwww,hhhh);
                    super.setSize((Dimension)adjustedSize);// end fancy sizing
                    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.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  19. #19
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Red face links

    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.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  20. #20
    ninian is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

Page 1 of 2 12 LastLast

Similar Threads

  1. Help with Program . . .
    By DSutta22 in forum New To Java
    Replies: 7
    Last Post: 09-18-2008, 08:47 AM
  2. Help with program
    By bri1547 in forum New To Java
    Replies: 16
    Last Post: 07-27-2008, 06:26 AM
  3. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 09:24 AM
  4. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

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