📄 barsprite.java
字号:
package com.yang.c10.Brick;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
public class BarSprite extends Sprite{
private int m_nTime; //取得武器后,停留的时间
public BarSprite( Image image, int frameWidth, int frameHeight){
super(image, frameWidth, frameHeight);
defineReferencePixel(frameWidth / 2, frameHeight / 2);
}
//设置木棒加长,参数blong为true,则设置成长型木棒,否则设置成普通木棒
public void setLong( boolean blong ){
if( blong ){
setFrame(1);
m_nTime = 300;
}
else
setFrame(0);
}
//根据玩家的输入,控制木棒的位置
public void Input(int keyStates, int scrWidth ){
int x = getRefPixelX();
if( ( keyStates & GameCanvas.LEFT_PRESSED ) != 0 )
x -= 5;
if( ( keyStates & GameCanvas.RIGHT_PRESSED ) != 0 )
x += 5;
if( x < this.getWidth() / 2 )
x = this.getWidth() / 2;
if( x > scrWidth - this.getWidth() / 2 )
x = scrWidth - this.getWidth() / 2;
setRefPixelPosition(x, getRefPixelY());
}
//逻辑操作,如果木棒处于加长状态,则计算加长状态所能保持的时间
public void Logic(){
int n = getFrame();
if( n == 1 ){
m_nTime --;
if( m_nTime < 0 )
setLong( false );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -