-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.java
127 lines (112 loc) · 3.53 KB
/
Player.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.awt.*;
import java.awt.Rectangle;
public class Player extends GameObject {
private Game game;
private Handler handler;
public static int ammo = 5;
public static int deathCounter = 300;
public static int eDeathCounter = 7500;
public static boolean death = false;
public Player(int x, int y, ID id, Handler handler, Game game) {
super(x, y, id);
this.handler = handler;
this.game = game;
}
public Rectangle getBounds() {
return new Rectangle(x, y, 64, 64);
}
public void update() {
x += velX;
y += velY;
x = Game.clamp(x, 0, Game.WIDTH-64);
y = Game.clamp((int)y, 0, Game.HEIGHT - 96);
collision();
shoot();
death();
if (death) {
eDeathCounter--;
if(eDeathCounter <= 0) {
game.gameState = Game.STATE.Win;
}
}
}
private void collision(){
for(int i=0; i<handler.object.size(); i++) {
GameObject tempObject = handler.object.get(i);
if(tempObject.getId() == ID.Meteor) {
if(getBounds().intersects(tempObject.getBounds())) {
HUD.HEALTH -= 2;
handler.removeObject(tempObject);
}
}
if(tempObject.getId() == ID.Enemy) {
if(getBounds().intersects(tempObject.getBounds())) {
HUD.HEALTH -= 50;
if(HUD.BOSS1 > 0) {
HUD.BOSS1 -= 50;
this.setX(tempObject.getX());
this.setY(tempObject.getY() + 256);
} else if (HUD.BOSS2 > 0) {
HUD.BOSS2 -= 50;
this.setX(tempObject.getX());
this.setY(tempObject.getY() + 256);
} else if (HUD.BOSS3 > 0) {
HUD.BOSS3 -= 50;
this.setX(tempObject.getX());
this.setY(tempObject.getY() + 256);
} else if (HUD.BOSS4 > 0) {
HUD.BOSS4 -= 50;
this.setX(tempObject.getX());
this.setY(tempObject.getY() + 256);
} else if (HUD.BOSS5 > 0) {
HUD.BOSS5 -= 50;
this.setX(tempObject.getX());
this.setY(tempObject.getY() + 256);
} else if (HUD.BOSS5 <= 0) {
handler.removeObject(tempObject);
for (int j=0; j<25; j++) {
int tempX = tempObject.getX();
int tempY = tempObject.getY();
handler.addObject(new Explosion(tempX-i, tempY+i, ID.Explosion));
handler.addObject(new Explosion(tempX+i, tempY-i, ID.Explosion));
handler.addObject(new Explosion(tempX, tempY, ID.Explosion));
}
death = true;
}
}
}
}
}
private void shoot(){
if (Game.shot && HUD.BULLET!=0){
handler.addObject(new Laser(this.getX()+16,this.getY(),ID.Laser,handler, game));
HUD.BULLET -= 1;
}
if (HUD.BULLET == 0 && ammo != 0) {
HUD.BULLET = 100;
ammo --;
}
}
public void draw(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Image img1 = Toolkit.getDefaultToolkit().getImage("64Ship.png");
g.drawImage(img1, x, y, null);
}
public void death() {
if(HUD.BOSSPASS >= Game.HEIGHT) {
game.gameState = Game.STATE.Lose;
}
if (HUD.HEALTH <= 0) {
for (int i=0; i<25; i++) {
handler.addObject(new Explosion(x-i, y+i, ID.Explosion));
handler.addObject(new Explosion(x+i, y-i, ID.Explosion));
handler.addObject(new Explosion(x, y, ID.Explosion));
}
if(deathCounter <= 0) {
game.gameState = Game.STATE.Lose;
} else {
deathCounter --;
}
}
}
}