1     /**
2      * Curso Básico de desarrollo de Juegos en Java - Invaders
3      * 
4      * (c) 2004 Planetalia S.L. - Todos los derechos reservados. Prohibida su reproducción
5      * 
6      * http://www.planetalia.com
7      * 
8      */
9     package version14;
10    
11    import java.awt.Graphics2D;
12    import java.awt.image.BufferedImage;
13    
14    public class Actor {
15      protected int x,y;
16      protected int width, height;
17      protected String[] spriteNames;
18      protected int currentFrame;
19      protected Stage stage;
20      protected SpriteCache spriteCache;
21      
22      public Actor(Stage stage) {
23        this.stage = stage;
24        spriteCache = stage.getSpriteCache();
25        currentFrame = 0;
26      }
27      
28      public void paint(Graphics2D g){
29        g.drawImage( spriteCache.getSprite(spriteNames[currentFrame]), x,y, stage );
30      }
31      
32      public int getX()  { return x; }
33      public void setX(int i) { x = i; }
34    
35      public int getY() { return y; }
36      public void setY(int i) { y = i; }
37      
38      public void setSpriteNames(String[] names) { 
39        spriteNames = names;
40        height = 0;
41        width = 0;
42        for (int i = 0; i < names.length; i++ ) {
43          BufferedImage image = spriteCache.getSprite(spriteNames[i]);
44          height = Math.max(height,image.getHeight());
45          width = Math.max(width,image.getWidth());
46        }
47      }     
48      
49      public int getHeight() { return height; }
50      public int getWidth() { return width; }
51      public void setHeight(int i) {height = i; }
52      public void setWidth(int i) { width = i;  }
53    
54      public void act() {
55        currentFrame = (currentFrame + 1) % spriteNames.length;
56      }
57    }
58