-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCraftMissile.java
More file actions
35 lines (30 loc) · 880 Bytes
/
CraftMissile.java
File metadata and controls
35 lines (30 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.awt.*;
import javax.swing.*;
public class CraftMissile
{
private int x, y;
private Image myImage;
boolean visible;
private final int BOARD_WIDTH = 390;
private final int MISSILE_SPEED = 2;
public CraftMissile( int xpos, int ypos )
{
ImageIcon ii = new ImageIcon( getClass().getResource( "missile.png" ) );
myImage = ii.getImage();
visible = true;
x = xpos;
y = ypos;
}
public Image getImage() { return myImage; }
public int getX() { return x; }
public int getY() { return y; }
public boolean isVisible() { return visible; }
// missile moves at a constant speed from left side to right side of board
// when it moves past the board, it becomes invisible
public void move()
{
x = x + MISSILE_SPEED;
if( x > BOARD_WIDTH )
visible = false;
}
}