-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
51 lines (45 loc) · 1.02 KB
/
Player.java
File metadata and controls
51 lines (45 loc) · 1.02 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
/**
* @(#)Player.java
*
* Set up player; contains methods relating to the player (eg. making the player 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 Player extends Common{
public int pW,pH; //height and width
private BufferedImage img;
/********************** Constructor **********************/
public Player(int x){
//get sprite
try {
img = ImageIO.read(new File("player.png"));
}
catch (IOException e) {
System.out.println(e);
}
setX(x);
setY(510);
pW = img.getWidth();
pH = img.getHeight();
setSpeed(6);
}
/********************** Methods **********************/
//move
public void pMove(int dir,int w, int h){
setX(getX() + getSpeed() * dir);
}
//to Image for drawing
public Image toImage(){
return (Image)img;
}
//kill the player
public void die(int initX){
setVisible(false);
setX(initX);
}
}