Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Finish up code and need some help?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Finish up code and need some help?

    Hey everyone, I am currently doing some off-work exercises and was wondering if any of you could help. My project is a "movie" file called WolfAttackMovie from one of the books and below I'll insert the code files so you can see for yourself. The problem with this now is that the wolves are supposed to "grow" as they enter the scene gradually and then shrink as they leave gradually. To do this I am supposed to implement a ScaleNode and it is that I need help writing/implementing. Thanks.
    /**
     * Class to make a wolf attack movie
     * @author Mark Guzdial
     * @author Barb Ericson
     */
    public class WolfAttackMovie{
     
      /** The root of the scene data structure */
      private Branch sceneRoot;
     
      /** FrameSequencer where the animation is created */
      private FrameSequencer frames;
     
      /** The nodes we need to track between methods */
      private MoveBranch wolfEntry, wolfRetreat, hero;
     
      /**
       * Constructor that takes no arguments and
       * sets up the movie
       */
      public WolfAttackMovie() {
        setUp();
      }
     
      /**
       * Set up all the pieces of the tree.
       */
      private void setUp(){
        Picture wolf = 
          new Picture(FileChooser.getMediaPath("dog-blue.jpg")).flip();
        Picture house = 
          new Picture(FileChooser.getMediaPath("house-blue.jpg"));
        Picture tree = 
          new Picture(FileChooser.getMediaPath("tree-blue.jpg"));
        Picture monster = 
          new Picture(FileChooser.getMediaPath("mScary.jpg")).flip();
     
        //Make the forest
        MoveBranch forest = new MoveBranch(10,400); // at bottom 
        HBranch trees = new HBranch(50); // 50 pixels between
        BlueScreenNode treenode;
        for (int i=0; i < 8; i++) { // insert 8 trees
          treenode = new BlueScreenNode(tree.scale(0.5));
          trees.addChild(treenode);
        }
        forest.addChild(trees);
     
        // Make the cluster of attacking "wolves"
        wolfEntry = new MoveBranch(350,50); // starting position
        VBranch wolves = new VBranch(20); // space out by 20 pixels 
        BlueScreenNode wolf1 = new BlueScreenNode(wolf.scale(0.5));
        BlueScreenNode wolf2 = new BlueScreenNode(wolf.scale(0.5));
        BlueScreenNode wolf3 = new BlueScreenNode(wolf.scale(0.5));
        wolves.addChild(wolf1);
        wolves.addChild(wolf2);
        wolves.addChild(wolf3);
        wolfEntry.addChild(wolves);
     
        // Make the cluster of retreating "wolves"
        wolfRetreat = new MoveBranch(400,50); // starting position
        wolves = new VBranch(20); // space them out by 20 pixels 
        wolf1 = new BlueScreenNode(wolf.scale(0.5).flip());
        wolf2 = new BlueScreenNode(wolf.scale(0.5).flip());
        wolf3 = new BlueScreenNode(wolf.scale(0.5).flip());
        wolves.addChild(wolf1);
        wolves.addChild(wolf2);
        wolves.addChild(wolf3);
        wolfRetreat.addChild(wolves);
     
        // Make the village
        MoveBranch village = new MoveBranch(300,450); // on bottom
        VBranch vhouses = new VBranch(-50); // move UP 50 pixels
        BlueScreenNode house1 = new BlueScreenNode(house.scale(0.25));
        BlueScreenNode house2 = new BlueScreenNode(house.scale(0.25));
        BlueScreenNode house3 = new BlueScreenNode(house.scale(0.25));
        HBranch hhouses = new HBranch(40); // 40 pixels apart
        BlueScreenNode house4 = new BlueScreenNode(house.scale(0.25));
        BlueScreenNode house5 = new BlueScreenNode(house.scale(0.25));
        BlueScreenNode house6 = new BlueScreenNode(house.scale(0.25));
        hhouses.addChild(house4); 
        hhouses.addChild(house5); 
        hhouses.addChild(house6); 
        vhouses.addChild(house1); 
        vhouses.addChild(house2); 
        vhouses.addChild(house3);
        hhouses.addChild(vhouses); // a VBranch can be a child
        village.addChild(hhouses);
     
     
     
     
     
     
        // Make the monster
        hero = new MoveBranch(0,300);
        BlueScreenNode heronode = 
          new BlueScreenNode(monster.scale(0.75));
        hero.addChild(heronode);
     
        //Assemble the base scene
        sceneRoot = new Branch();
        sceneRoot.addChild(forest);
        sceneRoot.addChild(village);
        sceneRoot.addChild(wolfEntry);
      }
      /**
       * Method to get the scene root
       * @return the sceneRoot
       */
      public Branch getSceneRoot() { return sceneRoot;}
     
      /**
       * Render just the first scene
       */
      public void renderScene() {
        Picture bg = new Picture(500,500);
        sceneRoot.drawOn(bg);
        bg.show();
      }
     
      /**
       * Render the whole animation
       */
      public void renderAnimation() {
        frames = new FrameSequencer("C:/Temp/");
        frames.show();
        Picture bg;
     
        // First, the nasty wolvies come closer to the poor village
        // Cue the scary music
        for (int i=0; i<25; i++) {
     
          // Render the frame
          bg = new Picture(500,500);
          sceneRoot.drawOn(bg);
          frames.addFrame(bg);
     
          // Tweak the data structure
          wolfEntry.moveTo(wolfEntry.getXPos()-5,
                           wolfEntry.getYPos()+10);
        }
     
        // Now, our hero arrives!
        this.getSceneRoot().addChild(hero);
     
        // Render the frame
        bg = new Picture(500,500);
        sceneRoot.drawOn(bg);
        frames.addFrame(bg);
     
        // Remove the wolves entering, and insert the wolves 
        // retreating
        Branch root = this.getSceneRoot();
        root.getFirstChild().remove(wolfEntry);
        root.addChild(wolfRetreat);
     
        // Make sure that they retreat from the same place 
        wolfRetreat.moveTo(wolfEntry.getXPos(),wolfEntry.getYPos());
     
        // Render the frame
        bg = new Picture(500,500);
        root.drawOn(bg);
        frames.addFrame(bg);
     
        // Now, the cowardly wolves hightail it out of there!
        // Cue the triumphant music
        for (int i=0; i<10; i++) {
     
          // Render the frame
          bg = new Picture(500,500);
          root.drawOn(bg);
          frames.addFrame(bg);
     
          // Tweak the data structure
          wolfRetreat.moveTo(wolfRetreat.getXPos()+10,
                             wolfRetreat.getYPos()-20);
        }
      }
     
      /**
       * Replay the animation
       */
      public void replay() {
        // Probably about 5 frames per second will work
        frames.replay(200);
      }
     
      /** Main method for testing */
      public static void main (String[] args) {
        FileChooser.pickMediaPath();
        WolfAttackMovie movie = new WolfAttackMovie();
        movie.renderAnimation();
      }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,186
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Finish up code and need some help?

    How can your code be tested? It does not compile.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Finish up code and need some help?

    Sorry, I'm new how do I upload a folder? It comes with 2 folders that you need to compile it properly.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,186
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Finish up code and need some help?

    How many files are you talking about? More than 2 is too many.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Finish up code and need some help?

    Media Computation Teachers Website

    Here is the link rather. The two folders under Data Structures are mediasources and java-source. You would have to set an extra classpath to java-source and when you run the program you also need ButtonPanel.java to be opened alongside with this class(which comes with java-source). When you actually run the program though, you select the media source folder. If this is too much, then sorry :/ I just wanted to find any help really and this seemed like a good place to start/find it.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,186
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Finish up code and need some help?

    If you can't post them here then there must be too many files.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Finish up code and need some help?

    There are Well rather do you know of such code that can decrease/increase an images scaling throughout each frame? I figured I needed a loop but I don't really know where to start.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,186
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Finish up code and need some help?

    Not really. The drawImage method has many versions that might be useful.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    erock618 (April 21st, 2012)

Similar Threads

  1. Can anyone help me finish creating a GUI for my program
    By danbendlin in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 16th, 2012, 07:34 PM
  2. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 08:30 PM
  3. [SOLVED] Help me finish this program :(
    By thisbeme in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 12th, 2011, 03:09 AM
  4. Get out of loop to finish program?
    By Doofy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 17th, 2011, 08:34 AM
  5. tax return program..help finish please!!
    By dscrudato21xo in forum Loops & Control Statements
    Replies: 2
    Last Post: November 5th, 2009, 02:23 PM