📄 scenemodel.java
字号:
break;
case 3:
case 4:
case 5:
mCock.mUsed = true;
mCock.setState(HF.STATE_MOVE_LEFT);
break;
}
}
}
for(int i=1;i<sceneCount.length;i++) {
if(sceneCount[i]>=mSceneWidth)
sceneCount[i]-=mSceneWidth;
}
//变换场景中的敌兵的坐标
for(int i=2;i<MAX_PAWN;i++){
if(mPawns[i].mUsed==true){
mPawns[i].mX = mPawns[i].mX - dx;
if(mPawns[i].mX +17<=0){
mPawns[i].reset();//消失在视野范围内,从场景中移去
}
}
}
//变换场景中的物品的坐标
for(int i=0;i<MAX_SCENEUNIT;i++){
if(mUpScenes[i].mUsed==true){
mUpScenes[i].mX = mUpScenes[i].mX - dx;
int width = mSceneImages[mUpScenes[i].mType-2].getWidth();
if(mUpScenes[i].mX+width<=0){
mUpScenes[i].reset();
}
}
if(mDownScenes[i].mUsed==true){
mDownScenes[i].mX = mDownScenes[i].mX - dx;
int width = mSceneImages[mDownScenes[i].mType-2].getWidth();
if(mDownScenes[i].mX+width<=0){
mDownScenes[i].reset();
}
}
}
//变换场景中的药箱的坐标
for(int i=0;i<2;i++){
if(mCabinets[i].mUsed == true){
mCabinets[i].mX = mCabinets[i].mX - dx;
if(mCabinets[i].mX+7<0){
mCabinets[i].reset();
}
}
}
}
//绘制场景中的物品,例如屋子等等
private void drawSceneObjects(Graphics g) {
//绘制场景中的上一排的布景
for(int i=0;i<MAX_SCENEUNIT;i++){
if(mUpScenes[i].mUsed == true){
int x =mUpScenes[i].mX,y = mUpScenes[i].mY;
Image img = mSceneImages[mUpScenes[i].mType-2];
//System.out.println("图片是:"+img);
g.drawImage(img,x,y,Graphics.LEFT|Graphics.BOTTOM);
}
}
//绘制场景中的子弹
for(int i=0;i<MAX_BULLET;i++){
if(mBullets[i].mUsed ==true){
int index = mBullets[i].mDirection== HF.STATE_MOVE_LEFT ? 0:1;
if(fireEmpty)
g.drawImage(mBulletImages[index],mBullets[i].mX,mBullets[i].mY,Graphics.LEFT|Graphics.TOP);
else
g.drawImage(mFireBulletImages[index],mBullets[i].mX,mBullets[i].mY,Graphics.LEFT|Graphics.TOP);
}
}
//绘制场景中敌人的子弹
for(int i=0;i<MAX_ENEMY_BULLET;i++){
if(mEnemyBullets[i].mUsed ==true){
int index = mEnemyBullets[i].mDirection== HF.STATE_MOVE_LEFT ? 0:1;
//System.out.println("敌人子弹X"+mEnemyBullets[i].mX+"敌人子弹Y"+mEnemyBullets[i].mY);
g.drawImage(mBulletImages[index],mEnemyBullets[i].mX,mEnemyBullets[i].mY,Graphics.LEFT|Graphics.TOP);
}
}
//System.out.println("B");
//绘制场景中的药箱
for(int i =0;i<2;i++){
if(mCabinets[i].mUsed == true){
g.drawImage(mCabinetImage[mCabinets[i].mType==1?0:1],mCabinets[i].mX,mCabinets[i].mY,Graphics.TOP|Graphics.LEFT);
}
}
//System.out.println("C");
//绘制场景中的敌人
boolean[] flags = new boolean[MAX_PAWN];//是否需要留待绘制小爱之后才绘制
for(int i=0;i<MAX_PAWN;i++){
flags[i] = false;
if(mPawns[i].mUsed==true){
if((mPawns[i].mY+mPawns[i].mImages[2].getHeight())<(mPlayer.mY+mPlayer.mImages[2].getHeight())){//敌兵位置在小爱的上方
//System.out.println("敌人"+mPawns[i]);
mPawns[i].draw(g);
mPawns[i].setFrame();
} else{
flags[i] = true;//敌兵在小爱的下方,要等绘制小爱后再绘制
}
}
}
//System.out.println("D");
if(mPlayer.mUsed == true){
mPlayer.draw(g);
if(mPlayer.mState != HF.STATE_STILL){
mPlayer.setFrame();
}
}
//System.out.println("E");
//绘制位于小爱下方的敌人
for(int i=0;i<MAX_PAWN;i++){
if(flags[i] == true){
mPawns[i].draw(g);
mPawns[i].setFrame();
}
}
g.setClip(0,0,mSceneWidth,mSceneHeight);
for(int i=0;i<MAX_ENEMY_BULLET+MAX_BULLET;i++){
// g.drawImage(mBBImg,mBBlood[i].mX,mBBlood[i].mY,Graphics.LEFT|Graphics.TOP);
if(mBBlood[i].mUsed){
mBBlood[i].mUsed=false;
g.drawImage(mBBImg,mBBlood[i].mX,mBBlood[i].mY,Graphics.LEFT|Graphics.TOP);
}
}
for(int i=0;i<MAX_BULLET;i++){
// g.drawImage(mBBImg,mBBlood[i].mX,mBBlood[i].mY,Graphics.LEFT|Graphics.TOP);
if(mBFloor[i].mUsed){
mBFloor[i].mUsed=false;
g.drawImage(mBFImg,mBFloor[i].mX,mBFloor[i].mY,Graphics.LEFT|Graphics.TOP);
}
}
//System.out.println("F");
//绘制场景中的下一排的布景
for(int i=0;i<MAX_SCENEUNIT;i++){
if(mDownScenes[i].mUsed == true){
int x =mDownScenes[i].mX,y = mDownScenes[i].mY;
Image img = mSceneImages[mDownScenes[i].mType-2];
g.drawImage(img,x,y,Graphics.LEFT|Graphics.BOTTOM);
}
}
//System.out.println("G");
}
private int[] sceneCount=new int[3];
//绘制场景
static final String[] mSceneName = {"口腔","食道","","胃","肠"};
static final int[] mNumPosi = {54,0,6,12,18,24,30,36,42,48};
private void drawNum(Graphics g,int num,int x1,int y1) {
int x = x1;
int y = y1;
while(num>0) {
int i = num%10;
g.setClip(x,y,6,7);
g.drawImage(mNumImage,x-mNumPosi[i],y,Graphics.LEFT|Graphics.TOP);
x -= 7;
num /= 10;
}
g.setClip(0,0,176,208);
}
public void draw(Graphics g) {
int transX = mBufferGraphics.getTranslateX();
sceneCount[0]=transX;
mBufferGraphics.setClip(0,0,mSceneWidth,mSceneHeight);
//for(int i=0;i<mBackgroundImage.length;i++)
{
switch(mLevel) {
case 1:
case 2:
case 4:
case 5:
mBufferGraphics.drawImage(mBackgroundImage[0],-sceneCount[0],0,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.drawImage(mBackgroundImage[0],mSceneWidth-sceneCount[0],0,Graphics.LEFT|Graphics.TOP);
break;
case 3:
mBufferGraphics.drawImage(mBackgroundImage[1],-sceneCount[2],0,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.drawImage(mBackgroundImage[1],mSceneWidth-sceneCount[2],0,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.drawImage(mBackgroundImage[0],-sceneCount[0],115,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.drawImage(mBackgroundImage[0],mSceneWidth-sceneCount[0]-7,115,Graphics.LEFT|Graphics.TOP);
break;
//mBufferGraphics.drawImage(mBackgroundImage[1],-sceneCount[2],0,Graphics.LEFT|Graphics.TOP);
//mBufferGraphics.drawImage(mBackgroundImage[1],mSceneWidth-sceneCount[2],0,Graphics.LEFT|Graphics.TOP);
//mBufferGraphics.drawImage(mBackgroundImage[0],-sceneCount[0],0,Graphics.LEFT|Graphics.TOP);
//mBufferGraphics.drawImage(mBackgroundImage[0],mSceneWidth-sceneCount[0],0,Graphics.LEFT|Graphics.TOP);
// break;
}
}
drawSceneObjects(mBufferGraphics);//绘制场景中的其余物品
mBufferGraphics.setClip(0,0,mSceneWidth,mSceneHeight);
//绘制玩家和敌兵头目的生命值
int x=0,y = 8;
if(mPlayer.mUsed == true){
//mBufferGraphics.setColor(HF.COLOR_WHITE);
//mBufferGraphics.fillRect(x+23,y+4,HP_LENGTH,4);
if(hpSplashTime>0){
hpSplashTime--;
if(hpSplashTime==0){
mPlayer.mLife += 20;
if(mPlayer.mLife>100){
mPlayer.mLife = 100;
}
}
if(hpSplashTime%2==0){
mBufferGraphics.drawImage(mPlayerHPImage,x,y,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.setColor(0);
mBufferGraphics.fillRect(x+30+mPlayer.mLife*HP_LENGTH/100,y+10,35-mPlayer.mLife*HP_LENGTH/100,6);
}
}else{
mBufferGraphics.drawImage(mPlayerHPImage,x,y,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.setColor(0);
mBufferGraphics.fillRect(x+30+mPlayer.mLife*HP_LENGTH/100,y+10,35-mPlayer.mLife*HP_LENGTH/100,6);
}
if(fireNum>0) {
drawNum(mBufferGraphics,fireNum,x+70,y+20);
} else {
mBufferGraphics.setClip(x+60,y+20,13,7);
mBufferGraphics.drawImage(mNumImage,x+60-60,y+20,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.setClip(0,0,176,208);
}
}
//y = y+ 30;
x = 100;
y = 180;
if(mCock.mUsed == true){
mBufferGraphics.drawImage(mCockHPImage,x,y,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.setColor(HF.COLOR_RED);
mBufferGraphics.fillRect(x+30+mCock.mLife*HP_LENGTH/mCockLife[mLevel-1],y+16,35-mCock.mLife*HP_LENGTH/mCockLife[mLevel-1],3);
} else if(mPreCock.mUsed == true){
mBufferGraphics.drawImage(mCockHPImage,x,y,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.setColor(0);
mBufferGraphics.fillRect(x+30+mPreCock.mLife*HP_LENGTH/mCockLife[mLevel-1],y+16,35-mPreCock.mLife*HP_LENGTH/mCockLife[mLevel-1],3);
}
//关卡开头
if(bShowFrames) {
if(mFramesPosiX>(mSceneWidth>>1)) {
mFramesPosiX-=16;
} else if(mFramesPosiX<=(mSceneWidth>>1)&&mFramesCount>0) {
mFramesPosiX = mSceneWidth>>1;
mFramesCount -=2;
} else {
mFramesPosiX-=16;
if(mFramesPosiX<-40)
bShowFrames = false;
}
mBufferGraphics.drawImage(mFramesImage[0],mFramesPosiX,mFramesPosiY,Graphics.HCENTER|Graphics.BOTTOM);
mBufferGraphics.setFont(HF.SMALL_FONT);
mBufferGraphics.setColor(0x500000);
mBufferGraphics.drawString(mSceneName[mLevel-1],mFramesPosiX,mFramesPosiY-10,Graphics.HCENTER|Graphics.BOTTOM);
}
//绘制通关时的提示信息
if(isPassLevel() == true){
x = (mSceneWidth-mPassImage.getWidth())/2;
y = (mSceneHeight-120)/2;
mBufferGraphics.drawImage(mPassImage,x,y,Graphics.LEFT|Graphics.TOP);
y = y+ 30;
int width = 155, height = 98;//背景阴影的大小
x = (mSceneWidth-width)/2;
/* mBufferGraphics.setColor(HF.COLOR_GRAY);
mBufferGraphics.fillRect(x+4,y+4,width,height);
mBufferGraphics.setColor(HF.COLOR_WHITE);
mBufferGraphics.fillRect(x,y,width,height);
mBufferGraphics.setColor(HF.COLOR_BLACK);
mBufferGraphics.setFont(HF.MEDIUM_FONT);
*/
//x = x+2;
y = y+4;
mBufferGraphics.drawImage(mFramesImage[1],x,y,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.setClip(x+2,y,24,35);
//mBufferGraphics.drawImage(mPlayerImages[1],x+2,y,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.setClip(x,y+height/2,28,35);
///mBufferGraphics.drawImage(mPawnImages[1],x,y+height/2,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.setClip(0,0,mSceneWidth,mSceneHeight);
y = y +16;
x = x + 34;
mBufferGraphics.drawString("得分: "+mScore.getScore(),x,y,Graphics.LEFT|Graphics.TOP);
mBufferGraphics.drawString("杀敌数: "+mKillPawn,x,y+height/2,Graphics.LEFT|Graphics.TOP);
}
/* if(isTalk)
{
//mBufferGraphics.setColor(0xffffff);
//mBufferGraphics.fillRect(0,5,mSceneWidth,30);
//System.out.println(mPreCock.mX+" "+" "+mPreCock.mY);
}
*/
g.drawImage(mBufferImage,-transX,0,Graphics.LEFT|Graphics.TOP);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -