-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZombieAlmanac.java
More file actions
189 lines (155 loc) · 4.38 KB
/
ZombieAlmanac.java
File metadata and controls
189 lines (155 loc) · 4.38 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
// ZombieAlmanac.java
// David Wang
// Displays all the zombies in the almanac
// User can interact with the tombs
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
class ZombieAlmanac extends JFrame implements ActionListener{
MainMenu menu;
AlmanacMenu almanac;
ZombieAlmanacPanel zombiepanel;
String comingfrom;
PvZ pvz;
javax.swing.Timer myTimer;
public ZombieAlmanac (MainMenu menu,String comingfrom, PvZ pvz){
super();
this.menu = menu;
this.comingfrom = comingfrom; // must know if coming from pause or main menu
this.pvz = pvz; // to know what to set back to visible when almanac is closed
setLayout(null);
zombiepanel = new ZombieAlmanacPanel(this);
zombiepanel.setSize(818,647);
zombiepanel.setLocation(0,0);
add(zombiepanel);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(818,647);
myTimer = new javax.swing.Timer(100,this);
myTimer.start();
}
public void mainMenu(){
if(comingfrom.equals("menu")){
menu.stopAlmanacMusic();
menu.playMusic();
menu.setVisible(true);
setVisible(false);
}
if(comingfrom.equals("game")){
pvz.setVisible(true);
pvz.getPanel().setInAlmanac(false);
pvz.getPanel().setMusicLoop();
setVisible(false);
}
}
public void backToAlmanac(){
almanac = new AlmanacMenu(menu,comingfrom,pvz);
setVisible(false);
}
public void actionPerformed(ActionEvent evt){
Object source = evt.getSource();
zombiepanel.draw();
}
public static void main(String[]args){
ZombieAlmanac menu = new ZombieAlmanac(null,null,null);
}
}
class ZombieAlmanacPanel extends JPanel implements MouseListener, MouseMotionListener{
ZombieAlmanac menu;
Image ZombieAlmanacPic, AlmanacPic, QuitPic;
int[] pos;
boolean clicked;
ArrayList<Image> zombies = new ArrayList<Image>();
Rectangle[] zombieCards = new Rectangle[11];
boolean[] displayZombies = new boolean[11];
public void mouseClicked(MouseEvent evt){
clicked = true;
}
public void mouseExited(MouseEvent evt){}
public void mouseEntered(MouseEvent evt){}
public void mouseReleased(MouseEvent evt){
clicked = true;
}
public void mousePressed(MouseEvent evt){
clicked = false;
}
public void mouseMoved(MouseEvent evt){
pos = new int[]{evt.getX(),evt.getY()};
}
public void mouseDragged(MouseEvent evt){
pos = new int[]{evt.getX(),evt.getY()};
}
public ZombieAlmanacPanel(ZombieAlmanac menu){
super();
setFocusable(true);
grabFocus();
addMouseListener(this);
addMouseMotionListener(this);
this.menu = menu;
pos = new int[]{0,0};
clicked = false;
ZombieAlmanacPic = new ImageIcon("Images/Menus/ZombieAlmanac.png").getImage();
AlmanacPic = new ImageIcon("Images/Menus/ReturnToAlmanac.png").getImage();
QuitPic = new ImageIcon("Images/Menus/ExitAlmanac.png").getImage();
for(int i = 1; i < 12; i ++){
zombies.add(new ImageIcon(String.format("Images/Menus/Zombies Almanac Entries/almanac%s.png",i)).getImage());
}
for(int i = 0; i < 5; i++){
zombieCards[i] = new Rectangle(30+(i*85),95,60,55);
}
for(int i = 5; i < 7; i ++){
zombieCards[i] = new Rectangle(30+((i%5)*85),175,60,55);
}
for(int i = 0; i < displayZombies.length; i ++){
displayZombies[i] = false;
}
}
public void checkZombieRectCollide(){
for(int i = 0; i < zombieCards.length; i ++){
if(zombieCards[i] != null){
if(zombieCards[i].contains(pos[0],pos[1])){
for(int j = 0; j < displayZombies.length; j ++){
displayZombies[j] = false;
}
displayZombies[i] = true;
}
}
}
}
public void draw(){
repaint();
}
public void paintComponent(Graphics g){
g.drawImage(ZombieAlmanacPic,0,0,this);
Rectangle exit = new Rectangle(35,570,157,20);
Rectangle menuexit = new Rectangle(678,570,85,22);
if(exit.contains(pos[0],pos[1])){ // go back to almanac menu
g.drawImage(AlmanacPic,0,0,this);
if(clicked){
menu.backToAlmanac();
}
}
if(menuexit.contains(pos[0],pos[1])){ // go back to main menu or pause screen
g.drawImage(QuitPic,0,0,this);
if(clicked){
menu.mainMenu();
}
}
for(int i = 0; i < zombies.size(); i ++){
if(displayZombies[i]){
g.drawImage(zombies.get(i),457,81,this);
}
}
if(clicked){
checkZombieRectCollide();
clicked = false;
}
if(exit.contains(pos[0],pos[1])){
g.drawImage(AlmanacPic,0,0,this);
if(clicked){
menu.backToAlmanac();
}
}
}
}