-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePanel.java
More file actions
265 lines (213 loc) · 8.94 KB
/
Copy pathGamePanel.java
File metadata and controls
265 lines (213 loc) · 8.94 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import java.awt.event.*;
import java.util.ArrayList;
import java.awt.*;
import javax.swing.*;
public class GamePanel extends JPanel implements KeyListener
{
public static EndScreen endScreen = new EndScreen();
public static StartScreen startScreen = new StartScreen();
public static JFrame mainFrame;
public static JLabel userName;
public static ArrayList<plateform> currentPlateformCourse = new ArrayList<>();
public static ArrayList<plateform> plateformCourse1 = new ArrayList<>();
public static ArrayList<plateform> plateformCourse2 = new ArrayList<>();
public static ArrayList<plateform> plateformCourse3 = new ArrayList<>();
public static int plateformDelay = 0;
public static String playerName = startScreen.enterPlayerName.getText();
public static boolean endScreenFrame = false;
public static boolean startScreenFrame = true;
public static boolean frameRate = true;
public static boolean runGame = false;
public static lava lava = new lava(0, 900, 1200, 200);
public static int lavaDelay = 0;
public static boolean moveLeft;
public static boolean moveRight;
public static int playerVelX = 6;
public static int playerVelY;
public static int acceleration;
public static int playerSizeX = 50;
public static int playerSizeY = 50;
public static int playerCharacterBorderX = playerSizeX / 2;
public static int playerCharacterBorderY = playerSizeY / 2;
public static int spawnX;
public static int spawnY;
public static int playerPositionX;
public static int playerPositionY;
public static void main(String[]args) throws Exception
{
mainFrame = new JFrame();
GamePanel visuals = new GamePanel();
userName = new JLabel("Player: " + playerName);
System.out.println(playerName);
mainFrame.setSize(1200, 900);
mainFrame.setResizable(false);
userName.setBounds(0,0,300, 25);
userName.setFont(new Font("SansSerif", Font.PLAIN, 20));
mainFrame.add(userName);
mainFrame.add(visuals);
mainFrame.getContentPane().setBackground(Color.GRAY);
spawnX = 600 - playerCharacterBorderX;
spawnY = 900 - playerCharacterBorderY;
playerPositionX = spawnX;
playerPositionY = spawnY;
plateform1Presets();
mainFrame.addKeyListener(new KeyAdapter() {
public void keyPressed (KeyEvent e)
{
int key = e.getKeyCode();
if(key == 65 && playerPositionX > 0)
{
moveLeft = true;
}
if(key == 68 && playerPositionX < 1135)
{
moveRight = true;
}
if(key == 32 && playerVelY == 0)
{
playerVelY = -35;
acceleration = 10;
}
}
public void keyReleased(KeyEvent e){
int key = e.getKeyCode();
if(key == 65)
{
moveLeft = false;
}
if(key == 68)
{
moveRight = false;
}
}
public void keyTyped(KeyEvent e){}
});
/*int courseChoice = randCourse.nextInt(2+1);
if(courseChoice == 1)
{
currentPlateformCourse = plateformCourse1;
}
if(courseChoice == 2)
{
currentPlateformCourse = plateformCourse2;
}*/
while(frameRate == true)
{
mainFrame.repaint();
if(startScreenFrame == true)
{
startScreen.startFrame.setVisible(true);
mainFrame.setVisible(false);
runGame = false;
}
else
{
startScreen.startFrame.setVisible(false);
mainFrame.setVisible(true);
runGame = true;
}
if(endScreenFrame == true)
{
GamePanel.runGame = false;
startScreen.startFrame.setVisible(false);
mainFrame.setVisible(false);
endScreen.exitFrame.setVisible(true);
frameRate = false;
}
if(runGame == true)
{
character.playerMovement(moveLeft, moveRight);
currentPlateformCourse = plateformCourse1;
for(plateform plateform : currentPlateformCourse)
{
if(plateformDelay == 0)
{
plateform.blockPositionY += 1;
plateformDelay = 2;
}
else
{
plateformDelay--;
}
if(plateform.blockPositionY > 811)
{
plateform.blockPositionY = -600 - 50;
}
}
if(lava.lavaPositionY > 712)
{
if(lavaDelay == 0)
{
lava.lavaPositionY -= 1;
lavaDelay = 3;
}
else
{
lavaDelay--;
}
}
}
Thread.sleep(8);
}
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.fillRect(playerPositionX, playerPositionY, playerSizeX, playerSizeY);
for(plateform plateform : currentPlateformCourse)
{
g.setColor(Color.black);
g.fillRect(plateform.blockPositionX, plateform.blockPositionY, plateform.blockSizeX, plateform.blockSizeY);
}
g.setColor(Color.red);
g.fillRect(lava.lavaPositionX, lava.lavaPositionY, lava.lavaSizeX, lava.lavaSizeY);
}
public static void plateform1Presets()
{
//First set of plateforms for course number 1
plateformCourse1.add(new plateform(650,740,100,30));
plateformCourse1.add(new plateform(450,740,100,30));
plateformCourse1.add(new plateform(830,690,100,30));
plateformCourse1.add(new plateform(270,690,100,30));
plateformCourse1.add(new plateform(1000,580,100,30));
plateformCourse1.add(new plateform(100,580,100,30));
plateformCourse1.add(new plateform(790,470,100,30));
plateformCourse1.add(new plateform(290,470,100,30));
plateformCourse1.add(new plateform(930,350,100,30));
plateformCourse1.add(new plateform(130,350,100,30));
plateformCourse1.add(new plateform(1100,240,100,30));
plateformCourse1.add(new plateform(0,240,100,30));
plateformCourse1.add(new plateform(200,150,800,30));
//Second set of plateforms for course number 1
plateformCourse1.add(new plateform(550,50,100,30));
plateformCourse1.add(new plateform(750,0,100,30));
plateformCourse1.add(new plateform(350,0,100,30));
plateformCourse1.add(new plateform(950,-30,100,30));
plateformCourse1.add(new plateform(150,-30,100,30));
plateformCourse1.add(new plateform(1100,-100,100,30));
plateformCourse1.add(new plateform(0,-100,100,30));
plateformCourse1.add(new plateform(950,-210,100,30));
plateformCourse1.add(new plateform(150,-210,100,30));
plateformCourse1.add(new plateform(300,-280,600,30));
plateformCourse1.add(new plateform(950,-390,100,30));
plateformCourse1.add(new plateform(150,-390,100,30));
plateformCourse1.add(new plateform(1100,-490,100,30));
plateformCourse1.add(new plateform(0,-490,100,30));
plateformCourse1.add(new plateform(200,-600,800,30));
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'keyPressed'");
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'keyReleased'");
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'keyTyped'");
}
}