Compare commits
3 Commits
90d7c933ba
...
f60ecaf688
Author | SHA1 | Date |
---|---|---|
|
f60ecaf688 | 3 years ago |
|
4122bfa034 | 3 years ago |
|
5334cb5391 | 3 years ago |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,95 @@
|
||||
package com.example.tankbattle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.DataLine;
|
||||
import javax.sound.sampled.SourceDataLine;
|
||||
|
||||
public class Audio {
|
||||
|
||||
byte[] b = new byte[1024 * 1024 * 15];
|
||||
|
||||
public void loop() {
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
int len = 0;
|
||||
sourceDataLine.open(audioFormat, 1024 * 1024 * 15);
|
||||
sourceDataLine.start();
|
||||
//System.out.println(audioInputStream.markSupported());
|
||||
audioInputStream.mark(12358946);
|
||||
while ((len = audioInputStream.read(b)) > 0) {
|
||||
sourceDataLine.write(b, 0, len);
|
||||
}
|
||||
audioInputStream.reset();
|
||||
|
||||
sourceDataLine.drain();
|
||||
sourceDataLine.close();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private AudioFormat audioFormat = null;
|
||||
private SourceDataLine sourceDataLine = null;
|
||||
private DataLine.Info dataLine_info = null;
|
||||
|
||||
private AudioInputStream audioInputStream = null;
|
||||
|
||||
public Audio(String fileName) {
|
||||
try {
|
||||
audioInputStream = AudioSystem.getAudioInputStream(Audio.class.getClassLoader().getResource(fileName));
|
||||
audioFormat = audioInputStream.getFormat();
|
||||
dataLine_info = new DataLine.Info(SourceDataLine.class, audioFormat);
|
||||
sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLine_info);
|
||||
//FloatControl volctrl=(FloatControl)sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN);
|
||||
//volctrl.setValue(-40);//
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
try {
|
||||
byte[] b = new byte[1024 * 5];
|
||||
int len = 0;
|
||||
sourceDataLine.open(audioFormat, 1024 * 5);
|
||||
sourceDataLine.start();
|
||||
System.out.println(audioInputStream.markSupported());
|
||||
// audioInputStream.mark(12358946);
|
||||
while ((len = audioInputStream.read(b)) > 0) {
|
||||
sourceDataLine.write(b, 0, len);
|
||||
}
|
||||
// audioInputStream.reset();
|
||||
|
||||
sourceDataLine.drain();
|
||||
sourceDataLine.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
audioInputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Audio a = new Audio("audio/explode.wav");
|
||||
Audio a = new Audio("audio/war1.wav");
|
||||
a.loop();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.example.tankbattle;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Explode {
|
||||
public static int WIDTH = ResourceMgr.explodes[0].getWidth();
|
||||
public static int HEIGHT = ResourceMgr.explodes[0].getHeight();
|
||||
|
||||
private int x, y;
|
||||
|
||||
TankFrame tf = null;
|
||||
|
||||
private int step = 0;
|
||||
|
||||
public Explode(int x, int y, TankFrame tf) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.tf = tf;
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
|
||||
g.drawImage(ResourceMgr.explodes[step++], x, y, null);
|
||||
|
||||
if (step >= ResourceMgr.explodes.length)
|
||||
tf.explodes.remove(this);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.example.tankbattle;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ImageUtil {
|
||||
public static BufferedImage rotateImage(final BufferedImage bufferedimage,
|
||||
final int degree) {
|
||||
int w = bufferedimage.getWidth();
|
||||
int h = bufferedimage.getHeight();
|
||||
int type = bufferedimage.getColorModel().getTransparency();
|
||||
BufferedImage img;
|
||||
Graphics2D graphics2d;
|
||||
(graphics2d = (img = new BufferedImage(w, h, type))
|
||||
.createGraphics()).setRenderingHint(
|
||||
RenderingHints.KEY_INTERPOLATION,
|
||||
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
graphics2d.rotate(Math.toRadians(degree), w / 2, h / 2);
|
||||
graphics2d.drawImage(bufferedimage, 0, 0, null);
|
||||
graphics2d.dispose();
|
||||
return img;
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 847 B |
After Width: | Height: | Size: 271 KiB |
Loading…
Reference in new issue