-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeathPanel.java
137 lines (121 loc) · 4.07 KB
/
DeathPanel.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
128
129
130
131
132
133
134
135
136
137
/* e-LEMON-ators */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.ArrayList;
import java.io.File;
import javax.imageio.ImageIO;
import java.applet.*;
public class DeathPanel extends JPanel
{
private BufferedImage myImage;
private Graphics myBuffer;
private final int FRAME = 600;
private Image img;
private JFrame frame;
private JButton reButton, homeButton;
private AudioClip music;
private Monster ghost;
private String[] gArray = {"sprites/ghost_one.png", "sprites/ghost_two.png"};
private Timer gTimer;
private int gIndex = 0;
public DeathPanel(JFrame frame)
{
this.frame = frame;
setLayout(new GridLayout(5, 1));
myImage = new BufferedImage(FRAME, FRAME, BufferedImage.TYPE_INT_RGB);
myBuffer = myImage.getGraphics();
myBuffer.setColor(new Color(0, 0, 0));
myBuffer.fillRect(0, 0, FRAME, FRAME);
myBuffer.setColor(Color.WHITE);
myBuffer.setFont(new Font("Chiller", Font.BOLD, 100));
myBuffer.drawString("lol u noob",130,225);
ghost = new Monster(250, 250, "sprites/ghost_one.png");
ghost.draw(myBuffer);
gTimer = new Timer(300, new Ghost());
gTimer.start();
/********FORMATTING*********/
JPanel trash1 = new JPanel();
trash1.setOpaque(false);
add(trash1);
JPanel trash2 = new JPanel();
trash2.setOpaque(false);
add(trash2);
JPanel trash3 = new JPanel();
trash3.setOpaque(false);
add(trash3);
/**************************/
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.setOpaque(false);
add(buttonPanel);
reButton = new JButton ("Replay");
reButton.setFont(new Font("Chiller", Font.BOLD, 50));
reButton.setBackground(Color.WHITE);
reButton.setForeground(Color.RED);
reButton.setOpaque(true);
reButton.setHorizontalAlignment(SwingConstants.CENTER);
reButton.setFocusPainted(false);
reButton.addActionListener(new Replay());
buttonPanel.add(reButton);
homeButton = new JButton ("Home");
homeButton.setFont(new Font("Chiller", Font.BOLD, 50));
homeButton.setBackground(Color.WHITE);
homeButton.setForeground(Color.RED);
homeButton.setOpaque(true);
homeButton.setHorizontalAlignment(SwingConstants.CENTER);
homeButton.setFocusPainted(false);
homeButton.addActionListener(new Home());
buttonPanel.add(homeButton);
music = Sound.getClip("sound/death.wav");
Sound.loop(music);
try {
Thread.currentThread().sleep(5);
}
catch (Exception e) {
e.printStackTrace();
}
}
public void paintComponent(Graphics g)
{
g.drawImage(myImage, 0, 0, getWidth(), getHeight(), null);
}
private class Ghost implements ActionListener
{
public void actionPerformed (ActionEvent a)
{
myBuffer.setColor(new Color(0, 0, 0));
myBuffer.fillRect(0, 0, FRAME, FRAME);
myBuffer.setColor(Color.WHITE);
myBuffer.setFont(new Font("Chiller", Font.BOLD, 100));
myBuffer.drawString("lol u noob",130,225);
ghost.setSprite(gArray[gIndex]);
gIndex++;
gIndex %= gArray.length;
ghost.draw(myBuffer);
repaint();
}
}
private class Replay implements ActionListener
{
public void actionPerformed(ActionEvent a)
{
Sound.stop(music);
gTimer.stop();
frame.setContentPane(new GamePanel(frame));
frame.revalidate();
frame.setVisible(true);
}
}
private class Home implements ActionListener
{
public void actionPerformed(ActionEvent a)
{
Sound.stop(music);
gTimer.stop();
frame.setContentPane(new HomePanel(frame));
frame.revalidate();
frame.setVisible(true);
}
}
}