hi,
i am doing a trebuchet simulation and i am just wondering if there is a way for a player to be able to input weights into the program for the projectile and the counter weight?
cheers


java.lang.ArrayIndexOutOfBoundsException: 2 at Earth.<init>(Earth.java:26) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at greenfoot.core.Simulation.newInstance(Simulation.java:520) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:406) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:411) at greenfoot.core.Simulation.maybePause(Simulation.java:269) at greenfoot.core.Simulation.runContent(Simulation.java:201) at greenfoot.core.Simulation.run(Simulation.java:194)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; import java.awt.Font; import java.lang.String; /** * Write a description of class Earth here. * * @author (your name) * @version (a version number or a date) */ public class Earth extends World { private double gravity = 2; static boolean transitioning = false; static boolean change = false; static final String[] barText = { "Projectile", "CounterWieght"}; static final int[][] barCols = { { 128, 0, 0, 255 }, { 0, 128, 0, 255 }}; Bar[] bars = new Bar[8]; public Earth() { super(800, 600, 1); for (int i = 0; i < 8; i++) { bars[i] = new Bar(barText[i % 4], "", 63 + 64 * (i < 4 ? i : 1), 255); bars[i].setSafeColor(new Color(barCols[i % 4][0], barCols[i % 4][1], barCols[i % 4][2], barCols[i % 4][3])); } for (int i = 0; i < 4; i++) addObject(bars[i], 750, 75 + 25 * i); //addObject(new Button(), 750, 200); //addObject(new Pad(), 300, 200); //updateBackground(); Greenfoot.start(); } //private Color BackgroundColor = Color.BLACK; public void act() { if (!change) return; change = false; //updateBackground(); if (transitioning && getObjects(Bar.class).size() < 8) for (int i = 0; i < 4; i++) addObject(bars[4 + i], 750, 275 + 25 * i); if (!transitioning && getObjects(Bar.class).size() > 4) for (int i = 0; i < 4; i++) removeObject(bars[4 + i]); } public double getGravity() { return gravity; } //public static boolean isKeyDown ("1"); public class TrebArm { } public class TrebBase { } public class Trebuchet { TrebArm arm = new TrebArm(); TrebBase base = new TrebBase(); } }
java.lang.ArrayIndexOutOfBoundsException: 2 at Earth.<init>(Earth.java:26) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at greenfoot.core.Simulation.newInstance(Simulation.java:520) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:406) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:411) at greenfoot.core.Simulation.maybePause(Simulation.java:269) at greenfoot.core.Simulation.runContent(Simulation.java:201) at greenfoot.core.Simulation.run(Simulation.java:194)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; import java.awt.Font; import java.lang.String; /** * Write a description of class Earth here. * * @author (your name) * @version (a version number or a date) */ public class Earth extends World { private double gravity = 2; //static boolean transitioning = false; static boolean change = false; static final String[] barText = { "Projectile", "CounterWieght"}; static final int[][] barCols = { { 128, 0, 0, 255 }, { 0, 128, 0, 255 }}; Bar[] bars = new Bar[2]; public Earth() { super( 800, 600, 1); for (int i = 0; i; i++) { bars[i] = new Bar(barText[i ], "", 63 + 64 * (i), 255); bars[i].setSafeColor(new Color(barCols[i ][0], barCols[i ][1], barCols[i][2], barCols[i][3])); } for (int i = 0; i < 4; i++) addObject(bars[i], 750, 75 + 25 * i); //addObject(new Button(), 750, 200); //addObject(new Pad(), 300, 200); //updateBackground(); Greenfoot.start(); } //private Color BackgroundColor = Color.BLACK; public void act() { // if (!change) return; // change = false; //updateBackground(); //if (transitioning && getObjects(Bar.class).size() < 4) for (int i = 0; i < 2; i++) addObject(bars[2 + i], 750, 275 + 25 * i); // if (!transitioning && getObjects(Bar.class).size() > 4) for (int i = 0; i < 2; i++) removeObject(bars[ + i]); } public double getGravity() { return gravity; } //public static boolean isKeyDown ("1"); public class TrebArm { } public class TrebBase { } public class Trebuchet { TrebArm arm = new TrebArm(); TrebBase base = new TrebBase(); } }