📄 hero.java~28~
字号:
package newgame;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class Hero extends Base {
int speedx, speedy; //速度
Image img_hero;//玩家
Image img_shadow;
int frameWidth, frameHeight;
boolean visble; //可见不可见
int x, y; //坐标
int type; //类型
Canvas1 mc;
Tools tool;
final int hero1 = 1;
final int hero2 = 2;
final int hero3 = 3;
/** switch(type){
case hero1:break;
case hero2:break;
case hero3:break;
}*/
int frameCnt; //圖片序號
public Hero(Canvas1 mc, int type) {
tool=new Tools(this.mc);
this.mc = mc;
this.type = type;
frameCnt = 2;
switch(type){
case hero1: img_hero= tool.getImage("/hero1.png");
img_shadow=tool.getImage("/hero1s.png");
this.setPosition(mc.SCx / 2,mc.SCy * 3 / 4);break;
case hero2:break;
case hero3:break;
}
}
public void setPosition(int x, int y) {
this.x = x;
this.y = y;
switch (type) {
case hero1:
speedx = 5;
speedy = 5;
break;
case hero2:
break;
case hero3:
break;
}
}
//this.x += speedx;
// this.y += speedy;
public void move() {
if (mc.key2) {
this.y -= speedy;
}
if (mc.key8) {
this.y += speedy;
}
if (mc.key4) {
this.x -= speedx;
if (frameCnt != 0) {
frameCnt--;
}
}
if (mc.key6) {
this.x += speedx;
if (frameCnt != 4) {
frameCnt++;
}
}
if(mc.key4==false&frameCnt==0){frameCnt+=1;}
if(mc.key4==false&frameCnt==1){frameCnt+=1;}
if(mc.key6==false&frameCnt==4){frameCnt-=1;}
if(mc.key6==false&frameCnt==3){frameCnt-=1;}
}
public void paint(Graphics g) {
mc.tool.drawPartImage(g, img_hero, x, y, this.frameCnt * 31, 0, 31, 27);
mc.tool.drawPartImage(g, img_shadow, x-15, y+15, this.frameCnt * 26, 0, 26, 23);
}
public void setVisble(boolean flag) {
this.visble = flag;
}
public boolean isVisble() {
return this.visble;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -