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.
Code Java:
/**
* 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();
}
}
Re: Finish up code and need some help?
How can your code be tested? It does not compile.
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.
Re: Finish up code and need some help?
How many files are you talking about? More than 2 is too many.
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.
Re: Finish up code and need some help?
If you can't post them here then there must be too many files.
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.
Re: Finish up code and need some help?
Not really. The drawImage method has many versions that might be useful.