1.如何加入音乐
File f=new File("音乐文件路径");
URL ur=f.toURL();//将文件转换成URL
AudioClip a=new Applet.newAudioClip(ur);
a.play();//播放一次
a.loop();//循环播放
a.stop();//调用时结束音乐播放
例如:File file999=new File("D:\\eclise\\2Dgame\\44.wav");
URL url999=file999.toURL();
bj=Applet.newAudioClip(url999);
bj.play();
2.如何把图片画上去(很好的方法)
其中用到BufferedImage画纸
BufferedImage bu=BufferedImage(int width,int height,BufferedImage.TYPE_INT_RGB);
然后创建需要的图片对象
ImageIcon im=new ImageIcon("图片路径");
然后获取画纸上的画布
Graphics g=bu.getGraphics();
然后在将图片画上去
g.drawImage(im,int beginx,int beginy,int width,int height,null);
然后再将自己的画纸在画到面板上去就是了方法同上。。
然后就是可以利用线程死循环while(true){
//方法中写入上述代码,这样就可以一直切换你创建的图片了}
这样就可以让你的图片动起来了
就可以做拳皇之类的游戏了
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
话不多说,先上图
再看代码,这是前期的作品,代码风格不是很好,注释不全,不懂之处,可以留言
package hf20130722first2D;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
public class Key implements KeyListener{
public Ren t;
public AudioClip bj;
public Key(Ren t){
this.t=t;
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
int key = e.getKeyCode();
switch(key){
case KeyEvent.VK_O:
t.s=11;
break;
case KeyEvent.VK_L:
t.s=12;
break;
case KeyEvent.VK_Y:
t.ss=11;
break;
case KeyEvent.VK_H:
t.ss=12;
break;
case KeyEvent.VK_DOWN://向下
t.s=1;
// t.dun();
System.out.println("u");
; break;
case KeyEvent.VK_S:
t.ss=1;
; break;
case KeyEvent.VK_LEFT: //向左
t.d=2;
t.s=2;
// t.qj() ;
System.out.println("l");
break;
case KeyEvent.VK_A: //向左
t.dd=2;
t.ss=2;
// t.qj() ;
System.out.println("l");
break;
case KeyEvent.VK_D: //向左
t.dd=3;
t.ss=2;
// t.qj() ;
System.out.println("l");
break;
case KeyEvent.VK_RIGHT: //向右
t.d=3;
t.s=7;
// t.qj() ;
System.out.println("r"); break;
case KeyEvent.VK_R: //向左
File file999=new File("D:\\eclise\\2Dgame\\拳.wav");
URL url999;
try {
url999 = file999.toURL();
bj=Applet.newAudioClip(url999);
bj.play();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
t.ss=3;
if(t.ren1x+40>=t.ren2x){
t.bd=1;
}
// t.qj() ;
System.out.println("l");
break;
case KeyEvent.VK_U: //重脚
File file=new File("D:\\eclise\\2Dgame\\拳.wav");
URL url;
try {
url = file.toURL();
bj=Applet.newAudioClip(url);
bj.play();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// t.b=1;
t.s=3;
if(t.ren1x+40>=t.ren2x){
t.bd1=1;
}
// t.zj();
; break;
case KeyEvent.VK_I: //轻脚
// t.b=1;
File fil=new File("D:\\eclise\\2Dgame\\脚.wav");
URL ur;
try {
ur = fil.toURL();
bj=Applet.newAudioClip(ur);
bj.play();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
t.s=4;
if(t.ren1x+40>=t.ren2x){
t.bd1=2;
}
// t.qij();
; break;
case KeyEvent.VK_T: //轻脚
// t.b=1;
File fi=new File("D:\\eclise\\2Dgame\\脚.wav");
URL u;
try {
u = fi.toURL();
bj=Applet.newAudioClip(u);
bj.play();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
t.ss=4;
if(t.ren1x+40>=t.ren2x){
t.bd=2;
}
// t.qij();
; break;
case KeyEvent.VK_J: //重脚
// t.b=1;
File file99=new File("D:\\eclise\\2Dgame\\拳.wav");
URL url99;
try {
url99 = file99.toURL();
bj=Applet.newAudioClip(url99);
bj.play();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
t.s=5;
if(t.ren1x+30>=t.ren2x){
t.bd1=1;
}
// t.zq();
; break;
case KeyEvent.VK_F: //重脚
// t.b=1;
File file9=new File("D:\\eclise\\2Dgame\\拳.wav");
URL url9;
try {
url9 = file9.toURL();
bj=Applet.newAudioClip(url9);
bj.play();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
t.ss=5;
if(t.ren1x+30>=t.ren2x){
t.bd=1;
}
// t.zq();
; break;
case KeyEvent.VK_K: //轻拳
// t.b=1;
File f=new File("D:\\eclise\\2Dgame\\脚.wav");
URL u1;
try {
u1 = f.toURL();
bj=Applet.newAudioClip(u1);
bj.play();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
t.s=6;
if(t.ren1x+30>=t.ren2x){
t.bd1=2;
}
// t.qiq();
; break;
case KeyEvent.VK_G: //轻拳
// t.b=1;
File f2=new File("D:\\eclise\\2Dgame\\脚.wav");
URL u2;
try {
u2 = f2.toURL();
bj=Applet.newAudioClip(u2);
bj.play();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
t.ss=6;
if(t.ren1x+30>=t.ren2x){
t.bd=2;
}
// t.qiq();
; break;
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
int key = e.getKeyCode();
switch(key){
case KeyEvent.VK_RIGHT: //向右
t.s=0;
break;
case KeyEvent.VK_LEFT: //向右
t.s=0;
break;
case KeyEvent.VK_DOWN: //向右
t.s=0;
break;
// case KeyEvent.VK_U: //向右
// t.s=0;
// break;
// case KeyEvent.VK_I: //向右
// t.s=0;
// break;
// case KeyEvent.VK_J: //向右
// t.s=0;
// break;
// case KeyEvent.VK_K: //向右
// t.s=0;
// break;
case KeyEvent.VK_D: //向右
t.ss=0;
break;
case KeyEvent.VK_A: //向右
t.ss=0;
break;
case KeyEvent.VK_S: //向右
t.ss=0;
break;
// case KeyEvent.VK_R: //向右
// t.ss=0;
// break;
// case KeyEvent.VK_T: //向右
// t.ss=0;
// break;
// case KeyEvent.VK_F: //向右
// t.ss=0;
// break;
// case KeyEvent.VK_G: //向右
// t.ss=0;
// break;
}
// t.z=new zl(new Te());
//t.z.start();
System.out.println(t.s);
}
}
package hf20130722first2D;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.ImageIcon;
public class Ren extends Thread{
public AudioClip bj;
public int tt=0;
public int k=0;
public int k1=0;
public int bd1=0;
public int bd=0;
public int ren1x;
public int ren2x;
//攻击状态
public int q=0;
public int z=0;
public int q1=0;
public int z1=0;
//计数图片
public int sk=0;
public int sk1=0;
public int kc=0;
public int kc1=0;
public int dx=0;
public int dx1=0;
public int jn=0;
public int jn1=0;
public int qg=0;
public int zg=0;
public int qg1=0;
public int zg1=0;
public int zq=0;
public int zq1=0;
public int zj=0;
public int zj1=0;
public int qij=0;
public int qij1=0;
public int qiq=0;
public int qiq1=0;
public Graphics g1;
public Graphics g2;
public BufferedImage im;
final int Up=0;
final int Down=1;
final int Left=2;
final int Right=3;
public int x=130,y=340;
public int xx=630,yy=340;
public int s=100;
public int kk=0;
public int ss=0;
public int d,dd;
public int i=0,ii=0;
public int j=1,jj=1;
public Te t;
public Ren(Te t){
this.t=t;
}
public void tie(){
t.getGraphics().drawImage(im,0,0,null);
}
public void hua(){
im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
}
public void beijing(){
ImageIcon be=new ImageIcon("77.png");
Graphics g=im.getGraphics();
g.drawImage(be.getImage(),0,0,null);
}
public void zl1(){
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
//while(true){
// if(s==0&&b==0){
if(ii>=8){
ii=0;
}
ImageIcon i1=new ImageIcon("站立1/_000"+ii+"_"+"-----"+(8-ii)+".png");
Graphics g=im.getGraphics();
// try{
// Thread.sleep(50);
// }catch(Exception e){
// e.printStackTrace();
// }
g.drawImage(i1.getImage(),xx+10,yy+10,i1.getIconWidth()+20,i1.getIconHeight()+20,null);
//t.getGraphics().drawImage(im,0,0,null);
ren2x=xx+10;
ii++;}
public void zl(){
if(i>=8){
i=0;
}
ImageIcon i1=new ImageIcon("站立/_000"+i+"_"+"-----"+(8-i)+".png");
Graphics g=im.getGraphics();
g.drawImage(i1.getImage(),x+10,y+10,i1.getIconWidth()+20,i1.getIconHeight()+20,null);
ren1x=x+10+i1.getIconWidth()+20;
i++;}
//}
//}
public void qj(){
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
//ImageIcon be=new ImageIcon("77.png");
//while(true){
if(i>=10){
i=0;
}
ImageIcon i1=new ImageIcon("前进/_000"+i+"_"+"-----"+(10-i)+".png");
//ImageIcon i1=new ImageIcon("前进1/前进_"+f+".png");
Graphics g=im.getGraphics();
//g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),x+10,y+10,i1.getIconWidth()+20,i1.getIconHeight()+20,null);
x=130+j*12;
ren1x=x+10+i1.getIconWidth()+20;
//t.getGraphics().drawImage(im,0,0,null);
System.out.println(i);
i++;
if(d==Right){j++;}
else if(d==Left) {j--;}
//}
}public void qj1(){
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
//ImageIcon be=new ImageIcon("77.png");
//while(true){
if(ii>=10){
ii=0;
}
ImageIcon i1=new ImageIcon("前进1/_000"+ii+"_"+"-----"+(10-ii)+".png");
//ImageIcon i1=new ImageIcon("前进1/前进_"+f+".png");
Graphics g=im.getGraphics();
//g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),xx+10,yy+10,i1.getIconWidth()+20,i1.getIconHeight()+20,null);
xx=630+jj*12;
ren2x=xx+10;
//t.getGraphics().drawImage(im,0,0,null);
System.out.println(i);
ii++;
if(dd==Right){jj++;}
else if(dd==Left) {jj--;}
//}
}
public void dun(){
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
// ImageIcon be=new ImageIcon("77.png");
//while(true){
if(i>=6){
i=0;
}
ImageIcon i1=new ImageIcon("下蹲/"+i+".png");
Graphics g=im.getGraphics();
// g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),x,y,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
System.out.println(i);
i++;
System.out.println("正在下蹲");
}
public void dun1(){
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
// ImageIcon be=new ImageIcon("77.png");
//while(true){
if(ii>=6){
ii=0;
}
ImageIcon i1=new ImageIcon("下蹲1/"+ii+".png");
Graphics g=im.getGraphics();
// g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),xx,yy,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
System.out.println(i);
ii++;
System.out.println("正在下蹲");
}
public void qg(){
if(qg>=7){
qg=0;s=0;q=0;bd=0;
}
ImageIcon i1=new ImageIcon("被拳打/_000"+qg+"_"+"-----"+(8-qg)+".png");
Graphics g=im.getGraphics();
//g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),x,y+10,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
qg++;
}
public void qg1(){
if(qg1>=7){
qg1=0;ss=0;q=0;bd1=0;
}
ImageIcon i1=new ImageIcon("被拳打1/_000"+qg1+"_"+"-----"+(8-qg1)+".png");
Graphics g=im.getGraphics();
//g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),xx,yy+10,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
qg1++;
}
public void zg(){
if(zg>=7){
zg=0;s=0;bd=0;
}
ImageIcon i1=new ImageIcon("被脚打/_000"+zg+"_"+"-----"+(8-zg)+".png");
Graphics g=im.getGraphics();
//g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),x,y,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
zg++;
}
public void zg1(){
if(zg1>=7){
zg1=0;ss=0;bd1=0;
}
ImageIcon i1=new ImageIcon("被脚打1/_000"+zg1+"_"+"-----"+(8-zg1)+".png");
Graphics g=im.getGraphics();
//g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),xx,yy,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
System.out.println("zehnzgaichuquan");
zg1++;
}
public void zj(){
if(zj>=9){
zj=0;s=0;
}
ImageIcon i1=new ImageIcon("重脚/"+zj+".png");
Graphics g=im.getGraphics();
g.drawImage(i1.getImage(),x,y,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
System.out.println("zehnzgaichuquan");
zj++;
}
public void kc() throws Exception{
try{
Thread.sleep(50);
}catch(Exception e){}
ImageIcon i1=new ImageIcon("狂笑/_00"+(36-kc)+"_"+"-----"+(kc+1)+".png");
Graphics g=im.getGraphics();
g.drawImage(i1.getImage(),x+10,y,i1.getIconWidth()+20,i1.getIconHeight()+20,null);
if(kc==0){
File file999=new File("E:\\eclipsworks\\2Dgame");
URL url999=file999.toURL();
bj=Applet.newAudioClip(url999);
bj.play();}
kc++;
if(kc>=36){
kc=0;s=0;tt=1;
}
}
public void kc1() throws Exception{
ss=100;
if(kc1==0){
File file999=new File("D:\\eclise\\2Dgame\\骂人.wav");
URL url999=file999.toURL();
bj=Applet.newAudioClip(url999);
bj.play();
System.out.print("fffffffffffffwwwwwwwwwwwwww");}
try{Thread.sleep(80);}catch(Exception e){}
ImageIcon i1=new ImageIcon("嘲讽/"+(kc1+1)+".png");
Graphics g=im.getGraphics();
g.drawImage(i1.getImage(),xx+10,yy,i1.getIconWidth()+20,i1.getIconHeight()+20,null);
kc1++;
if(kc1>7){
kc1=0;ss=0;tt=0;
}}
public void dx(){
ImageIcon i1=new ImageIcon("倒下/_000"+(25-dx)+"_"+"-----"+(dx+1)+".png");
Graphics g=im.getGraphics();
if(0<dx&&dx<=6){y=y-10;}
if(dx>6&&dx<=12){y=y+10;}
g.drawImage(i1.getImage(),x,y+40,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
System.out.println("zehnzgaichuquan");
dx++;
if(dx>=25){
dx=0;s=0;bd=0;
}
}
public void dx1(){
ImageIcon i1=new ImageIcon("倒下1/_000"+(25-dx1)+"_"+"-----"+(dx1+1)+".png");
Graphics g=im.getGraphics();
if(0<dx1&&dx1<=6){yy=yy-10;}
if(dx1>6&&dx1<=12){yy=yy+10;}
g.drawImage(i1.getImage(),xx,yy+40,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
System.out.println("zehnzgaichuquan");
dx1++;
if(dx1>=25){
dx1=0;ss=0;bd1=0;
}
}
public void jn(){
ImageIcon i1=new ImageIcon("技能/_000"+(15-jn)+"_"+"-----"+(jn+1)+".png");
Graphics g=im.getGraphics();
g.drawImage(i1.getImage(),x,y,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
jn++;
if(jn>=15){
jn=0;s=0;k1=0;
}
if(ren1x+i1.getIconWidth()-46>=ren2x){
if(k1==0){
bd1=1;k1++;}
}
}
public void jn1(){
if(jn1>=15){
jn1=0;ss=0;k=0;
}
ImageIcon i1=new ImageIcon("技能1/_000"+(15-jn1)+"_"+"-----"+(jn1+1)+".png");
Graphics g=im.getGraphics();
g.drawImage(i1.getImage(),xx-i1.getIconWidth()+55,yy,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
jn1++;
if(ren1x+i1.getIconWidth()-46>=ren2x){
if(k==0){
bd=1;
k++;}
}
}
public void sk(){
ImageIcon i1=new ImageIcon("技/_00"+(59-sk)+"_"+"-----"+(sk+1)+".png");
Graphics g=im.getGraphics();
g.drawImage(i1.getImage(),x,470-i1.getIconHeight()-26,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
sk++;
if(ren1x+i1.getIconWidth()-46>=ren2x){
if(k1==0){
bd1=3;k1++;}
}if(sk>=59){
sk=0;s=0;k1=0;
}}
public void sk1(){
ImageIcon i1=new ImageIcon("技2/_00"+(59-sk1)+"_"+"-----"+(sk1+1)+".png");
Graphics g=im.getGraphics();
g.drawImage(i1.getImage(),xx+80-i1.getIconWidth(),470-i1.getIconHeight()-26,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
sk1++;
if(ren1x+i1.getIconWidth()-46>=ren2x){
if(k1==0){
bd=3;k1++;}
}
if(sk1>=59){
sk1=0;ss=0;k1=0;
}
}
public void zj1(){
ImageIcon i1=new ImageIcon("重脚1/"+zj1+".png");
Graphics g=im.getGraphics();
g.drawImage(i1.getImage(),xx-50,yy,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
System.out.println(i);
System.out.println("zehnzgaichuquan");
zj1++;
if(zj1>=9){
zj1=0;ss=0;
}
}
public void qij(){
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
//ImageIcon be=new ImageIcon("77.png");
ImageIcon i1=new ImageIcon("轻脚/"+qij+".png");
Graphics g=im.getGraphics();
//g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),x,y,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
System.out.println(i);
qij++;
if(qij>=5){
qij=0;s=0;
}
}
public void qij1(){
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
//ImageIcon be=new ImageIcon("77.png");
ImageIcon i1=new ImageIcon("轻脚1/"+qij1+".png");
Graphics g=im.getGraphics();
//g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),xx-50,yy,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
System.out.println(i);
qij1++;
if(qij1>=5){
qij1=0;ss=0;
}
}
public void zq() throws Exception{
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
//ImageIcon be=new ImageIcon("77.png");
ImageIcon i1=new ImageIcon("重拳/"+(8-zq)+".png");
Graphics g=im.getGraphics();
// g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),x,y,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
zq++;
if(zq>=9){
zq=0;s=0;
}
}
public void zq1(){
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
//ImageIcon be=new ImageIcon("77.png");
ImageIcon i1=new ImageIcon("重拳1/"+(8-zq1)+".png");
Graphics g=im.getGraphics();
// g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),xx-50,yy,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
System.out.println(i);
zq1++;
if(zq1>=9){
zq1=0;
ss=0;
}
}
public void qiq(){
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
//ImageIcon be=new ImageIcon("77.png");
ImageIcon i1=new ImageIcon("轻拳/"+qiq+".png");
Graphics g=im.getGraphics();
//g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),x,y,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
System.out.println(i);
qiq++;
if(qiq>=5){
qiq=0;s=0;
}
}
public void qiq1(){
// im=new BufferedImage(t.getWidth(),t.getHeight(),BufferedImage.TYPE_INT_RGB);
//ImageIcon be=new ImageIcon("77.png");
ImageIcon i1=new ImageIcon("轻拳1/"+qiq1+".png");
Graphics g=im.getGraphics();
//g.drawImage(be.getImage(),0,0,null);
g.drawImage(i1.getImage(),xx-50,yy,i1.getIconWidth()+26,i1.getIconHeight()+26,null);
//t.getGraphics().drawImage(im,0,0,null);
System.out.println(i);
qiq1++;
if(qiq1>=5){
qiq1=0;ss=0;
}
}
public void music(){
File file999=new File("D:\\eclise\\2Dgame\\1.wav");
try
{
URL url999=file999.toURL();
bj=Applet.newAudioClip(url999);
}
catch (Exception e)
{
}
}
public void run(){
// music();bj.play();
while(true){
this.hua();
this.beijing();
if(bd1==1){
ss=8;
this.zg1();
}
if(bd==1){
s=8;
this.zg();
}
if(bd1==3){
ss=8;
this.dx1();
}
if(bd==3){
s=8;
this.dx();
}
if(bd1==2){
ss=8;
this.qg1();
}
if(bd==2){
s=8;
this.qg();
}
if(s==100){
try {
this.kc();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(tt==1){
try {
this.kc1();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(s==0){
this.zl();
}
if(ss==0){
this.zl1();
}
if(ss==1){
this.dun1();}
if(s==1){
this.dun();
}if(s==2){
this.qj() ;
}
if(ss==2){
this.qj1() ;
}if(s==3){
this.zj();
}
if(ss==3){
this.zj1();
}if(s==4){
this.qij();
}
if(ss==4){
this.qij1();
}
if(s==5){
try {
this.zq();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(ss==5){
this.zq1();
}
if(s==6){
this.qiq();
}
if(ss==6){
this.qiq1();
}
if(s==7){
this.qj() ;
}
if(ss==7){
this.qj1() ;
}
if(s==11){
this.jn();
}
if(ss==11){
this.jn1();
}
if(s==12){
this.sk();
}
if(ss==12){
this.sk1();
}
//if(z1==0){
// this.zg1();
//}
this.tie();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}}
package hf20130722first2D;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.*;
public class Te extends JFrame {
public AudioClip bj;
public void UI() throws Exception{
this.setTitle("2DGame");
this.setSize(1000,550);
this.setLocation(200,100);
this.setResizable(false);
this.setDefaultCloseOperation(3);
this.setVisible(true);
Ren z=new Ren(this);
Key k=new Key(z);
this.addKeyListener(k);
File file999=new File("E:\\eclipsworks\\2Dgame\\44.wav");
URL url999=file999.toURL();
bj=Applet.newAudioClip(url999);
bj.play();
kaichang("八神/1.jpg");
kaichang("八神/2.jpg");
kaichang("八神/3.jpg");
//kaichang("八神/4.jpg");
kaichang("八神/5.jpg");
kaichang("八神/6.jpg");
kaichang("八神/7.jpg");
kaichang("八神/8.jpg");
kaichang("八神/9.jpg");
kaichang("八神/10.jpg");
kaichang("八神/11.jpg");
Thread.sleep(100);
kaichang("八神/12.jpg");
bj.stop();
File file99=new File("E:\\eclipsworks\\2Dgame\\2.wav");
URL url99=file99.toURL();
AudioClip b=Applet.newAudioClip(url99);
z.start();
Thread.sleep(6000);
b.loop();
//kaishi=Applet.newAudioClip(url000);
}
//Applet a=new Applet();
//AudioClip au=a.getAudioClip(null, "D:\\eclise\\2Dgame\\1.wav");
//au.play();
public void kaichang(String name){
BufferedImage bd=new BufferedImage(this.getWidth(),this.getHeight(),BufferedImage.TYPE_INT_RGB);
ImageIcon im=new ImageIcon(name);
Graphics g=bd.getGraphics();
g.drawImage(im.getImage(),0,20,bd.getWidth(),bd.getHeight(),null);
this.getGraphics().drawImage(bd, 0, 0,null);
try{Thread.sleep(3500);}catch(Exception e){}
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
new Te().UI();
}
}
猛戳下面网址下载源程序和游戏要用到的资源 http://pan.baidu.com/disk/home#dir/path=%2F%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E8%B5%84%E6%96%99