Results 1 to 2 of 2

Thread: Array help

  1. #1
    Sidoney is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default Array help

    Hello

    Ive hit a road block even though I think the solution is probably staring me in the face.

    I have 5 static objects and 1 objects which moves (ill call this A).

    When the program starts I need A to move to the closest object. Once its there I need it to move to the next closest one, then the next closest one etc. Once it has moved to an object it needs to ignore it for the rest of the run. Once it has moved through all 5 objects the program ends.

    The way I have done it is made an array and find the distance to all the balls and store these values in an array.

    Next I have made a 2nd array to store the sorted distances.

    Then I have a for loop with this in it

    Java Code:
    if(eculDist[i] == eculDistSort[0])
    Once this executes, say it gets to i = 3 and that is equal to the smallest distance it then sets 3 as the value for which object I want to move to.

    Now my program currently moves A to the closest object but once its there I have no idea how to get it to then move again to the next closest one.

    I have used
    Java Code:
    System.out.println(Arrays.toString(eculDist));
    to see whats happening and the numbers are constantly been updated as A moves closer to the object.

    Sorry for the wall of text.

    Thanks for any help.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,960
    Rep Power
    8

    Default Re: Array help

    Well, you can do a couple different things. Either make sure you only create that array once instead of updating it constantly, or you can update it constantly but keep track of which Objects you've already visited (either as a part of the Object itself or in a separate data structure). Which one you go with is dependent upon exactly what you want the program to do.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 3
    Last Post: 12-28-2013, 09:39 PM
  2. Replies: 15
    Last Post: 05-14-2012, 12:42 PM
  3. Replies: 0
    Last Post: 05-12-2011, 07:04 PM
  4. Replies: 23
    Last Post: 09-07-2010, 08:12 PM
  5. Replies: 2
    Last Post: 09-06-2010, 01:03 AM

Posting Permissions

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