Repository navigation
Expand file tree
/
Copy pathPlayer.java
More file actions
148 lines (136 loc) · 4.75 KB
/
Copy pathPlayer.java
File metadata and controls
148 lines (136 loc) · 4.75 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package game;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Rectangle;
public class Player extends GameObject {
private Handler handler;
private int counter = 5;
// Inherited fields
/*
private ID id;
private double x;
private double y;
private double velX;
private double velY;
*/
public Player(ID id, double x, double y, Handler handler) {
super(id, x, y);
this.handler = handler;
}
public Rectangle getBounds() {
return new Rectangle((int) x, (int) y, 32, 40);
}
public void tick() {
x += velX;
y += velY;
x = Game.clamp(x, (double) 0, (double) (Window.frame.getWidth() - 84));
y = Game.clamp(y, (double) 0, (double) ( Window.frame.getHeight() - 84)) ;
for (int i = 0; i < handler.object.size(); i++) {
GameObject obj = handler.object.get(i);
checkForCollision(obj, i);
}
if(counter >= 5){
handler.addObject(new FriendlyBullet(ID.FriendlyBullet, getBounds().getCenterX(),getBounds().getCenterY(), getVelX(), getVelY(), handler));
counter = 0;
}
counter++;
}
public void render(Graphics g) {
g.setColor(Color.BLUE);
g.fillOval((int) x, (int) y, 32, 40);
}
@Override
public void setHealth(int damage){}
private void checkForCollision(GameObject obj, int i) {
if (this.getBounds().intersects(obj.getBounds())) {
if (obj.getId() == ID.LightEnemy) {
handler.removeObject(obj);
if(HUD.SHIELD <= 0 ){
HUD.HEALTH -= 20;
if (HUD.HEALTH <= 0){
Game.gameState = STATE.GAMEOVER;
handler.object.clear();
}
}else{
HUD.SHIELD -= 20;
if (HUD.SHIELD <= 0 ) {
HUD.SHIELD = 0;
HUD.haveShield = false;
}
}
//handler.object.set(i, new InvisibleObject(ID.InvisibleObject, 0, 0));
}
else if (obj.getId() == ID.TankEnemy) {
handler.removeObject(obj);
if(HUD.SHIELD <= 0 ){
HUD.HEALTH -= 5;
if (HUD.HEALTH <= 0){
Game.gameState = STATE.GAMEOVER;
handler.object.clear();
}
}else{
HUD.SHIELD -= 5;
if (HUD.SHIELD <= 0 ) {
HUD.SHIELD = 0;
HUD.haveShield = false;
}
}
//handler.object.set(i, new InvisibleObject(ID.InvisibleObject, 0, 0));
}
else if (obj.getId() == ID.BossEnemy) {
if(HUD.SHIELD <= 0 ){
HUD.HEALTH -= 100;
if (HUD.HEALTH <= 0){
Game.gameState = STATE.GAMEOVER;
handler.object.clear();
}
}else{
HUD.SHIELD -= 100;
if (HUD.SHIELD <= 0 ) {
HUD.SHIELD = 0;
HUD.haveShield = false;
}
}
}else if (obj.getId() == ID.BossEnemyArm) {
if(HUD.SHIELD <= 0 ){
HUD.HEALTH -= 100;
if (HUD.HEALTH <= 0){
Game.gameState = STATE.GAMEOVER;
handler.object.clear();
}
}else{
HUD.SHIELD -= 100;
if (HUD.SHIELD <= 0 ) {
HUD.SHIELD = 0;
HUD.haveShield = false;
}
}
}
else if (obj.getId() == ID.BossEnemyBullet){
handler.removeObject(obj);
if(HUD.SHIELD <= 0 ){
HUD.HEALTH -= 5;
if (HUD.HEALTH <= 0){
Game.gameState = STATE.GAMEOVER;
handler.object.clear();
}
}else{
HUD.SHIELD -= 5;
if (HUD.SHIELD <= 0 ) {
HUD.SHIELD = 0;
HUD.haveShield = false;
}
}
}
else if (obj.getId() == ID.ShieldPowerUp){
handler.removeObject(obj);
if (HUD.SHIELD >= 100) {
HUD.SHIELD = 200;
} else {
HUD.SHIELD += 100;
}
HUD.haveShield = true;
}
}
}
}