⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gamegame.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    dos.writeByte(AttackWave);
    dos.writeByte(Vibrator);
    dos.writeByte(Sound);
  }

  public void unSerialize( DataInputStream dis ) throws IOException {
    Marker = dis.readChar();
    HighScoreListEntries.unSerialize(dis);
    Level = dis.readShort();
    Wave = dis.readByte();
    ValidHighScores = dis.readByte();
    Score = dis.readInt();
    Lives = dis.readByte();
    Bombs = dis.readByte();
    Difficulty = dis.readByte();
    Humans = dis.readByte();
    AttackWave = dis.readByte();
    Vibrator = dis.readByte();
    Sound = dis.readByte();
  }
}

class
DefEnemies_t {
  public DefKidnapper_t pKidnappers[ ] = new DefKidnapper_t [ 6 ];
  public DefBomber_t pBombers[ ] = new DefBomber_t [ 3 ];
  public DefSuperAlien_t pSuperAliens[ ] = new DefSuperAlien_t [ 4 ];
  public DefScout_t pScouts[ ] = new DefScout_t [ 6 ];

  public DefMine_t pMines[ ] = new DefMine_t [ 5 ];

  public byte enemyOrder[ ] = new byte [ ( 6 + 3 + 4 + 6 ) ];
  public byte enemyNr[ ] = new byte [ ( 6 + 3 + 4 + 6 ) ];

  public byte nrOfEnemies;

}

class
DefShots_t {
  public boolean newPlayerShot;
  public DefTheShot_t pPlayerShots[ ] = new DefTheShot_t [ 5 ];
  public DefTheShot_t pEnemyShots[ ] = new DefTheShot_t [ 16 ];
}

class
DefGameState_t {
  public short status;
  public short statusData;
  public DefWorld_t display = new DefWorld_t();

  public boolean VibratorStarted;

  public DefPlayer_t pPlayer = new DefPlayer_t();
  public DefTerrain_t pTerrain = new DefTerrain_t();
  public DefEnemies_t pEnemies = new DefEnemies_t();
  public DefShots_t pShots = new DefShots_t();

  public DefExplosion_t pExplosions[ ] = new DefExplosion_t [ 10 ];

  public DefHuman_t pHumans[ ] = new DefHuman_t [ 5 ];


  public DefAdvancedRadar_t pAdvancedRadar = new DefAdvancedRadar_t();


  public DefAnimation_t largeExplosionAnimation = new DefAnimation_t();
  public DefAnimation_t mediumExplosionAnimation = new DefAnimation_t();
  public DefAnimation_t smallExplosionAnimation = new DefAnimation_t();

  public DefAnimation_t kidnapperAnimation = new DefAnimation_t();
  public DefAnimation_t bomberAnimation = new DefAnimation_t();
  public DefAnimation_t superAlienAnimation = new DefAnimation_t();
  public DefAnimation_t scoutAnimation = new DefAnimation_t();
  public DefAnimation_t mineAnimation = new DefAnimation_t();
  public DefAnimation_t humanAnimation = new DefAnimation_t();
  public DefAppearance_t humanCarriedAppearance = new DefAppearance_t();

  public DefAppearance_t smartBomb = new DefAppearance_t();
  public DefAppearance_t shipLeft = new DefAppearance_t();

  public byte nrOfKidnappers;
  public byte nrOfBombers;
  public byte nrOfScouts;
  public byte nrOfSuperAliens;

  public byte nrOfBombs;
  public byte nrOfLives;
  public short levelNr;
  public byte difficultyLevel;
  public int score;

  public int scoreBase;
  public byte bombBase;
  public byte lifeBase;
  public byte humanBase;

  public boolean newScore;
  public boolean newLives;
  public boolean newBombs;
  public boolean gamePaused;

  public int scoreNextLife;

  public boolean specialLevel;

  public boolean droppedBomb;

  public byte currentAttackWave;

  public byte nrOfKidnappings;

  public byte kidnapperShoot;
  public byte kidnapperKidnap;
  public byte scoutShoot;
  public byte scoutSeek;
  public byte superAlienShoot;
  public byte superAlienSeek;
  public byte superAlienMadShoot;
  public byte superAlienMadSeek;

  public byte SplashTickCount;
}

class
DefGlobalState_t {

  public short timerDelay;

  public DefGameState_t GameState = new DefGameState_t();


}

DefGlobalState_t DefGlobalState_p = null;

DefFrameworkStateStruct_t DefState = new DefFrameworkStateStruct_t();

static DefSaveData_t DefSaveData_p = null;
static GAPI_HighscoreList_t DefHighScoreList_p = null;

