📄 mariomainsprite.java
字号:
case FIRE_SPRITE:
rect2.x=gm.mashRooms[i].x;
rect2.y=gm.mashRooms[i].y;
if(LPRect.IntersectRect(rect1,rect2))
{
if(gm.mashRooms[i].frameCnt==8)
{
if(gm.menu.isVolOn)
{
gm.beatPlayer.replay();
}
// add a person
gm.mashRooms[i].isHidden=true;
return true;
}
}
break;
}
}
}
rect2.dy = 10;
rect2.dx = 10;
for(i=gm.flowers.length-1;i>=0;--i)
{
if(!gm.flowers[i].isHidden)
{
rect2.x=gm.flowers[i].x+3;
rect2.y=gm.flowers[i].y+2;
switch(mainSpriteState)
{
case SMALL_SPRITE:
if (LPRect.IntersectRect(rect1, rect2))
{
if(gm.menu.isVolOn)
{
gm.beatPlayer.replay();
}
gm.flowers[i].isHidden = true;
mainSpriteState = GROW_SPRITE;
return true;
}
break;
case NORMAL_SPRITE:
if(LPRect.IntersectRect(rect1,rect2))
{
if(gm.menu.isVolOn)
{
gm.beatPlayer.replay();
}
gm.flowers[i].isHidden=true;
mainSpriteState=BECOME_FIRE;
return true;
}
break;
case FIRE_SPRITE:
if (LPRect.IntersectRect(rect1, rect2))
{
if(gm.menu.isVolOn)
{
gm.beatPlayer.replay();
}
gm.flowers[i].isHidden = true;
mainSpriteState = FIRE_SPRITE;
return true;
}
break;
}
}
}
rect2.dx = 14;
rect2.dy = 14;
switch(gm.gameState)
{
case MarioGameManage.GAMESTATE_GAMELOOP:
for(i=gm.staticGold.length-1;i>=0;--i)
{
if(!gm.staticGold[i].isHidden)
{
rect2.x = gm.staticGold[i].x;
rect2.y = gm.staticGold[i].y;
if(LPRect.IntersectRect(rect1,rect2))
{
gm.staticGold[i].isHidden = true;
if(++gm.goldNum==100)
{
gm.goldNum = 0;
}
if(gm.menu.isVolOn)
{
gm.beatPlayer.replay();
}
}
}
}
break;
}
return false;
}
public void judgeKeyCode(int keyCode, int gameKeyCode)
{
switch (gameKeyCode)
{
case Canvas.UP:
if (dy == 0)
{
if ( ( ( (allAction & LPKeyMask.MASK_KEY_UP) == 0)
&& ( (allAction & LPKeyMask.MASK_KEY_UP_FLAG) == 0)))
{
allAction |= LPKeyMask.MASK_KEY_UP_FLAG | LPKeyMask.MASK_KEY_UP;
dy -= 18;
}
}
break;
case Canvas.FIRE:
if((((allAction&LPKeyMask.MASK_KEY_OK)==0)
&&((allAction&LPKeyMask.MASK_KEY_OK_FLAG)==0)))
{
allAction|=LPKeyMask.MASK_KEY_OK|LPKeyMask.MASK_KEY_OK_FLAG;
}
break;
case Canvas.LEFT:
allAction |= LPKeyMask.MASK_KEY_LEFT;
break;
case Canvas.RIGHT:
allAction |= LPKeyMask.MASK_KEY_RIGHT;
break;
default:
switch (keyCode)
{
case Canvas.KEY_NUM2:
if(dy==0)
{
if((((allAction&LPKeyMask.MASK_KEY_UP)==0)
&&((allAction&LPKeyMask.MASK_KEY_UP_FLAG)==0)))
{
allAction|=LPKeyMask.MASK_KEY_UP_FLAG|LPKeyMask.MASK_KEY_UP;
dy-=18;
}
}
break;
case Canvas.KEY_NUM4: //left
allAction |= LPKeyMask.MASK_KEY_LEFT;
break;
case Canvas.KEY_NUM6: //right
allAction |= LPKeyMask.MASK_KEY_RIGHT;
break;
case Canvas.KEY_NUM5:
if((((allAction&LPKeyMask.MASK_KEY_OK)==0)
&&((allAction&LPKeyMask.MASK_KEY_OK_FLAG)==0)))
{
allAction|=LPKeyMask.MASK_KEY_OK|LPKeyMask.MASK_KEY_OK_FLAG;
}
break;
}
break;
}
}
public void freeKey(int keyCode, int gameKeyCode)
{
switch (gameKeyCode)
{
case Canvas.FIRE:
allAction &= ~LPKeyMask.MASK_KEY_OK;
break;
case Canvas.UP:
allAction &= ~LPKeyMask.MASK_KEY_UP;
break;
case Canvas.DOWN:
allAction &= ~LPKeyMask.MASK_KEY_DOWN;
break;
case Canvas.LEFT:
allAction &= ~LPKeyMask.MASK_KEY_LEFT;
break;
case Canvas.RIGHT:
allAction &= ~LPKeyMask.MASK_KEY_RIGHT;
break;
default:
switch (keyCode)
{
case Canvas.KEY_NUM4: //left
allAction &= ~LPKeyMask.MASK_KEY_LEFT;
break;
case Canvas.KEY_NUM6:
allAction &= ~LPKeyMask.MASK_KEY_RIGHT; //right
break;
case Canvas.KEY_NUM2:
allAction &= ~LPKeyMask.MASK_KEY_UP; //jump
break;
case Canvas.KEY_NUM8:
allAction &= ~LPKeyMask.MASK_KEY_DOWN;
break;
case Canvas.KEY_NUM5:
allAction &= ~LPKeyMask.MASK_KEY_OK;
break;
}
break;
}
}
private void walk()
{
frameCnt++;
if (this.frameCnt > 3 + offset || this.frameCnt < 1 + offset)
{
this.frameCnt = 1 + offset;
}
}
private boolean checkTileCollisionVertical()
{
if (mainSpriteState == SMALL_SPRITE)
{
// 16X16
if (this.dy > 0)
{
isJumpOver = true;
for (int i = (y + this.judgeMap.y+15) /
this.judgeMap.tileSize+1;
i <= (y + this.judgeMap.y + dy) / this.judgeMap.tileSize+1; i++)
{
if (i < 0 || i > judgeMap.h - 1)
{
continue;
}
int xTile1 = (x + this.judgeMap.x + 2) / this.judgeMap.tileSize;
int xTile2 = (x + this.judgeMap.x + 14) / this.judgeMap.tileSize;
if (xTile2 > this.judgeMap.w - 1 || xTile1 < 0)
{
return false;
}
if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x02) == 0x02)
{
dy = (i - 1) * this.judgeMap.tileSize - (y + this.judgeMap.y);
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
return true;
}
if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x02) == 0x02)
{
dy = (i - 1) * this.judgeMap.tileSize - (y + this.judgeMap.y);
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
return true;
}
}
}
else if (dy < 0)
{
for (int i = (y + this.judgeMap.y + dy) / this.judgeMap.tileSize;
i <= (y + this.judgeMap.y) / this.judgeMap.tileSize; i++)
{
if (i < 0 || i > judgeMap.h - 1)
{
continue;
}
int xTile1 = (x + this.judgeMap.x + 2) / this.judgeMap.tileSize;
int xTile2 = (x + this.judgeMap.x + 14) / this.judgeMap.tileSize;
if (xTile2 > this.judgeMap.w - 1 || xTile1 < 0)
{
return false;
}
if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x08) == 0x08)
{
dy = 0;
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
if(isJumpOver)
{
changeUpSpriteState();
isJumpOver =false;
}
return true;
}
if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x08) == 0x08)
{
dy = 0;
if(isJumpOver)
{
changeUpSpriteState();
isJumpOver =false;
}
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
return true;
}
if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x01) == 0x01)
{
dy = 0;
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
return true;
}
if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x01) == 0x01)
{
dy = 0;
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
return true;
}
}
}
else
{
isJumpOver = true;
}
}
else
{
//32 X 32
if (this.dy > 0)
{
isJumpOver = true;
for (int i = (y + this.judgeMap.y+15) /
this.judgeMap.tileSize + 2;
i <= (y + this.judgeMap.y + dy) / this.judgeMap.tileSize + 2; i++)
{
if (i < 0 || i > judgeMap.h - 1)
{
continue;
}
int xTile1 = (x + this.judgeMap.x + 12) / this.judgeMap.tileSize;
int xTile2 = (x + this.judgeMap.x + 20) / this.judgeMap.tileSize;
if (xTile2 > this.judgeMap.w - 1 || xTile1 < 0)
{
return false;
}
if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x02) == 0x02)
{
dy = (i - 2) * this.judgeMap.tileSize - (y + this.judgeMap.y);
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
return true;
}
if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x02) == 0x02)
{
dy = (i - 2) * this.judgeMap.tileSize - (y + this.judgeMap.y);
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
return true;
}
}
}
else if (dy < 0)
{
for (int i = (y + this.judgeMap.y + dy) / this.judgeMap.tileSize;
i <= (y + this.judgeMap.y ) / this.judgeMap.tileSize; i++)
{
if (i < 0 || i > judgeMap.h - 1)
{
continue;
}
int xTile1 = (x + this.judgeMap.x + 12) / this.judgeMap.tileSize;
int xTile2 = (x + this.judgeMap.x + 20) / this.judgeMap.tileSize;
if (xTile2 > this.judgeMap.w - 1 || xTile1 < 0)
{
return false;
}
if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x08) == 0x08)
{
dy = 0;
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
if (isJumpOver)
{
judgeMap.mapArray[i][xTile1] = judgeMap.mapArray[0][0];
gm.createBrokenBrick(x + 10, y - 5, -5, -12);
gm.createBrokenBrick(x + 10, y - 5, 5, -12);
gm.createBrokenBrick(x + 10, y - 5, -5, -6);
gm.createBrokenBrick(x + 10, y - 5, 5, -6);
isJumpOver = false;
}
return true;
}
if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x08) == 0x08)
{
dy = 0;
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
if (isJumpOver)
{
judgeMap.mapArray[i][xTile2] = judgeMap.mapArray[0][0];
gm.createBrokenBrick(x + 10, y - 5, -5, -12);
gm.createBrokenBrick(x + 10, y - 5, 5, -12);
gm.createBrokenBrick(x + 10, y - 5, -5, -6);
gm.createBrokenBrick(x + 10, y - 5, 5, -6);
isJumpOver = false;
}
return true;
}
if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x01) == 0x01)
{
dy = 0;
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
return true;
}
if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x01) == 0x01)
{
dy = 0;
allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
return true;
}
}
}
else
{
isJumpOver = true;
}
}
return false;
}
private boolean checkTileCollisionHorizon()
{
int i;
if (mainSpriteState == SMALL_SPRITE)
{
rect1.y = this.y + this.judgeMap.y;
rect1.dx = 16;
rect1.dy = 16;
rect2.dx = 16;
rect2.dy = 16;
rect1.x = x + judgeMap.x + dx;
if (dx<0)
{
i = (x + judgeMap.x + dx) / judgeMap.tileSize;
}
else
{
i = (x + judgeMap.x + dx) / judgeMap.tileSize + 1;
}
if (i < 0 || i > this.judgeMap.w - 1)
return false;
int yTile1 = (y + judgeMap.y) / judgeMap.tileSize;
int yTile2 = (y + judgeMap.y) / judgeMap.tileSize+1;
if (yTile1 < 0 || yTile2 > judgeMap.h - 1)
return false;
if(dx>0)
{
if(((this.judgeMap.mapArray[yTile1][i]>>8)&0x10)==0x10)
{
rect2.x=i*16;
rect2.y=yTile1*16;
if(LPRect.IntersectRect(rect1,rect2))
{
return true;
}
}
}
if(((this.judgeMap.mapArray[yTile1][i]>>8)&0x04)==0x04)
{
rect2.x = i * 16;
rect2.y = yTile1 * 16;
if (LPRect.IntersectRect(rect1, rect2))
{
return true;
}
}
if ( ( (this.judgeMap.mapArray[yTile2][i] >> 8) & 0x04) == 0x04)
{
rect2.x = i * 16;
rect2.y = yTile2 * 16;
if (LPRect.IntersectRect(rect1, rect2))
{
return true;
}
}
}
else
{
rect1.y = this.y + this.judgeMap.y+1;
rect1.dx = 16;
rect1.dy = 31;
rect2.dx = 16;
rect2.dy = 16;
if (dx<0)
{
rect1.x = x + judgeMap.x +6+dx;
i = (x + judgeMap.x +6+dx) / judgeMap.tileSize;
}
else
{
rect1.x = x + judgeMap.x +20+dx;
i = (x + judgeMap.x +20+dx) / judgeMap.tileSize ;
}
if (i < 0 || i > this.judgeMap.w - 1)
return false;
int yTile1 = (y + judgeMap.y) / judgeMap.tileSize;
int yTile2 = (y + judgeMap.y) / judgeMap.tileSize + 1;
int yTile3 = (y + judgeMap.y) / judgeMap.tileSize + 2;
if (yTile1 < 0 || yTile3 > judgeMap.h - 1)
return false;
if(dx>0)
{
boolean isCheck = false;;
if(((this.judgeMap.mapArray[yTile1][i]>>8)&0x10)==0x10)
{
rect2.x=i*16;
rect2.y=yTile1*16;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -