hoffe ist nicht zu viel import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Wand extends World
{
public Slider Amplitude;
private h_feder Feder;
public Wand()
{
super(640, 480, 1);
setBackground("wand.jpg");
Feder = new h_feder();
addObject(Feder, 102, 182);
Amplitude = new Slider("(%) Amplitude",1,100);
addObject(Amplitude,480,100);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
/**
* The AnimatedActor class serves as a superclass for other, more specific
* Actor classes. It provides a mechanism to give actors an animated image.<p>
*
* To use this class, you need a sequence of image files to be used for the
* animation. Let's say we create four files named "cat0.png", "cat1.png",
* "cat2.png" and "cat3.png". In this case, our base name would be "cat", the
* suffix is ".png", and the number of images is 4.<p>
*
* You can create an animated actor by subclassing this class, and calling this
* class's constructor with the base name, suffix, and number of images as a
* parameter. So, to make an animated cat, I might have a subclass 'Cat' with
* the folling constructor"<p>
*
* <pre>
* public Cat() {
* super("cat", ".png", 4);
* }
* <pre>
*
* The image files have to be numbered starting at 0, and they have to ve in the
* scenario's 'image' folder.<p>
*
* The image will change with every act step.
*
* @author mik
* @version 1.0
*/
public class AnimatedActor extends Mover
{
private GreenfootImage[] images;
private int currentImage = 0;
private boolean hin = true;
private double max_el;
/**
* Construct an animated actor. This assumes that you have provided image
* file (in the 'images' folder) named 'basenameN.suffix', where N is
* [0..numberOfImages-1].
*
* @param basename The base name of the image files.
* @param suffix The suffix of the image files (must include the ".").
* @param noOfImages The number of images to be use din the animation.
*/
public AnimatedActor(String basename, String suffix, int noOfImages)
{
images = new GreenfootImage[noOfImages];
for(int i=0; i < noOfImages; i++) {
images[i] = new GreenfootImage(basename + i + suffix);
}
setImage(images[currentImage]);
}
/**
* Act - do whatever the AnimatedActor wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*
* Method was changed! Now the animation waves, i.e. not 12341234, but 1234321
*/
public void act()
{
// max_el = Amplitude.getValue() ;
//*Math.sin(w*t);
if(hin)
{
currentImage = (currentImage + 1) % images.length;
}
if(hin==false)
{
currentImage = (currentImage-1) % images.length;
}
setImage(images[currentImage]);
if (currentImage==images.length-1)
{
hin = false;
}
if (currentImage==0)
{
hin = true;
}
}
}