-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hud.pde
179 lines (166 loc) · 4.18 KB
/
Hud.pde
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//----------------------------------------------------------
// HUD class
//----------------------------------------------------------
class HUD {
// fields
int condition;
float x,y;
float mapPX,mapPY = 0;
float mappedSpeed = (player.speed*0.1)-.1;
HashMap<float[],float[]> hm = new HashMap<float[],float[]>();
//constructor
HUD(float x, float y) {
this.x = x;
this.y = y;
condition = 0;
// save this for later
for(int i=0; i<ss.size();i++){
SpaceStation temp = ss.get(i);
float[] coords = {temp.x,temp.y};
float spaceX = temp.x;
float spaceY = temp.y;
//if(flag){
float xdiff = spaceX - player.x;
float ydiff = spaceY - player.y;
float[] diffArray = {xdiff, ydiff};
// they key will be the x/y coords cause it's a unique id
hm.put(coords,diffArray);
}
}
void display(){
rectMode(CORNER);
fill(0);
//rect(x+1350,y-900,600,1800);
rect(x+1000,y-1000,700,2000);
// display highscore:
fill(255,0,0);
textSize(75);
text("Hi-Score", x+1000, y-900);
fill(255);
text(highscore, x+1000, y-800);
// display 1 up:
text("1UP", x+1000, y-700);
text(oneUp, x+1000, y-600);
// display condition:
text("CONDITION", x+1000, y-500);
//green
if(condition == 0){
fill(0,255,0);
rect(x+1000, y-450,600,100);
fill(0);
textSize(105);
text("GREEN", x+1125, y-360);
}
//yellow
if(condition == 1){
fill(255,255,0);
rect(x+1000, y-450,600,100);
fill(0);
textSize(105);
text("YELLOW", x+1100, y-360);
}
textSize(100);
// map
fill(155,0,255);
rect(x+1000, y-320,600,1000);
// set map limits:
float nearX = x+1000;
float farX = x+1600;
float nearY = y-320;
float farY = y+680;
// mapped player circle
//
// BUG: x (y?) moves circle to middle briefly
// when crossing a limit, fill covers this mistake
//eColor = eColor == 0 ? 255 : 0; // for blinking effect
fill(255);
float ex = x+1300+mapPX;
float ey = y+180+mapPY;
// check limits
if(nearX >= ex-5){
fill(155,0,255);
ex = x+1300;
mapPX = 300-5;
//map/update real player
player.x = 4345.0;
//println(player.getX());
}
if(farX <= ex+5){
fill(155,0,255);
ex = x+1300;
mapPX = -300+5;
//map/update real player
player.x = -3045.0;
//println(player.getX());
}
if(nearY >= ey-5){
fill(155,0,255);
ey = y-320;
mapPY = 500-5;
//map/update real player
player.y = 6695.0;
//println(player.getY());
}
if(farY <= ey+5){
fill(155,0,255);
ex = y-320;
mapPY = -500+5;
//map/update real player
player.y= -5695.0;
//println(player.getY());
}
ellipse(ex,ey,10,10);
// enemy space station locations on map:
for (Map.Entry ent : hm.entrySet()) {
float[] keyCoords = (float[])ent.getKey();
boolean flag = false;
for(int i=0; i<ss.size(); i++){
SpaceStation temp = ss.get(i);
if(temp.x == keyCoords[0] && temp.y == keyCoords[1]){
if(temp.count < 1){
flag = true;
}
}
}
float[] value = (float[])ent.getValue();
// draw map representation here:
if(flag == false){
fill(0,255,0);
ellipse(x+1300+value[0]/12.5,y+180+value[1]/12.5,13,13);
}
}
// lives
int distance = 0;
for(int i=0; i<numLives; i++){
Ship tempLife = new Ship(x+1050+distance,y+725);
//noStroke();
rectMode(CENTER);
tempLife.shipSprite();
rectMode(CORNER);
distance+=100;
}
// round number
fill(255);
text("ROUND:", x+1000, y+875);
text(level, x+1400, y+875);
}
void update(){
x = player.x;
y = player.y;
String hudDir = player.dirFlag;
switch(hudDir){
case "w":
mapPY-=mappedSpeed;
break;
case "a":
mapPX-=mappedSpeed;
break;
case "s":
mapPY+=mappedSpeed;
break;
case "d":
mapPX+=mappedSpeed;
break;
}
}
}