-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMystery.java
More file actions
59 lines (52 loc) · 1.24 KB
/
Mystery.java
File metadata and controls
59 lines (52 loc) · 1.24 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @(#)Mystery.java
*
* Sets up the mystery ship/ufo; contains methods relating to it (eg. making the ship move)
*
* @author
* @version 1.00 2021/11/22
*/
import java.awt.image.BufferedImage;
import java.awt.*;
import java.io.*;
import javax.imageio.ImageIO;
public class Mystery extends Common{
public int mW,mH; //height and width
private BufferedImage img;
/********************** Constructors **********************/
public Mystery(){
setVisible(false); //set invisible by default
}
public Mystery(int x){
setX(x);
setY(30);
setSpeed(3);
setVisible(false);
//get sprite
try {
img = ImageIO.read(new File("mystery.png"));
}
catch (IOException e) {
System.out.println(e);
}
//get width and height from image
mW = img.getWidth();
mH = img.getHeight();
}
/********************** Methods **********************/
//move
public void mMove(int screenW){
setX(getX() + getSpeed());
reachedEnd(screenW);
}
//set visibility to false if it reaches edge of screen
public void reachedEnd(int screenW){
if(getX() >= screenW){
setVisible(false);
}
}
//get Image so it can be drawn
public Image toImage(){
return (Image)img;
}
}