-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameRenderer.java
More file actions
313 lines (257 loc) · 13.7 KB
/
GameRenderer.java
File metadata and controls
313 lines (257 loc) · 13.7 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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import java.awt.*;
import java.util.ArrayList;
import java.util.Random;
public class GameRenderer {
public static void drawBackground(Graphics2D g2d, int screenWidth, int screenHeight, Color gridColor) {
// Draw gradient background
GradientPaint gradient = new GradientPaint(0, 0, new Color(15, 15, 25),
screenWidth, screenHeight, new Color(25, 25, 35));
g2d.setPaint(gradient);
g2d.fillRect(0, 0, screenWidth, screenHeight);
// Draw grid
g2d.setColor(gridColor);
int gridSize = 50;
for (int i = 0; i < screenWidth; i += gridSize) {
g2d.drawLine(i, 0, i, screenHeight);
}
for (int j = 0; j < screenHeight; j += gridSize) {
g2d.drawLine(0, j, screenWidth, j);
}
}
public static void drawParticles(Graphics2D g2d, ArrayList<Particle> particles) {
for (Particle p : particles) {
g2d.setColor(new Color(p.color.getRed(), p.color.getGreen(), p.color.getBlue(), p.alpha));
g2d.fillOval(p.x, p.y, p.size, p.size);
}
}
public static void drawPlayer(Graphics2D g2d, Rectangle player, Color playerColor, int playerSize) {
// Player glow effect
g2d.setColor(new Color(playerColor.getRed(), playerColor.getGreen(), playerColor.getBlue(), 50));
g2d.fillOval(player.x - 5, player.y - 5, player.width + 10, player.height + 10);
// Player main
g2d.setColor(playerColor);
g2d.setStroke(new BasicStroke(3));
g2d.drawOval(player.x, player.y, player.width, player.height);
}
public static void drawBullets(Graphics2D g2d, ArrayList<Bullet> bullets, Color bulletColor, int bulletSize) {
for (Bullet bullet : bullets) {
// Bullet glow
g2d.setColor(new Color(255, 255, 255, 100));
g2d.fillOval(bullet.x - 2, bullet.y - 2, bulletSize + 4, bulletSize + 4);
// Bullet core
g2d.setColor(bulletColor);
g2d.fillOval(bullet.x, bullet.y, bulletSize, bulletSize);
}
}
public static void drawEnemies(Graphics2D g2d, ArrayList<Enemy> enemies, Color enemyColor) {
for (Enemy enemy : enemies) {
// Enemy glow
g2d.setColor(new Color(enemyColor.getRed(), enemyColor.getGreen(), enemyColor.getBlue(), 50));
g2d.fillOval(enemy.x - 2, enemy.y - 2, enemy.width + 4, enemy.height + 4);
// Enemy core
g2d.setColor(enemyColor);
g2d.fillOval(enemy.x, enemy.y, enemy.width, enemy.height);
}
}
public static void drawBoss(Graphics2D g2d, Boss boss, Color bossColor, int bossHealth, int maxBossHealth, int bossSize) {
// Boss glow
g2d.setColor(new Color(bossColor.getRed(), bossColor.getGreen(), bossColor.getBlue(), 50));
g2d.fillOval(boss.x - 10, boss.y - 10, boss.width + 20, boss.height + 20);
// Boss main
g2d.setColor(bossColor);
g2d.fillOval(boss.x, boss.y, boss.width, boss.height);
// Boss health bar
int healthBarWidth = bossSize;
int healthBarHeight = 10;
g2d.setColor(Color.RED);
g2d.fillRect(boss.x, boss.y - 15, healthBarWidth, healthBarHeight);
g2d.setColor(Color.GREEN);
g2d.fillRect(boss.x, boss.y - 15, (int)(healthBarWidth * ((float)bossHealth / maxBossHealth)), healthBarHeight);
}
public static void drawHUD(Graphics2D g2d, int playerHealth, int maxPlayerHealth, int score, long startTime,
int screenWidth, int screenHeight, int maxWidth, int maxHeight) {
// Player health bar
g2d.setColor(new Color(30, 30, 40));
g2d.fillRect(20, 20, maxPlayerHealth + 4, 14);
g2d.setColor(Color.RED);
g2d.fillRect(22, 22, maxPlayerHealth, 10);
g2d.setColor(Color.GREEN);
g2d.fillRect(22, 22, playerHealth, 10);
// Score and time
g2d.setColor(Color.WHITE);
g2d.setFont(new Font("Arial", Font.BOLD, 20));
g2d.drawString("Score: " + score, 20, 50);
long elapsedTime = (System.currentTimeMillis() - startTime) / 1000;
g2d.drawString("Time: " + elapsedTime + "s", 20, 80);
// Screen fill progress
int progressWidth = 200;
float fillProgress = Math.min((float)screenWidth / maxWidth, (float)screenHeight / maxHeight);
g2d.setColor(new Color(30, 30, 40));
g2d.fillRect(screenWidth - progressWidth - 30, 20, progressWidth + 4, 14);
g2d.setColor(new Color(100, 100, 255));
g2d.fillRect(screenWidth - progressWidth - 28, 22, (int)(progressWidth * fillProgress), 10);
g2d.setColor(Color.WHITE);
g2d.drawString("Fill: " + (int)(fillProgress * 100) + "%", screenWidth - progressWidth - 30, 50);
}
public static void drawPauseScreen(Graphics2D g2d, int screenWidth, int screenHeight) {
g2d.setColor(new Color(0, 0, 0, 150));
g2d.fillRect(0, 0, screenWidth, screenHeight);
g2d.setFont(new Font("Arial", Font.BOLD, 40));
g2d.setColor(Color.WHITE);
g2d.drawString("PAUSED", screenWidth / 2 - 80, screenHeight / 2);
}
public static void drawWinScreen(Graphics2D g2d, int screenWidth, int screenHeight, int score, long startTime, int timeLeft) {
g2d.setColor(new Color(0, 0, 0, 200));
g2d.fillRect(0, 0, screenWidth, screenHeight);
g2d.setFont(new Font("Arial", Font.BOLD, 40));
g2d.setColor(Color.YELLOW);
g2d.drawString("YOU WIN!", screenWidth / 2 - 100, screenHeight / 2 - 30);
g2d.setFont(new Font("Arial", Font.PLAIN, 20));
g2d.setColor(Color.WHITE);
g2d.drawString("Final Score: " + score, screenWidth / 2 - 60, screenHeight / 2 + 20);
long elapsedTime = (System.currentTimeMillis() - startTime) / 1000;
g2d.drawString("Time: " + elapsedTime + "s", screenWidth / 2 - 40, screenHeight / 2 + 50);
g2d.drawString("Click to Restart", screenWidth / 2 - 80, screenHeight / 2 + 100);
g2d.drawString("Auto-restart in: " + timeLeft + "s", screenWidth / 2 - 100, screenHeight / 2 + 130);
}
public static void drawGameOverScreen(Graphics2D g2d, int screenWidth, int screenHeight, int score, long startTime) {
g2d.setColor(new Color(0, 0, 0, 200));
g2d.fillRect(0, 0, screenWidth, screenHeight);
g2d.setFont(new Font("Arial", Font.BOLD, 40));
g2d.setColor(Color.RED);
g2d.drawString("GAME OVER", screenWidth / 2 - 120, screenHeight / 2 - 30);
g2d.setFont(new Font("Arial", Font.PLAIN, 20));
g2d.setColor(Color.WHITE);
g2d.drawString("Score: " + score, screenWidth / 2 - 40, screenHeight / 2 + 20);
long elapsedTime = (System.currentTimeMillis() - startTime) / 1000;
g2d.drawString("Time: " + elapsedTime + "s", screenWidth / 2 - 40, screenHeight / 2 + 50);
g2d.drawString("Click to Restart", screenWidth / 2 - 80, screenHeight / 2 + 100);
}
public static void drawMainMenu(Graphics2D g2d, int screenWidth, int screenHeight, Rectangle startButton, Rectangle exitButton, Random random) {
drawMainMenuBackground(g2d, screenWidth, screenHeight, random);
// Title
g2d.setFont(new Font("Arial", Font.BOLD, 50));
GradientPaint titleGradient = new GradientPaint(
screenWidth/2 - 150, screenHeight/2 - 150, new Color(100, 150, 255),
screenWidth/2 + 150, screenHeight/2 - 100, new Color(150, 200, 255)
);
g2d.setPaint(titleGradient);
g2d.drawString("FILL THE SCREEN", screenWidth/2 - 180, screenHeight/2 - 100);
// Subtitle
g2d.setFont(new Font("Arial", Font.PLAIN, 20));
g2d.setColor(new Color(200, 200, 200));
g2d.drawString("Survive and expand your screen to win!", screenWidth/2 - 160, screenHeight/2 - 60);
// Start button
drawMenuButton(g2d, startButton, "START", new Color(0, 150, 0), new Color(0, 200, 0));
// Exit button
drawMenuButton(g2d, exitButton, "EXIT", new Color(150, 0, 0), new Color(200, 0, 0));
// Instructions
g2d.setFont(new Font("Arial", Font.PLAIN, 16));
g2d.setColor(new Color(180, 180, 180));
String[] instructions = {
"WASD - Move",
"Mouse - Aim and Shoot",
"P - Pause",
"Escape - Return to Menu",
"CREDIT - 'NRIMIT_ANGANE'"
};
for (int i = 0; i < instructions.length; i++) {
g2d.drawString(instructions[i], 50, screenHeight - 120 + (i * 25));
}
}
private static void drawMainMenuBackground(Graphics2D g2d, int screenWidth, int screenHeight, Random random) {
// Animated background with particles
GradientPaint bgGradient = new GradientPaint(0, 0, new Color(10, 10, 20),
screenWidth, screenHeight, new Color(20, 20, 40));
g2d.setPaint(bgGradient);
g2d.fillRect(0, 0, screenWidth, screenHeight);
// Draw some animated stars/particles
g2d.setColor(new Color(255, 255, 255, 100));
for (int i = 0; i < 50; i++) {
int x = random.nextInt(screenWidth);
int y = random.nextInt(screenHeight);
int size = random.nextInt(3) + 1;
g2d.fillOval(x, y, size, size);
}
// Draw grid overlay
g2d.setColor(new Color(50, 50, 70, 30));
int gridSize = 40;
for (int i = 0; i < screenWidth; i += gridSize) {
g2d.drawLine(i, 0, i, screenHeight);
}
for (int j = 0; j < screenHeight; j += gridSize) {
g2d.drawLine(0, j, screenWidth, j);
}
}
private static void drawMenuButton(Graphics2D g2d, Rectangle button, String text, Color baseColor, Color hoverColor) {
// Button background with gradient
GradientPaint buttonGradient = new GradientPaint(
button.x, button.y, baseColor,
button.x, button.y + button.height, baseColor.darker()
);
g2d.setPaint(buttonGradient);
g2d.fillRoundRect(button.x, button.y, button.width, button.height, 10, 10);
// Button border
g2d.setColor(hoverColor);
g2d.setStroke(new BasicStroke(2));
g2d.drawRoundRect(button.x, button.y, button.width, button.height, 10, 10);
// Button text
g2d.setColor(Color.WHITE);
g2d.setFont(new Font("Arial", Font.BOLD, 24));
FontMetrics fm = g2d.getFontMetrics();
int textWidth = fm.stringWidth(text);
int textHeight = fm.getHeight();
g2d.drawString(text,
button.x + (button.width - textWidth) / 2,
button.y + (button.height + textHeight / 2) / 2);
}
public static void drawExplosion(Graphics2D g2d, int x, int y, int radius, Color color, int alpha) {
g2d.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha));
g2d.fillOval(x - radius, y - radius, radius * 2, radius * 2);
// Inner bright core
g2d.setColor(new Color(255, 255, 255, alpha / 2));
g2d.fillOval(x - radius/2, y - radius/2, radius, radius);
}
public static void drawPowerUp(Graphics2D g2d, Rectangle powerUp, Color color) {
// Rotating power-up with glow effect
long time = System.currentTimeMillis();
float rotation = (time % 2000) / 2000.0f * 360;
// Glow effect
g2d.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 100));
g2d.fillOval(powerUp.x - 5, powerUp.y - 5, powerUp.width + 10, powerUp.height + 10);
// Main power-up
g2d.setColor(color);
g2d.fillRect(powerUp.x, powerUp.y, powerUp.width, powerUp.height);
// Cross pattern
g2d.setColor(Color.WHITE);
g2d.fillRect(powerUp.x + powerUp.width/2 - 2, powerUp.y, 4, powerUp.height);
g2d.fillRect(powerUp.x, powerUp.y + powerUp.height/2 - 2, powerUp.width, 4);
}
public static void drawAimingArrow(Graphics2D g2d, Rectangle player, Point mousePosition, int playerSize) {
// Calculate player center
int playerCenterX = player.x + playerSize / 2;
int playerCenterY = player.y + playerSize / 2;
// Calculate angle to mouse
double angle = Math.atan2(mousePosition.y - playerCenterY, mousePosition.x - playerCenterX);
// Arrow properties
int arrowLength = 40;
int arrowEndX = playerCenterX + (int)(Math.cos(angle) * arrowLength);
int arrowEndY = playerCenterY + (int)(Math.sin(angle) * arrowLength);
// Draw aiming line
g2d.setColor(new Color(255, 255, 255, 150));
g2d.setStroke(new BasicStroke(2));
g2d.drawLine(playerCenterX, playerCenterY, arrowEndX, arrowEndY);
// Draw arrowhead
int arrowHeadSize = 8;
double arrowHeadAngle = Math.PI / 6; // 30 degrees
int arrowHead1X = arrowEndX - (int)(Math.cos(angle - arrowHeadAngle) * arrowHeadSize);
int arrowHead1Y = arrowEndY - (int)(Math.sin(angle - arrowHeadAngle) * arrowHeadSize);
int arrowHead2X = arrowEndX - (int)(Math.cos(angle + arrowHeadAngle) * arrowHeadSize);
int arrowHead2Y = arrowEndY - (int)(Math.sin(angle + arrowHeadAngle) * arrowHeadSize);
g2d.drawLine(arrowEndX, arrowEndY, arrowHead1X, arrowHead1Y);
g2d.drawLine(arrowEndX, arrowEndY, arrowHead2X, arrowHead2Y);
// Draw small dot at arrow tip for better visibility
g2d.setColor(new Color(255, 255, 255, 200));
g2d.fillOval(arrowEndX - 2, arrowEndY - 2, 4, 4);
}
}