1
9 package version18;
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 int frameSpeed;
20 protected int t;
21 protected Stage stage;
22 protected SpriteCache spriteCache;
23 protected boolean markedForRemoval;
24
25 public Actor(Stage stage) {
26 this.stage = stage;
27 spriteCache = stage.getSpriteCache();
28 currentFrame = 0;
29 frameSpeed = 1;
30 t=0;
31 }
32
33 public void remove() {
34 markedForRemoval = true;
35 }
36
37 public boolean isMarkedForRemoval() {
38 return markedForRemoval;
39 }
40
41 public void paint(Graphics2D g){
42 g.drawImage( spriteCache.getSprite(spriteNames[currentFrame]), x,y, stage );
43 }
44
45 public int getX() { return x; }
46 public void setX(int i) { x = i; }
47
48 public int getY() { return y; }
49 public void setY(int i) { y = i; }
50
51 public int getFrameSpeed() {return frameSpeed; }
52 public void setFrameSpeed(int i) {frameSpeed = i; }
53
54
55 public void setSpriteNames(String[] names) {
56 spriteNames = names;
57 height = 0;
58 width = 0;
59 for (int i = 0; i < names.length; i++ ) {
60 BufferedImage image = spriteCache.getSprite(spriteNames[i]);
61 height = Math.max(height,image.getHeight());
62 width = Math.max(width,image.getWidth());
63 }
64 }
65
66 public int getHeight() { return height; }
67 public int getWidth() { return width; }
68 public void setHeight(int i) {height = i; }
69 public void setWidth(int i) { width = i; }
70
71 public void act() {
72 t++;
73 if (t % frameSpeed == 0){
74 t=0;
75 currentFrame = (currentFrame + 1) % spriteNames.length;
76 }
77 }
78 }
79