-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmid
More file actions
216 lines (179 loc) · 5.62 KB
/
mid
File metadata and controls
216 lines (179 loc) · 5.62 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
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.sound.sampled.*;
import javax.swing.*;
class panelAnimation extends JPanel implements KeyListener, ActionListener {
Random rand = new Random();
int n = rand.nextInt(800) + 1;
URL sound;
URL sound2;
Clip clip;
Clip clip2;
AudioInputStream audioinput;
AudioInputStream audioinput2;
int bgx1, bgx2, bgx3, way, bgy;
int hu, sp, walk, x, up, y;
BufferedImage image1;
BufferedImage image2;
BufferedImage l1;
BufferedImage l2;
BufferedImage l3;
BufferedImage r1;
BufferedImage r2;
BufferedImage r3;
Boolean jump;
Boolean jumpl;
Boolean jumpr;
Boolean down;
Boolean downn;
Boolean l;
Boolean r;
Boolean u;
panelAnimation() throws IOException, LineUnavailableException, UnsupportedAudioFileException {
sound = new URL("file:///C:\\Users\\GELAB\\Desktop\\Gamejava-master\\Lab5As1\\stepstone.wav");
sound2 = new URL("file:///C:\\Users\\GELAB\\Desktop\\Gamejava-master\\Lab5As1\\movement.wav");
clip = AudioSystem.getClip();
audioinput = AudioSystem.getAudioInputStream(sound);
clip2 = AudioSystem.getClip();
audioinput2 = AudioSystem.getAudioInputStream(sound2);
clip.open(audioinput);
clip2.open(audioinput2);
this.image1 = ImageIO.read(new File("C:\\Users\\GELAB\\Desktop\\Gamejava-master\\Lab5As1\\bg1.jpg"));
this.image2 = ImageIO.read(new File("C:\\Users\\GELAB\\Desktop\\Gamejava-master\\Lab5As1\\rock.png"));
this.l1 = ImageIO.read(new File("C:\\Users\\GELAB\\Desktop\\Gamejava-master\\Lab5As1\\a1.jpg"));
this.l2 = ImageIO.read(new File("C:\\Users\\GELAB\\Desktop\\Gamejava-master\\Lab5As1\\a2.jpg"));
this.l3 = ImageIO.read(new File("C:\\Users\\GELAB\\Desktop\\Gamejava-master\\Lab5As1\\a3.jpg"));
new Timer(10, this).start();
bgx1 = 0;
bgx2 = 1600;
bgx3 = 800;
way = 0;
sp = 5;
bgy = 0;
hu = 0;
walk = 0;
x = 350;
y = 0;
up = 300;
jump = false;
jumpl = false;
jumpr = false;
down = false;
downn = false;
l = false;
u = false;
setFocusable(true);
addKeyListener(this);
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(this.image1, bgx1, bgy, null);
g.drawImage(this.image1, bgx2, bgy, null);
if (hu == 1) {
if ((walk / 3) % 3 == 0) {
g.drawImage(this.l1, x, up, 150, 150, null);
} else if ((walk / 3) % 3 == 1) {
g.drawImage(this.l2, x, up, 150, 150, null);
} else if ((walk / 3) % 3 == 2) {
g.drawImage(this.l3, x, up, 150, 150, null);
}
}
g.drawImage(this.image2, n - way, y, 100, 100, null);
repaint();
}
@Override
public void keyPressed(KeyEvent ke) {
int key = ke.getKeyCode();
if (down == true) {
} else {
if (key == KeyEvent.VK_LEFT) {
l = true;
clip.loop(Clip.LOOP_CONTINUOUSLY);
clip.start();
hu = 1;
walk++;
clip2.setMicrosecondPosition(0);
clip2.stop();
way -= sp;
bgx1 += sp;
bgx2 += sp;
if (bgx1 >= 1600) {
bgx1 = -1600;
}
if (bgx2 >= 1600) {
bgx2 = -1600;
}
}
if (key == KeyEvent.VK_RIGHT) {
r = true;
clip.loop(Clip.LOOP_CONTINUOUSLY);
clip.start();
hu = 1;
walk++;
clip2.setMicrosecondPosition(0);
clip2.stop();
way += sp;
bgx1 -= sp;
bgx2 -= sp;
if (bgx1 <= -1600) {
bgx1 = 1600;
}
if (bgx2 <= -1600) {
bgx2 = 1600;
}
}
}
}
@Override
public void keyTyped(KeyEvent ke) {
}
@Override
public void keyReleased(KeyEvent ke) {
int key = ke.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
walk = 0;
clip.stop();
}
if (key == KeyEvent.VK_RIGHT) {
walk = 0;
clip.stop();
}
}
@Override
public void actionPerformed(ActionEvent ae) {
System.out.println(way);
if (y >= 600) {
n = rand.nextInt(800) + 1;
y = 0;
} else {
y++;
}
if(y>=up-100&&y<=up+150&&(n - way)>=x-70&&(n - way)<=x+140){
down=true;
}
else{
down=false;
}
}
}
class frameAnimation extends JFrame {
frameAnimation() throws IOException, LineUnavailableException, UnsupportedAudioFileException {
this.add(new panelAnimation());
this.setTitle("Wunchissanuphong");
}
}
public class main {
public static void main(String[] args) throws IOException, LineUnavailableException, UnsupportedAudioFileException {
frameAnimation f = new frameAnimation();
f.setSize(800, 600);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}