?? hero.java
字號(hào):
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class Hero {
int state;
int dir;
int x;
int y;
int speed;
int nowPic;
int hp;
int mp;
Image img;
int w;
int h;
int count;
//state
static final int STOP=0;
static final int MOVE=1;
static final int DEAD=2;
//dir
static final int UP=0;
static final int DOWN=1;
static final int LEFT=2;
static final int RIGHT=3;
int action[][]={
{12,13,14,15},
{0,1,2,3},
{4,5,6,7},
{8,9,10,11}
};
public Hero(){
try {
img=Image.createImage("/039-Mage07.png");
w=img.getWidth()/4;
h=img.getHeight()/4;
} catch (IOException e) {
e.printStackTrace();
}
}
public void initHero(int state,int dir,int x,int y){
this.state=state;
this.dir=dir;
this.x=x;
this.y=y;
this.speed=4;
}
public void paint(Graphics g){
if(state==STOP){
nowPic=action[dir][0];
g.setClip(x, y, w, h);
g.drawImage(img, x-nowPic%4*w, y-nowPic/4*h, 0);
}
if(state==MOVE){
nowPic=action[dir][count%4];
g.setClip(x, y, w, h);
g.drawImage(img, x-nowPic%4*w, y-nowPic/4*h, 0);
}
}
public void move(){
if(state==MOVE){
count++;
if(count>999){
count=0;
}
switch(dir){
case UP:
y-=speed;
if(y<=0){
y=0;
}
break;
case DOWN:
y+=speed;
if(y>=GameCanvas.screen_h-h){
y=GameCanvas.screen_h-h;
}
break;
case LEFT:
x-=speed;
if(x<=0){
x=0;
}
break;
case RIGHT:
x+=speed;
if(x>=GameCanvas.screen_w-w){
x=GameCanvas.screen_w-w;
}
break;
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -