1   package erland.game.tileadventure;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  import erland.util.SubImageHandler;
22  import erland.util.ParameterValueStorageExInterface;
23  import erland.util.StringUtil;
24  
25  import java.awt.*;
26  
27  public class BitmapObject extends GameObject {
28      private int subImage;
29      private Image image;
30      private SubImageHandler subImages;
31      private String imageName;
32      public static int drawCount;
33      /***
34       * Set the background image
35       * @param image The main image
36       * @param subImage The sub image number of the sub image to use
37       */
38      public void setImage(Image image, int subImage) {
39          this.subImage = subImage;
40          this.image = image;
41          this.subImages = ((TileGameEnvironmentInterface)getEnvironment().getCustomEnvironment()).createSubImageHandler(this.image);
42      }
43  
44      /***
45       * Set the background image
46       * @param image The name of the main image
47       * @param subImage The sub image number of the sub image to use
48       */
49      public void setImage(String image, int subImage)
50      {
51          if(getEnvironment().getImageHandler()!=null) {
52              setImage(getEnvironment().getImageHandler().getImage(image),subImage);
53          }
54          this.imageName = image;
55      }
56  
57      public void draw(Graphics g) {
58          if(subImages!=null) {
59              if(getContainer().getVisible(getPosX(),getPosY(),getPosZ())) {
60                  
61                  if(subImage>=0) {
62                      drawCount++;
63                      subImages.drawImage(g,subImage,getDrawingPosX(0f,0f,0f),getDrawingPosY(0f,0f,0f));
64                  }
65              }
66          }
67      }
68  
69      public void write(ParameterValueStorageExInterface out) {
70          super.write(out);
71          if(StringUtil.asNull(imageName)!=null) {
72              out.setParameter("image",imageName);
73          }
74          out.setParameter("subimage",Integer.toString(subImage));
75      }
76  
77      public void read(ParameterValueStorageExInterface in) {
78          super.read(in);
79          int subImage = Integer.valueOf(in.getParameter("subimage")).intValue();
80          setImage(image,subImage);
81      }
82  }