/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package multididdy_view;
import java.util.LinkedList;
import java.util.List;
import multididdy_model.SpriteModel;
import org.newdawn.slick.Animation;
import org.newdawn.slick.SpriteSheet;
/**
*
* @author jones
*/
public class Sprite{
public SpriteModel model;
List<Animation> animations;
Animation currentAnimation;
public Sprite(){
super();
animations=new LinkedList();
}
public void addAnimation(SpriteSheet sheet,int duration){
for(int y=0;y<sheet.getVerticalCount();y++){
Animation animation=new Animation();
for(int x=0;x<sheet.getHorizontalCount();x++){
animation.addFrame(sheet.getSprite(x, y), duration);
}
animation.setAutoUpdate(true);
animations.add(animation);
}
setAnimation(0);
}
public void setAnimation(int i){
currentAnimation=animations.get(i);
}
public void stopAnimation(){
if(currentAnimation!=null)
currentAnimation.stop();
}
public void startAnimation(){
if(currentAnimation!=null)
currentAnimation.start();
}
public void setFrame(int i){
if(currentAnimation!=null)
currentAnimation.setCurrentFrame(i);
}
/*
public void setFrameRange(int first, int last){
this.setCurrentFrame(first);
this.stopAt(last);
this.setLooping(true);//(first!=last));
}*/
public void draw(){
setAnimation(model.direction);
if(currentAnimation!=null)
currentAnimation.draw(model.x,model.y,model.width,model.height);
}
}