📄 woodsprite.java
字号:
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class woodSprite extends Sprite{
private static int width=28;
private static int height=21;
private int disWidth;
private int disHeight;
private int nowX;
private int nowY;
private int position;
private int moveLength;
private boolean isLPoke;
private boolean isRPoke;
public woodSprite(int dWidth,int dHeight,int pos)throws Exception{
super(Image.createImage("/wood.png"[img]/images/wink.gif[/img],width,height);
position=pos;
disWidth=dWidth;
disHeight=dHeight;
}
public void reset(){
moveLength=0;
isLPoke=false;
isRPoke=false;
for(int i=1;i<=3;i++){
if(position==i){
nowX=(disWidth-getWidth())/2;
nowY=disHeight-(position+1)*40;
}
}
setPosition(nowX,nowY);
}
public boolean checkCollides(stickSprite stick,boolean isLeft){
if(this.collidesWith(stick,false)){
if(isLPoke&&!isLeft)
return true;
if(isRPoke&&isLeft)
return true;
if(isLeft&&!isRPoke){
isLPoke=true;
nowX+=3;
moveLength+=3;
}
if(!isLeft&&!isLPoke){
isRPoke=true;
nowX-=3;
moveLength+=3;
}
if(moveLength>=11){
if(isLeft){
nowX=nowX-moveLength+11;
isLPoke=false;
}
else{
nowX=nowX+moveLength-11;
isRPoke=false;
}
moveLength=0;
this.setPosition(nowX,nowY);
return true;
}
}
this.setPosition(nowX,nowY);
return false;
}
public boolean isSoar(stoneSprite stone){
if(!collidesWith(stone,false))
return true;
return false;
}
public boolean flatten(kidSprite kid){
if(collidesWith(kid,false))
return true;
return false;
}
public boolean fallDown(){
nowY+=4;
if(nowY>disHeight-40){
nowY=disHeight-40;
setPosition(nowX,nowY);
return false;
}
setPosition(nowX,nowY);
setVisible(true);
return true;
}
public boolean isLeftWin(){
if(nowX>=(disWidth+getWidth())/2)
return true;
else
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -