-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionMenu.java
More file actions
62 lines (57 loc) · 1.84 KB
/
SelectionMenu.java
File metadata and controls
62 lines (57 loc) · 1.84 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
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class SelectionMenu extends JPanel implements KeyListener{
private Image background = new ImageIcon("sprites/selectionBackground.jpg").getImage();
BoxHead BH;
private boolean[] keys;
private Font font = new Font("Impact", Font.PLAIN, 35);
public SelectionMenu(BoxHead b){
keys = new boolean[65535];
BH=b;
addKeyListener(this);
setSize(800,640);
}
public void keyTyped(KeyEvent e){}
public void keyPressed(KeyEvent e){keys[e.getKeyCode()]=true;}
public void keyReleased(KeyEvent e){keys[e.getKeyCode()]=false;}
public void checkUnPause(){
//check if the user decided to return to the game
if (keys[KeyEvent.VK_P]){
BH.state=BH.GAME;
BH.game.requestFocus();
keys[KeyEvent.VK_P]=false; //set to false so next time selectionMenu is needed, keys[KeyEvent.VK_P] would not be set at true and disrupt the program
}
}
public void paintComponent(Graphics g){
g.setFont(font);
g.drawImage(background,0,0,this);
//draw the names of all the available upgrades
//if they have been obtained, they are in green
//if not then they are in read
//half on one side half on the other side of the screen
for (int i=0;i<13;i++){
if (BH.game.getNextUpgrade()>i){
g.setColor(Color.green);
}
else{
g.setColor(Color.red);
}
g.drawString(BH.ug.getUpgradeString(i), 30, 150+i*30);
}
for (int i=13;i<26;i++){
if (BH.game.getNextUpgrade()>i){
g.setColor(Color.green);
}
else{
g.setColor(Color.red);
}
g.drawString(BH.ug.getUpgradeString(i), 430, 150+(i-13)*30);
}
}
}