?? role.java
字號(hào):
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
public class Role extends Sprite{
Image img;
int button=0;//控制按鍵操作
int index=1;
int mapx,mapy;//地圖的坐標(biāo)
public Role(Image img, int w, int h) {
super(img, w, h);
this.img=img;
//this.setPosition(80, 88);
this.defineCollisionRectangle(6, 22, 3, 10);
}
public void keypr(int key) {
switch (key){
case Tools.TWO_KEY:
case Tools.UP_KEY:
button=2;
index=7;
break;
case Tools.EIGHT_KEY:
case Tools.DOWN_KEY:
button=8;
index=1;
break;
case Tools.FOUR_KEY:
case Tools.LEFT_KEY:
button=4;
index=4;
break;
case Tools.SIX_KEY:
case Tools.RIGHT_KEY:
button=6;
index=10;
break;
}
}
public void keyre(int key){
button=0;
}
public void run (MyCanvas mc)
{
mapx=mc.t1.getX();
mapy=mc.t1.getY();
this.setFrame(index);
switch(button)
{
case 2:
index++;
if(index>8)
index=6;
if(mapy>=0){
mc.t1.setPosition(mapx,0);
mc.t2.setPosition(mapx,0);
mc.t3.setPosition(mapx,0);
this.move(0,-8);
if(this.collidesWith(mc.t2,false)){
this.move(0,8);
}
if(this.getRefPixelY()<=-8){
this.move(0,8);
}
}else{
if(this.getY()>88){
this.move(0,-8);
if(this.collidesWith(mc.t2,false)){
this.move(0,8);
}
}else{
mc.t1.move(0,8);
mc.t2.move(0,8);
mc.t3.move(0,8);
if(this.collidesWith(mc.t2,false)){
mc.t1.move(0,-8);
mc.t2.move(0,-8);
mc.t3.move(0,-8);
}
}
}
break;
case 8:
index++;
if(index>2)
index=0;
if(mapy<=(Tools.ScreenHeight-mc.t1.getHeight())){
mc.t1.setPosition(mapx,(Tools.ScreenHeight-mc.t1.getHeight()));
mc.t2.setPosition(mapx,(Tools.ScreenHeight-mc.t1.getHeight()));
mc.t3.setPosition(mapx,(Tools.ScreenHeight-mc.t1.getHeight()));
this.move(0,8);
if(this.collidesWith(mc.t2,false)){
this.move(0,-8);
}
if(this.getRefPixelY()>=176+8){
this.move(0,-8);
}
}else{
if(this.getY()<88){
this.move(0,8);
if(this.collidesWith(mc.t2,false)){
this.move(0,-8);
}
}
else
{
mc.t1.move(0,-8);
mc.t2.move(0,-8);
mc.t3.move(0,-8);
if(this.collidesWith(mc.t2,false)){
mc.t1.move(0,8);
mc.t2.move(0,8);
mc.t3.move(0,8);
}
}
}
break;
case 4:
index++;
if(index>5)
index=3;
if(mapx>=0){
mc.t1.setPosition(0,mapy);
mc.t2.setPosition(0,mapy);
mc.t3.setPosition(0,mapy);
this.move(-8,0);
if(this.collidesWith(mc.t2,false)){
this.move(8,0);
}
if(this.getRefPixelX()<=-8){
this.move(8,0);
}
}else{
if(this.getX()>88){
this.move(-8,0);
if(this.collidesWith(mc.t2,false)){
this.move(8,0);
}
}else{
mc.t1.move(8,0);
mc.t2.move(8,0);
mc.t3.move(8,0);
if(this.collidesWith(mc.t2,false)){
mc.t1.move(-8,0);
mc.t2.move(-8,0);
mc.t3.move(-8,0);
}
}
}
break;
case 6:
index++;
if(index>11)
index=9;
if(mapx<=(Tools.ScreenWidth-mc.t1.getWidth())){
mc.t1.setPosition((Tools.ScreenWidth-mc.t1.getWidth()),mapy);
mc.t2.setPosition((Tools.ScreenWidth-mc.t1.getWidth()),mapy);
mc.t3.setPosition((Tools.ScreenWidth-mc.t1.getWidth()),mapy);
this.move(8,0);
if(this.collidesWith(mc.t2,false)){
this.move(-8,0);
}
if(this.getRefPixelX()>=168){
this.move(-8,0);
}
}else{
if(this.getX()<88){
this.move(8,0);
if(this.collidesWith(mc.t2,false)){
this.move(-8,0);
}
}
else
{
mc.t1.move(-8,0);
mc.t2.move(-8,0);
mc.t3.move(-8,0);
if(this.collidesWith(mc.t2,false)){
mc.t1.move(8,0);
mc.t2.move(8,0);
mc.t3.move(8,0);
}
}
}
break;
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -