C:\eclipse\workspace\Epsilon_01\src\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 import javax.microedition.lcdui.*;
14 
15 class GameSprite {
16 
17         public int x;
18         public int y;
19         
20         public int w;
21         public int h;
22 
23         public int vx;
24         public int vy;
25         
26         public byte energy;
27         public byte energyMax;
28         
29         public Image img;
30 
31         GameSprite(Image loaded_image, byte energy_max)
32         {
33                 img = loaded_image;
34                 w = loaded_image.getWidth();
35                 h = loaded_image.getHeight();
36                 vx = 4;
37                 vy = 4;
38                 energyMax = energy_max;
39                 energy = energyMax;
40         }
41 
42         public boolean collidesWith(GameSprite sprite)
43         {
44                 return (x+w > sprite.x) && (x < sprite.x + sprite.w) &&
45                                 (y+h > sprite.y) && (y < sprite.y + sprite.h);
46         }
47 }
48