Results 1 to 2 of 2

Thread: Word Collider

  1. #1
    luigihs is offline Member
    Join Date
    Oct 2012
    Rep Power

    Default Word Collider

    Java Code:
     * Write a description of class WordCollider here.
     * @author (your name) 
     * @version (a version number or a date)
    public class WordCollider
        // instance variables - replace the example below with your own
        private Text word1;
        private Text word2;
        // the characters contained in word1
        private Text[] charWord1;
        // the characters contained in word2
        private Text[] charWord2;
         * Constructor for objects of class WordCollider
        public WordCollider(String w1, String w2)
            // initialise instance variables
            word1 = new Text(w1);
            word2 = new Text(w2);
            charWord1 = new Text[w1.length()];
            charWord2 = new Text[w2.length()];
            fillChars(charWord1, w1);
            fillChars(charWord2, w2);
        private void fillChars(Text[] a, String w) {
            char[] cs = w.toCharArray();
            for (int i=0; i<a.length; i++) {
                a[i] = new Text(""+cs[i]);
         * Randomize the position of the two words repeatedly and stop
         * when the bounding box of the two words overlaps.
        public void animate()
         * erase the words and any other characters on the display
        public void clearDisplay() {
         * check if the bounding box of the two words overlaps.
         * @return true when the words overlap and false otherwise.
        private Boolean checkOverlap() {
            return false;
    Hi people Im really new to Java barely understand I know I have to do a loop or something in void animate Randomize the position of the two words repeatedly and stop when the bounding box of the two words overlaps. But I dont know how to do it how is the program is going to know when is overlaps im so confused help me please!!!

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Rep Power

    Default Re: Word Collider

    Woah there, slow down. You're asking several things at once. If I understand you, you are asking how to:

    1. Animate, or at least randomize the position of the items
    2. Collision detection on those items

    Is that correct? If so, part 1 would involve making a look (outside of your paint method) that tells the system how often to refresh the screen. You would also need a method that actually paints the items onto the screen, and then usually another method that performs logic (like movement and collision). A normal loop would do something like:
    - Perform logic (move items, bounce items, whatever)
    - Paint the new state of all the objects onto a panel
    - refresh the screen

    Part 2 is more complex depending on the number of entities. For just a few bouncing entities, a brute force iteration would be fine (check every item against every other item for a collision). There are ways to optimize this, such as only checking every pair of elements once, etc... If you need to work with hundreds or thousands of entities, this is a MUCH more complex problem which is usually solved with data structures (like QuadTrees).

Similar Threads

  1. how to reverse word by word?
    By yamicaitsith in forum New To Java
    Replies: 13
    Last Post: 09-16-2012, 11:30 PM
  2. !word
    By walsby14 in forum New To Java
    Replies: 2
    Last Post: 07-16-2012, 04:36 PM
  3. Replies: 3
    Last Post: 08-30-2011, 04:44 PM
  4. Word
    By right2001 in forum New To Java
    Replies: 2
    Last Post: 04-07-2009, 03:25 AM
  5. Word OLE
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02: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