www.pudn.com > TWPlaneGame.rar > Bullet.java


package twplanegame; 
 
import javax.microedition.lcdui.*; 
 
class Bullet 
    extends PlaneGameObject 
{ 
    private int XSpeed; 
    private int YSpeed; 
 
    //constructor 
    public Bullet(int id) 
    { 
        super(id, 0, 0); 
        switch (id) { 
            case 0: //my bullet 
                try { 
                    ObjImage = Image.createImage("/MyBullet01.PNG"); 
                } 
                catch (Exception e) { 
                    ObjImage = null; 
                } 
                XSpeed = 10; 
                YSpeed = 0; 
                break; 
            case 1: //enemy plane bullet 
                try { 
                    ObjImage = Image.createImage("/EnemyBullet01.PNG"); 
                } 
                catch (Exception e) { 
                    ObjImage = null; 
                } 
                XSpeed = 3; 
                YSpeed = 3; 
                break; 
            case 2: 
                try { 
                    ObjImage = Image.createImage("/BossBullet01.PNG"); 
                } 
                catch (Exception e) { 
                    ObjImage = null; 
                } 
                XSpeed = 2; 
                YSpeed = 2; 
                break; 
        } 
        int width = ObjImage.getWidth(); 
        int height = ObjImage.getHeight(); 
        int radius = width < height ? width : height; 
        SetImageSize(width, height, radius); 
    } 
 
    public void SetSpeed(int x, int y) 
    { 
        XSpeed = x; 
        YSpeed = y; 
    } 
 
    public int GetXSpeed() 
    { 
        return XSpeed; 
    } 
 
    public int GetYSpeed() 
    { 
        return YSpeed; 
    } 
 
}