-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCharacterSelectState.java
More file actions
197 lines (171 loc) · 4.83 KB
/
CharacterSelectState.java
File metadata and controls
197 lines (171 loc) · 4.83 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
package gameState;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import audio.MusicPlayer;
import main.GamePanel;
public class CharacterSelectState extends GameState {
private static int currentChoice;
private boolean isPlayer1Turn;
private String[] options = {
"DRAGON",
"MEGAMAN",
"BATMAN",
"SPIDER-MAN",
"TUTORIAL",
"CLOSE"
};
public static final int DRAGON = 0;
public static final int MEGAMAN = 1;
public static final int BATMAN = 2;
public static final int SPIDERMAN = 3;
public static final int TUTORIAL = 4;
public static final int EXIT = 5;
public static int player1Choice;
public static int player2Choice;
private BufferedImage dragonModel;
private BufferedImage megamanModel;
private BufferedImage batmanModel;
private BufferedImage spidermanModel;
MusicPlayer music = new MusicPlayer("resources/audio/topGear.wav");
public CharacterSelectState (GameStateManager gsm) {
this.gsm = gsm;
init();
}
public void init() {
isPlayer1Turn = true;
currentChoice = 0;
try {
music.stop();
dragonModel = ImageIO.read(getClass().getClassLoader().getResourceAsStream("resources/sprites/player/dragonModel.png"));
megamanModel = ImageIO.read(getClass().getClassLoader().getResourceAsStream("resources/sprites/player/megamanModel.png"));
batmanModel = ImageIO.read(getClass().getClassLoader().getResourceAsStream("resources/sprites/player/batmanModel.png"));
spidermanModel = ImageIO.read(getClass().getClassLoader().getResourceAsStream("resources/sprites/player/spidermanModel.png"));
}
catch (Exception e) {
e.printStackTrace();
}
}
public void update() {
}
private static boolean hasHappened;
public static boolean getHappened() { return hasHappened; }
public static int getPlayer1Choice() { return player1Choice; }
public static int getPlayer2Choice() { return player2Choice; }
public void select() {
if(currentChoice == DRAGON) {
if(isPlayer1Turn) {
player1Choice = DRAGON;
isPlayer1Turn = false;
}
else {
player2Choice = DRAGON;
hasHappened = true;
gsm.setCurrentState(GameStateManager.PLAYSTATE);
gsm.initState(GameStateManager.PLAYSTATE);
EntryState.stopMusic();
music.playSound();
}
}
if(currentChoice == MEGAMAN) {
if(isPlayer1Turn) {
player1Choice = MEGAMAN;
isPlayer1Turn = false;
}
else {
player2Choice = MEGAMAN;
hasHappened = true;
gsm.setCurrentState(GameStateManager.PLAYSTATE);
gsm.initState(GameStateManager.PLAYSTATE);
EntryState.stopMusic();
music.playSound();
}
}
if(currentChoice == BATMAN) {
if(isPlayer1Turn) {
player1Choice = BATMAN;
isPlayer1Turn = false;
}
else {
player2Choice = BATMAN;
hasHappened = true;
gsm.setCurrentState(GameStateManager.PLAYSTATE);
gsm.initState(GameStateManager.PLAYSTATE);
EntryState.stopMusic();
music.playSound();
}
}
if(currentChoice == SPIDERMAN) {
if(isPlayer1Turn) {
player1Choice = SPIDERMAN;
isPlayer1Turn = false;
}
else {
player2Choice = SPIDERMAN;
hasHappened = true;
gsm.setCurrentState(GameStateManager.PLAYSTATE);
gsm.initState(GameStateManager.PLAYSTATE);
EntryState.stopMusic();
music.playSound();
}
}
if(currentChoice == TUTORIAL) {
Help.shouldReturnToEntry = false;
gsm.setCurrentState(GameStateManager.HELP);
}
if(currentChoice == EXIT) {
System.exit(0);
}
}
public void draw(Graphics2D graphics) {
graphics.setColor(Color.BLACK);
graphics.fillRect(0, 0, GamePanel.WIDTH, GamePanel.HEIGHT);
graphics.setColor(Color.RED);
graphics.drawString("CHOOSE YOUR DESTINY", 80, 20);
for (int i = 0; i < options.length; i++) {
if(i == currentChoice)
graphics.setColor(Color.WHITE);
else
graphics.setColor(Color.RED);
graphics.drawString(options[i], 120, 100 + i * 15);
if(currentChoice == DRAGON) {
graphics.drawImage(dragonModel, 250, 75, null);
}
else if(currentChoice == MEGAMAN) {
graphics.drawImage(megamanModel, 250, 95, null);
}
else if(currentChoice == BATMAN) {
graphics.drawImage(batmanModel, 250, 110, null);
}
else if(currentChoice == SPIDERMAN) {
graphics.drawImage(spidermanModel, 250, 125, null);
}
graphics.setColor(Color.RED);
if(isPlayer1Turn)
graphics.drawString("PLAYER 1", 120, 70);
else
graphics.drawString("PLAYER 2", 120, 70);
}
}
public void keyPressed(int key) {
if(key == KeyEvent.VK_ENTER) {
select();
}
if(key == KeyEvent.VK_UP) {
currentChoice--;
if(currentChoice == -1) {
currentChoice = options.length - 1;
}
}
if(key == KeyEvent.VK_DOWN) {
currentChoice++;
if(currentChoice == options.length) {
currentChoice = 0;
}
}
}
public void keyReleased(int key) {
}
}