This repository was archived by the owner on Aug 10, 2021. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathHUD.java
More file actions
120 lines (101 loc) · 3.68 KB
/
Copy pathHUD.java
File metadata and controls
120 lines (101 loc) · 3.68 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
package game;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
public class HUD {
private Handler handler;
public int level = 0;
public static int score = 0 ;
public static int HEALTH = 200;
public static int SHIELD = 0;
public static boolean haveShield = false;
private Random r = new Random();
private boolean spawnP = true;
private boolean spawnB = true;
private boolean spawnS = true;
private boolean spawnBB = true;
public HUD(Handler handler){
this.handler = handler;
}
public void tick(){
score++;
if( score >= 200 ){
score = 0;
level += 1;
}
if(level == 3 ){
spawnPowerUp();
}
if(level == 6){
spawnBoss();
spawnB = false;
}
if(level == 12){
spawnBossB();
spawnBB = false;
}
if(level == 14){
spawnSpecialStage();
}
spawnS = false;
}
public void spawnPowerUp(){
if(spawnP){
for(int i = 0; i < 4; i++){
handler.addObject(new PowerUp(ID.ShieldPowerUp, (double) r.nextInt(Window.frame.getWidth()), (double) r.nextInt(Window.frame.getHeight())));
}
spawnP = false;
}}
public void spawnBoss(){
if(spawnB){
handler.addObject(new BossEnemyArm(ID.BossEnemyArm, (double) 10.0, (double) 0.0, 5, 187, handler));
handler.addObject(new BossEnemyArm(ID.BossEnemyArm, (double) 151, (double) 0.0, 123, 0, handler));
spawnB = false;
}}
public void spawnBossB(){
if(spawnBB){
handler.addObject(new BossEnemy(ID.BossEnemy, (double) Window.frame.getWidth() / 2.0 , 5.0 , handler));
spawnBB = false;
}}
public void spawnSpecialStage(){
if(spawnS){
for(int i = 0; i < 20; i++){
handler.addObject(new LightEnemy(ID.LightEnemy
,(double) r.nextInt(Window.frame.getWidth())
, (double) r.nextInt(Window.frame.getHeight()), handler));
handler.addObject(new TankEnemy(ID.TankEnemy
,(double) r.nextInt(Window.frame.getWidth())
, (double) r.nextInt(Window.frame.getHeight()), handler));
}
for(int i = 0; i < 3; i++){
handler.addObject(new BossEnemy(ID.BossEnemy, (double) 64, (double) 0.0, handler));
}
}}
public void render(Graphics g){
g.setColor(Color.WHITE);
g.drawString("Health ", 10, 24);
g.setColor(Color.magenta);
g.drawRect(10, 30, 200, 20);
g.setColor(Color.green);
g.fillRect(10,30,HEALTH,20);
g.setColor(Color.white);
g.drawString("Level: " + level, 10, 64);
if(haveShield){
// System.out.printf("%d", SHIELD);
g.setColor(Color.blue);
g.fillRect(10, 30, SHIELD, 20);
}
}
public void score(int score) {
HUD.score = score;
}
public int getScore() {
return score;
}
public void setLevel(int level){
this.level = level;
}
public int getLevel(){
return level;
}
}