/**
  * A few constants deferred from the original unprocessed source code.
  */
static final short DEF_YOFFSET = 9; // 8 + 1
static final short DEF_ERASE_PLAYGROUND_HEIGHT = 53; // 53





/**
  *
  *
  *
  * @param pPlayer
  */
void
DefInitPlayer(DefPlayer_t pPlayer)
{
  DefAllocatePlayer();
}










/**
  * Draw all shots.
  *
  */
void
DefDrawShots(DefTheShot_t[] pShots,
short nrOfShots,
DefWorld_t pWorld,
boolean IsPlayer)
{
  byte ix;
  short xpos;

  for (ix = 0; ix < nrOfShots; ix++)
  {
    if (pShots[ix].shot.timeToLive > 0)
    {
      if (IsPlayer)
      {
        xpos = (short) ((pWorld.width + pShots[ix].shot.object.xpos - pWorld.xpos) % pWorld.width);

        if ((xpos > DISPLAY_WIDTH) || ((xpos + pShots[ix].shot.object.pAppearance.width) < 0))
        {
          pShots[ix].shot.timeToLive = 0;
        }
        else
        {
          DefDrawObject(pShots[ix].shot.object, pWorld);
        }
      }
      else
      {
        DefDrawObject(pShots[ix].shot.object, pWorld);
      }
    }
  }
} 



/**
  * Initializes all shots, by setting timeToLive to 0.
  *
  */
void
DefInitShots(DefTheShot_t[] pShots,
short nrOfShots)
{
  byte ix;

  for (ix = 0; ix < nrOfShots; ix++)
  {
    pShots[ix].shot.timeToLive = 0;
  }
}



/**
  * Update all PlayerShots.
  *
  * @param pShots  pointer to the shots
  * @param nrOfShots the number of shots
  * @param pWorld  pointer to the world which contains the current offset
  *
  */
void
DefUpdatePlayerShots(DefTheShot_t[] pShots,
short nrOfShots,
DefWorld_t pWorld)
{
  byte ix;

  for (ix = 0; ix < nrOfShots; ix++)
  {
    if (pShots[ix].shot.timeToLive > 0)
    {
      pShots[ix].shot.timeToLive--;

      pShots[ix].shot.object.xpos = (short) (pShots[ix].shot.object.xpos + pShots[ix].xspeed);

      if (pShots[ix].shot.object.xpos < 0)
      {
        pShots[ix].shot.object.xpos = (short) (pShots[ix].shot.object.xpos + pWorld.width);
      }

      pShots[ix].shot.object.xpos = (short) (pShots[ix].shot.object.xpos % pWorld.width);

    }
  }
} 






/**
  *
  *
  *
  * @param pShots
  * @param nrOfShots
  * @param pWorld
  */
void
DefUpdateEnemyShots(DefTheShot_t[] pShots,
short nrOfShots,
DefWorld_t pWorld)
{
  byte ix;

  for (ix = 0; ix < nrOfShots; ix++)
  {
    if (pShots[ix].shot.timeToLive > 0)
    {
      pShots[ix].shot.timeToLive--;
      pShots[ix].shot.object.xpos = (short) (pShots[ix].shot.object.xpos + pShots[ix].xspeed);
      pShots[ix].shot.object.ypos = (short) (pShots[ix].shot.object.ypos + pShots[ix].yspeed);

      if (pShots[ix].shot.object.xpos < 0)
      {
        pShots[ix].shot.object.xpos = (short) (pShots[ix].shot.object.xpos + pWorld.width);
        if (pShots[ix].shot.object.xpos < 0)
        {
          pShots[ix].shot.object.xpos = 0;
        }
      }

      if (pShots[ix].shot.object.xpos >= pWorld.width)
      {
        pShots[ix].shot.object.xpos = (short) (pShots[ix].shot.object.xpos - pWorld.width);
      }

      if (pShots[ix].shot.object.ypos < 0)
      {
        pShots[ix].shot.timeToLive = 0;
      }

      if (pShots[ix].shot.object.ypos >= pWorld.height)
      {
        pShots[ix].shot.timeToLive = 0;
      }

    }
  }
} 





/**
  *
  *
  *
  * @param pHumans
  * @param nrOfHumans
  * @param pWorld
  *
  * @returns
  */
