1
9 package version27;
10
11
12 public class Bomb extends Actor {
13 public static final int UP_LEFT = 0;
14 public static final int UP = 1;
15 public static final int UP_RIGHT = 2;
16 public static final int LEFT = 3;
17 public static final int RIGHT = 4;
18 public static final int DOWN_LEFT = 5;
19 public static final int DOWN = 6;
20 public static final int DOWN_RIGHT = 7;
21
22 protected static final int BOMB_SPEED = 5;
23 protected int vx;
24 protected int vy;
25
26 public Bomb(Stage stage, int heading, int x, int y) {
27 super(stage);
28 this.x = x;
29 this.y = y;
30 String sprite ="";
31 switch (heading) {
32 case UP_LEFT : vx = -BOMB_SPEED; vy = -BOMB_SPEED; sprite="bombUL.gif";break;
33 case UP : vx = 0; vy = -BOMB_SPEED; sprite="bombU.gif";break;
34 case UP_RIGHT: vx = BOMB_SPEED; vy = -BOMB_SPEED; sprite="bombUR.gif";break;
35 case LEFT : vx = -BOMB_SPEED; vy = 0; sprite = "bombL.gif";break;
36 case RIGHT : vx = BOMB_SPEED; vy = 0; sprite = "bombR.gif";break;
37 case DOWN_LEFT : vx = -BOMB_SPEED; vy = BOMB_SPEED; sprite="bombDL.gif";break;
38 case DOWN : vx = 0; vy = BOMB_SPEED; sprite = "bombD.gif";break;
39 case DOWN_RIGHT : vx = BOMB_SPEED; vy = BOMB_SPEED; sprite = "bombDR.gif";break;
40 }
41 setSpriteNames( new String[] {sprite});
42 }
43
44 public void act() {
45 super.act();
46 y+=vy;
47 x+=vx;
48 if (y < 0 || y > Stage.HEIGHT || x < 0 || x > Stage.WIDTH)
49 remove();
50 }
51 }