1
9 package version24;
10
11 import java.awt.Graphics2D;
12 import java.awt.Rectangle;
13 import java.awt.image.BufferedImage;
14
15 public class Actor {
16 protected int x,y;
17 protected int width, height;
18 protected String[] spriteNames;
19 protected int currentFrame;
20 protected int frameSpeed;
21 protected int t;
22 protected Stage stage;
23 protected SpriteCache spriteCache;
24 protected boolean markedForRemoval;
25
26 public Actor(Stage stage) {
27 this.stage = stage;
28 spriteCache = stage.getSpriteCache();
29 currentFrame = 0;
30 frameSpeed = 1;
31 t=0;
32 }
33
34 public void remove() {
35 markedForRemoval = true;
36 }
37
38 public boolean isMarkedForRemoval() {
39 return markedForRemoval;
40 }
41
42 public void paint(Graphics2D g){
43 g.drawImage( spriteCache.getSprite(spriteNames[currentFrame]), x,y, stage );
44 }
45
46 public int getX() { return x; }
47 public void setX(int i) { x = i; }
48
49 public int getY() { return y; }
50 public void setY(int i) { y = i; }
51
52 public int getFrameSpeed() {return frameSpeed; }
53 public void setFrameSpeed(int i) {frameSpeed = i; }
54
55
56 public void setSpriteNames(String[] names) {
57 spriteNames = names;
58 height = 0;
59 width = 0;
60 for (int i = 0; i < names.length; i++ ) {
61 BufferedImage image = spriteCache.getSprite(spriteNames[i]);
62 height = Math.max(height,image.getHeight());
63 width = Math.max(width,image.getWidth());
64 }
65 }
66
67 public int getHeight() { return height; }
68 public int getWidth() { return width; }
69 public void setHeight(int i) {height = i; }
70 public void setWidth(int i) { width = i; }
71
72 public void act() {
73 t++;
74 if (t % frameSpeed == 0){
75 t=0;
76 currentFrame = (currentFrame + 1) % spriteNames.length;
77 }
78 }
79
80 public Rectangle getBounds() {
81 return new Rectangle(x,y,width,height);
82 }
83
84 public void collision(Actor a){
85
86 }
87 }
88