📄 gameogre.java
字号:
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
//////////////////////////////////////////////////
//游戏怪物类
// 封装怪物的一切动画,移动,死亡 等。
//////////////////////////////////////////////////
public class GameOgre extends Sprite
{
private int statrFrame,endFrame;
private boolean isOK,isGongji,isL;
public boolean isDie = false;
private int OrgeScore;
/***********************************************************************/
// 构造方法
/***********************************************************************/
public GameOgre(Image img,int w,int h,int guaiNum)
{
super(img,w,h);
isOK = false;
isL = false;
isGongji = false;
switch(guaiNum)
{
case 1:
int daoseq[] = {0,0,0,1,1,1,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4};
statrFrame = 8;
endFrame = 21;
OrgeScore = 500;
this.setFrameSequence(daoseq);
break;
case 2:
int gongseq[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4};
statrFrame = 40;
endFrame = 40;
OrgeScore = 400;
this.setFrameSequence(gongseq);
break;
case 3:
int kuseq[] = {0,0,0,1,1,1,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4};
statrFrame = 8;
endFrame =23;
OrgeScore = 400;
this.setFrameSequence(kuseq);
break;
case 4:
int xiaoseq[] = {0,0,0,1,1,1,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4};
statrFrame = 8;
endFrame = 22;
OrgeScore = 200;
this.setFrameSequence(xiaoseq);
break;
}
}
/***********************************************************************/
// 怪物移动
/***********************************************************************/
public void moveGuai(boolean isL)
{
if (!isDie)
{
if (!isL)
{
this.setTransform(Sprite.TRANS_NONE);
if(this.getFrame() <= statrFrame - 1)
{
this.nextFrame();
}
else
{
this.setFrame(0);
}
}
else
{
this.setTransform(Sprite.TRANS_NONE);
this.setTransform(Sprite.TRANS_MIRROR);
if(this.getFrame() <= statrFrame - 1)
{
this.nextFrame();
}
else
{
this.setFrame(0);
}
}
}
else
{
die();
}
}
public void moveGuai(int statr,int end)
{
if(!isDie)
{
if (!isGongji)
{
if (!isOK)
{
if (this.getX() <= end)
{
this.moveRight();
this.move(1,0);
}
else
{
isOK = true;
}
}
else
{
if (this.getX() >= statr)
{
this.moveLeft();
this.move(-1,0);
}
else
{
isOK = false;
}
}
}
else
{
if(isL)
{
this.move(2,0);
this.moveRight();
if (MyGame.stage == 2)
{
if (this.getX() + this.getWidth() >= 90)
{
this.setPosition(90,this.getY());
}
}
}
else
{
this.move(-2,0);
this.moveLeft();
if (MyGame.stage == 5)
{
if (this.getX() <= 45)
{
this.setPosition(45,this.getY());
}
}
}
}
if((MyGame.player.getX()+ MyGame.player.getWidth() ) >= this.getX() -30
&& (MyGame.player.getX()+ MyGame.player.getWidth() <= this.getX()))
{
if ((MyGame.player.getY() - this.getY()) == this.getHeight() - MyGame.player.getHeight())
{
isGongji = true;
isL = false;
}
else
{
isGongji = false;
}
}
if((MyGame.player.getX()) >= this.getX()+this.getWidth()
&& (MyGame.player.getX() <= this.getX() + 30 + this.getWidth()))
{
if ((MyGame.player.getY() - this.getY()) == this.getHeight() - MyGame.player.getHeight())
{
isGongji = true;
isL = true;
}
else
{
isGongji = false;
}
}
}
else
{
die();
}
}
public void moveLeft()
{
this.setTransform(Sprite.TRANS_NONE);
this.setTransform(Sprite.TRANS_MIRROR);
if(getFrame()<=statrFrame - 1)
{
this.nextFrame();
}
else
{
this.setFrame(0);
}
if (this.getX() < 11)
{
this.setPosition(11,this.getY());
}
}
public void moveRight()
{
this.setTransform(Sprite.TRANS_NONE);
if(getFrame()<=statrFrame - 1)
{
this.nextFrame();
}
else
{
this.setFrame(0);
}
if (this.getX() > 176 - this.getWidth() - 7)
{
this.setPosition(176 - this.getWidth() - 7,this.getY());
}
}
/***********************************************************************/
// 怪物死亡动画
/***********************************************************************/
public void die()
{
if (this.getFrame() < statrFrame)
{
this.setFrame(statrFrame);
}
if (this.getFrame() >= statrFrame && this.getFrame()
<= endFrame-1)
{
this.nextFrame();
if(this.getFrame() == endFrame - 1)
{
this.setPosition(-200,-200);
MyGame.lm.remove(this);
MyGame.score += OrgeScore;
}
}
else
{
this.isDie = false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -