C:\__todo__\tecaj.www\src\Epsilon_02\GameSprite.java
 1  /**
 2   *  GameSprite contains the Sprite class for the Epsilon game.
 3   *  Epsilon is a simple space-shooter-vertical-scroller game.
 4   *
 5   *  Epsilon is available for non-commercial use only!
 6   *  You can learn from this sources and you can modify them
 7   *  for learning purposes.
 8   * 
 9   *  @author      Ziga Hajdukovic
10   *  @version     1.0
11   *  
12   *  
13   *  CHANGES
14   *  + frameId
15   *  + frameIdMax
16   *  + imageId replaced Image object
17   *  + spriteImageFrameWidths[]
18   *  
19   */  
20 
21 class GameSprite {
22 
23         public int x;
24         public int y;
25         
26         public int w;
27         public int h;
28 
29         public int vx;
30         public int vy;
31         
32         public byte energy;
33         public byte energyMax;
34         
35         public byte imageId;
36         
37         public byte frameId;
38         public byte frameIdMax;
39         
40         //public byte spriteId;
41         
42         public static final byte[] spriteImageFrameWidths =
43         {
44                 26,     // SPRITE_IMAGE_PLAYER
45                  4, // SPRITE_IMAGE_FIRE
46                 45, // SPRITE_IMAGE_BOSS1
47                 20, // SPRITE_IMAGE_ENEMY1
48                 20, // SPRITE_IMAGE_ENEMY2
49                 20, // SPRITE_IMAGE_ENEMY3
50                 20, // SPRITE_IMAGE_EXPLOSION
51         };
52 
53         GameSprite(byte image_id, byte energy_max)
54         {
55                 imageId = image_id;
56                 w = spriteImageFrameWidths[image_id];
57                 h = GameCanvas.spriteImages[image_id].getHeight();
58                 frameId = 0;
59                 frameIdMax = (byte) (GameCanvas.spriteImages[image_id].getWidth() / w - 1);
60                 vx = 4;
61                 vy = 4;
62                 energyMax = energy_max;
63                 energy = energyMax;
64         }
65 
66         public boolean collidesWith(GameSprite sprite)
67         {
68                 return (x+w > sprite.x) && (x < sprite.x + sprite.w) &&
69                            (y+h > sprite.y) && (y < sprite.y + sprite.h);
70         }
71 }
72