byte
DefUpdateHumans(DefHuman_t[] pHumans,
		short nrOfHumans,
		DefWorld_t pWorld)
{
  byte ix;
  byte nrOfHumansLeft;

  nrOfHumansLeft = 0;

  for (ix = 0; ix < nrOfHumans; ix++)
  {

    switch (pHumans[ix].status)
    {


      case  2 :
      {
        DefEnemy_t P;

        P = (DefEnemy_t) pHumans[ix].CarriedBy;
        nrOfHumansLeft++;
        pHumans[ix].reflectable.collidable.object.ypos = (short)(P.ypos + P.reflectable.collidable.object.pAppearance.height);
      }
      break;


      case  3 :
      {
        DefPlayer_t P;

        P = (DefPlayer_t) pHumans[ix].CarriedBy;
        nrOfHumansLeft++;
        pHumans[ix].reflectable.collidable.object.xpos = (short)(P.xpos + 3);
        pHumans[ix].reflectable.collidable.object.ypos = (short)(P.ypos + 5);
      }
      break;


      case  1 :
      nrOfHumansLeft++;
      pHumans[ix].FrameDelayCnt++;
      if (pHumans[ix].FrameDelayCnt >= pHumans[ix].FrameDelay)
      {
        pHumans[ix].FrameDelayCnt = 0;
        pHumans[ix].FrameIx = (byte)((pHumans[ix].FrameIx + 1) % pHumans[ix].pAnim.nrOfFrames);
        pHumans[ix].reflectable.collidable.object.pAppearance = pHumans[ix].pAnim.pAppearance[pHumans[ix].FrameIx];
      }
      break;


      case  4 :
      nrOfHumansLeft++;

      pHumans[ix].FrameDelayCnt++;
      if (pHumans[ix].FrameDelayCnt >= pHumans[ix].FrameDelay)
      {
        pHumans[ix].FrameDelayCnt = 0;
        pHumans[ix].FrameIx = (byte)((pHumans[ix].FrameIx + 1) % pHumans[ix].pAnim.nrOfFrames);

        pHumans[ix].reflectable.collidable.object.pAppearance = pHumans[ix].pAnim.pAppearance[pHumans[ix].FrameIx];

      }
      pHumans[ix].FallSpeedCnt++;
      if (pHumans[ix].FallSpeedCnt >= pHumans[ix].FallSpeed)
      {
        pHumans[ix].reflectable.collidable.object.ypos++;
      }
      if (pHumans[ix].reflectable.collidable.object.ypos + pHumans[ix].reflectable.collidable.object.pAppearance.height >= pWorld.height)
      {

        if (pHumans[ix].reflectable.collidable.object.ypos - pHumans[ix].fallFrom >= 10)
        {

          DefAddExplosion(pHumans[ix].reflectable.collidable );

          pHumans[ix].Valid = false;
          pHumans[ix].status =  0 ;
          pHumans[ix].reflectable.radarAppearance = RA_Not_Available;
          nrOfHumansLeft--;
        }
        else
        {

          pHumans[ix].status =  1 ;
        }
      }
      break;
    }
  }
  return nrOfHumansLeft;
}






/**
  *
  *
  *
  * @param pHumans
  * @param nrOfHumans
  * @param pWorld
  */
/*void
DefDrawHumans(DefHuman_t pHumans,
short nrOfHumans,
DefWorld_t pWorld)
{
  byte ix;

  for (ix = 0; ix < nrOfHumans; ix++)
  {
    if (pHumans.status !=  0 )
    {
      DefDrawObject(pHumans.reflectable.collidable.object, pWorld);
    }
    pHumans++;
  }
} */








/**
  * Updates the worlds position depending on the 
  * players position and the direction of the player.
  *
  * @param pPlayer Pointer to the player
  * @param pWorld pointer to the world that should be moved
  *
  *
  */
void
DefUpdateWorldPosition(DefPlayer_t pPlayer,
DefWorld_t pWorld)
{
  short TargetX;
  short Dist;
  short Temp;
  short Temp2;

  if (pPlayer.headingLeft)
  {
    TargetX = pPlayer.xpos;
    TargetX += (3 * (pPlayer.collidable.object.pAppearance.width / 2));
    TargetX -= DISPLAY_WIDTH;
  }
  else
  {
    TargetX = (short) (pPlayer.xpos - (pPlayer.collidable.object.pAppearance.width / 2));
  }

  TargetX += pWorld.width; 
  TargetX = (short) (TargetX % pWorld.width);

  Dist = (short) (TargetX - pWorld.xpos);
  if (Math.abs(Dist) > (pWorld.width / 2))
  {
    if (Dist < 0)
    {
      Dist += pWorld.width;
    }
    else
    {
      Dist -= pWorld.width;
    }
  }
  Dist = (short)Math.abs(Dist);

  Temp = DefPlayer_t.PLAYER_MAX_X_SPEED; // FLOAT: ((int) (( (( float ) (( 8.2f ))) )))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -