-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePanel.java
More file actions
111 lines (87 loc) · 2.17 KB
/
GamePanel.java
File metadata and controls
111 lines (87 loc) · 2.17 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
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.Timer;
import javax.swing.JPanel;
public class GamePanel extends JPanel implements ActionListener, KeyListener{
Timer timer;
GameObject GameObject;
final int MENU_STATE = 0;
final int GAME_STATE = 1;
final int END_STATE = 2;
int currentState = MENU_STATE;
public GamePanel() {
timer = new Timer(1000/60, this);
//GameObject = new GameObject();
}
void startGame() {
timer.start();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//GameObject.update();
if(currentState == MENU_STATE){
updateMenuState();
}
else if(currentState == GAME_STATE){
updateGameState();
}
else if(currentState == END_STATE){
updateEndState();
}
repaint();
}
public void paintComponent(Graphics g){
//GameObject.draw(g);
if(currentState == MENU_STATE){
drawMenuState(g);
}else if(currentState == GAME_STATE){
drawGameState(g);
}else if(currentState == END_STATE){
drawEndState(g);
}
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println("keyTyped");
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println("keyPressed");
if(e.getKeyCode()==KeyEvent.VK_ENTER) {
currentState=currentState+1;
if(currentState > END_STATE){
currentState = MENU_STATE;
}
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println("keyReleased");
}
void updateMenuState() {
}
void updateGameState() {
}
void updateEndState() {
}
void drawMenuState(Graphics g) {
g.setColor(Color.BLUE);
g.fillRect(0, 0, LeagueInvaders.WIDTH, LeagueInvaders.HEIGHT);
}
void drawGameState(Graphics g){
g.setColor(Color.BLACK);
g.fillRect(0, 0, LeagueInvaders.WIDTH, LeagueInvaders.HEIGHT);
}
void drawEndState(Graphics g) {
g.setColor(Color.RED);
g.fillRect(0, 0, LeagueInvaders.WIDTH, LeagueInvaders.HEIGHT);
}
}