锁定老帖子 主题:超级玛丽+源码
精华帖 (1) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-05-15
最后修改:2011-05-16
各位有什么意见可以交流下 附部分代码,图片,程序打包如下: ![]() Mario类代码: package org.liky.mario; import java.awt.image.BufferedImage; import javax.swing.JOptionPane; public class Mario implements Runnable { private int x; private int y; private BackGround bg; public void setBg(BackGround bg) { this.bg = bg; } private Thread t=null; private int xmove=0; private int ymove=0; private String status; public int getX() { return x; } public int getY() { return y; } public BufferedImage getShowImage() { return showImage; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } public int getLife() { return life; } public void setLife(int life) { this.life = life; } private BufferedImage showImage; private int score; private int life; private int moving=0; public boolean isClear() { return isClear; } private int upTime=0; private boolean isDead=false; private boolean isClear=false; public Mario(int x,int y){ this.x=x; this.y=y; this.showImage=StaticValue.allMarioImage.get(0); this.score=0; this.life=3; t=new Thread(this); t.start(); this.status="right--standing"; } public void leftMove(){ xmove=-5; if(this.status.indexOf("jumping")!=-1){ this.status="left--jumping"; }else{ this.status="left--moving"; } } public void rightMove(){ xmove=5; if(this.status.indexOf("jumping")!=-1){ this.status="right--jumping"; }else{ this.status="right--moving"; } } public void leftStop(){ xmove=0; if(this.status.indexOf("jumping")!=-1){ this.status="left--jumping"; }else{ this.status="left--standing"; } } public void rightStop(){ xmove=0; if(this.status.indexOf("jumping")!=-1){ this.status="right--jumping"; }else{ this.status="right--standing"; } } public void jump(){ if(this.status.indexOf("jumping")==-1){ if(this.status.indexOf("left")!=-1){ this.status="left--jumping"; }else{ this.status="right--jumping"; } ymove=-5; upTime=38; } } public boolean isDead() { return isDead; } public void dead(){ this.life--; if(this.life==0){ this.isDead=true; }else{ this.bg.reset(); this.x=0; this.y=480; } } public void down(){ if(this.status.indexOf("left")!=-1){ this.status="left--jumping"; }else{ this.status="right--jumping"; } ymove=5; } @Override public void run() { // TODO Auto-generated method stub while(true){ if(this.bg.isFlag() && this.x>=500){ this.bg.setOver(true); if(this.bg.isDown()){ if(this.x<580){ x+=5; }else { if(y<480){ y+=5; } x+=5; if(x>=780){ this.isClear=true; } } }else{ if(this.y<420){ this.y+=5; } if(this.y>=420){ this.y=420; this.status="right--standing"; } } }else{ boolean canLeft=true; boolean canRight=true; boolean onLand=false; for(int i=0;i<this.bg.getAllObstruction().size();i++){ Obstruction ob =this.bg.getAllObstruction().get(i); if(ob.getX()==this.x+60 && (ob.getY()+50>this.y && ob.getY()-50<this.y)){ if(ob.getType()!=3){ canRight=false; } } if(ob.getX()==this.x-60 && (ob.getY()+50>this.y && ob.getY()-50<this.y)){ if(ob.getType()!=3){ canLeft=false; } } if(ob.getY()==this.y+60 && (ob.getX()+60>this.x && ob.getX()-60<this.x)){ if(ob.getType()!=3){ onLand=true; } } if(ob.getY()==this.y-60 && (ob.getX()+50>this.x && ob.getX()-50<this.x)){ if(ob.getType()==0){ this.bg.getAllObstruction().remove(ob); this.bg.getRemovedObstruction().add(ob); } if((ob.getType()==4 || ob.getType()==3) && upTime>0){ ob.setType(2); ob.setImage(); } upTime=0; } } for (int i=0;i<this.bg.getAllEnemy().size();i++){ Enemy e=this.bg.getAllEnemy().get(i); if(e.getX()+50>this.x && e.getX()-50<this.x && (e.getY()+60>this.y && e.getY()-60<this.y)){ this.dead(); } if(e.getY()==this.y+60 && (e.getX()+60>this.x && e.getX()-60<this.x)){ if(e.getType()==1){ e.dead(); this.upTime=10; this.ymove=-5; }else if (e.getType()==2){ this.dead(); } } } if(onLand && upTime==0){ if(this.status.indexOf("left")!=-1){ if(xmove!=0){ this.status="left--moving"; }else{ this.status="left--standing"; } }else{ if(xmove!=0){ this.status="right--moving"; }else{ this.status="right--standing"; } } }else{ if(upTime!=0){ upTime--; }else{ this.down(); } y +=ymove; } if(this.y>600){ this.dead(); } if (canLeft && xmove<0 || (canRight && xmove>0)){ x+=xmove; if(x<0){ x=0; } } } int temp=0; if(this.status.indexOf("left")!=-1){ temp+=5; } if(this.status.indexOf("moving")!=-1){ temp+=this.moving; moving++; if(moving==4){ moving=0; } } if(this.status.indexOf("jumping")!=-1){ temp +=4; } this.showImage=StaticValue.allMarioImage.get(temp); try { Thread.sleep(50); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2011-05-16
![]() |
|
返回顶楼 | |
发表时间:2011-05-16
没图 没真相.
|
|
返回顶楼 | |
发表时间:2011-05-16
最后修改:2011-05-16
我发现了一个小BUG,你的t.start()放错了位置,应该放在this.addKeyListener(this); 之后,就可以了,
总体还不错,就是玩起来不是太流畅,这可能就是为什么很少有人用JASE编客户端的原因吧, |
|
返回顶楼 | |
发表时间:2011-05-16
没图没真相,发文章不配图认人怎么看啊,晕死
|
|
返回顶楼 | |
发表时间:2011-05-16
代码打下包撒、、、、
|
|
返回顶楼 | |
发表时间:2011-05-16
zhangxuewen1234 写道 我发现了一个小BUG,你的t.start()放错了位置,应该放在this.addKeyListener(this); 之后,就可以了,
总体还不错,就是玩起来不是太流畅,这可能就是为什么很少有人用JASE编客户端的原因吧, 谢谢啊,已经修正了,难怪有时启动会抛异常 |
|
返回顶楼 | |
发表时间:2011-05-16
llfzy 写道 代码打下包撒、、、、
已经打包传了 |
|
返回顶楼 | |
发表时间:2011-05-17
Exception in thread "Thread-2" java.lang.NullPointerException
at org.liky.mario.MyFrame.run(MyFrame.java:126) at java.lang.Thread.run(Unknown Source) 有报错 |
|
返回顶楼 | |
发表时间:2011-05-17
Exception in thread "Thread-2" java.lang.NullPointerException
at org.liky.mario.MyFrame.run(MyFrame.java:126) at java.lang.Thread.run(Unknown Source) 同楼上~ |
|
返回顶楼 | |