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

📄 avatar.java

📁 Critter_Crunch_J2ME 游戏源
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*******************************************************************************
 **
 ** Class: Avatar (Avatar.java)
 **
 ** The "Avatar" class encapsulates all the data and functionality associated
 ** with the Biggs, the user's avatar.
 **
 ******************************************************************************/



// Player header.
import javax.microedition.lcdui.Graphics;

// the Player class itself.
public class Avatar extends Entity {
   
   /****************************************************************************
    ** Constants
    ***************************************************************************/

   public static final int      BIGGS_ID           = 0;          // default Biggs ID.
   public static final int      STATE_TONGUE_FLICK = 0x00010000; // shooting tongue up.
   public static final int      STATE_TONGUE_DRAG  = 0x00020000; // dragging tongue down.
   public static final int      STATE_SPIT         = 0x00040000; // spitting out a Critter.
   public static final int      STATE_ONION_BREATH = 0x00100000; // blowing out onion breath.
   public static final int      STATE_CHOMP        = 0x00200000; // chomping down on a creature.
   public static final int      STATE_SKID         = 0x00400000; // skid to a stop.
   public static final int      STATE_SCARED       = 0x00800000; // Biggs is scared 'cause the creatures are about to attack him.
   public static final int      STATE_HOLD_DOWN    = 0x01000000; // Biggs is holding down and about to drop the stack by one.
   public static final int      STATE_DROP_BOARD   = 0x02000000; // Biggs has landed and the board should be dropping.
   public static final int      BREATH_TONGUE      = 0;          // tongue breath type.
   public static final int      BREATH_FIRE        = 1;          // tongue breath type.
   public static final int      BREATH_ICE         = 2;          // tongue breath type.
   public static final int      BREATH_ONION       = 3;          // tongue breath type.
   public static final int      TIME_CHEW          = 9;          // pause duration when chewing.
   public static final int      TIME_CHOMP         = 2;          // pause when chomping down on a creature.
   public static final int      TIME_SPIT          = 2;          // pause duration when spitting out Critters.
   public static final int      TIME_SKID          = 2;          // pause when skidding to a halt.
   public static final int      TIME_LANDING_SHAKE = 7;          // duration of Biggs shake when landing.
   public static final int      TIME_BOARD_JUMP_DROP = TOTFC.FRAMES_PER_SECOND / 2; // time for holding down and dropping/shaking the board.
   public static       byte     SPEED_DROP;                      // speed at which Biggs descends at the beginning of a level.
   public static       byte     SPEED_BOARD_JUMP;                // speed at which Biggs ascends after jumping when holding down.
   public static       byte     SPEED_SIDEWAYS;                  // Biggs' sideways movement speed.
   public static       byte     SPEED_TONGUE;                    // height of Biggs' tongue. 
   public static       byte     TONGUE_X;                        // x offset for Biggs' tongue.
   public static       byte     TONGUE_Y;                        // y offset for Biggs' tongue.
   public static       byte     TONGUE_W;                        // width of Biggs' tongue.
   public static       short    BIGGS_BOARD_Y;                   // destination of Biggs jump after holding down.      
   public static       byte     BIGGS_TONGUE_Y;                  // max height Biggs' tongue can reach.
   public static       short    BIGGS_GROUND_Y;                  // Biggs' ground anchor.
   public static       byte     BIGGS_SKY_Y;                     // Biggs' air anchor.
   public static       byte []  S_BOX;                           // Biggs' collision box.
   
   
   
   /****************************************************************************
    ** Variables
    ***************************************************************************/

   public              boolean  m_leftside;                      // flag that keeps track of which side Biggs faces.
   public              Critter  m_in_mouth;                      // reference to a Critter that Biggs is currently snagging/storing in his mouth.
   public              byte     m_powerup_id;                    // id of powerup that the player can currently use.
   public              byte     m_powerup_ammo;                  // powerup's left-over uses.
   public              short    m_tongue;                        // keeps track of how far Biggs' tongue is extended.
   public              short    m_destination_tongue;            // figure out the destination for Biggs' tongue.
   
   
   
   /****************************************************************************
    ** 'tors
    ***************************************************************************/
   
   // class initializer.
   public static void poke() { Thread.yield(); }
   
   // default Player constructor, off-screen.
   public Avatar() {
      
      m_id = BIGGS_ID;
      m_state = STATE_DEFAULT;
      m_leftside = true;
      setAnim(Anims.BIGGS_IDLE_LEFT);
      m_board_x = (byte)(Level.s_board[0].length / 2);
      m_board_y = (byte)(Engine.FULL_BYTE);
      m_x = m_next_x = m_destination_x = (short)(Level.s_board_x + (m_board_x * Level.SQUARE_W) + Level.SQUARE_HALF_W);
      m_y = m_next_y = m_destination_y = BIGGS_GROUND_Y;
      m_timer = 0;
      m_destination_tongue = m_tongue = 0;
      m_speed = 0;
      m_in_mouth = null;
      m_powerup_id = m_powerup_ammo = 0;
      //m_powerup_id = m_powerup_ammo = Critter.ITEM_PEPPER;
   }
   
   // Player constructor with a y destination.
   public Avatar(int destination_y) {
      
      this();
      
      m_state = STATE_DESCENDING;
      //#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Nokia_3220 || Nokia_3220_Unobfuscated || Razr
      setAnim(Anims.BIGGS_FALL);
      //#else
//#       setAnim(Anims.BIGGS_EATING);
      //#endif
      m_y = m_next_y = (short)destination_y;
      m_speed = SPEED_DROP;
   }

   
   
   /****************************************************************************
    ** Extended Methods
    ***************************************************************************/

   // process the Avatar's functionality.
   public void process() {

      super.process();
      Critter c = null;
      
      
      if( ((m_state & STATE_DESCENDING) != 0) ) {
         if(m_y >= m_destination_y) {
            if((m_state & STATE_HOLD_DOWN) != 0) {
               //#ifndef NO_SCREEN_SHAKING
               Engine.setShake(Engine.SHAKE_CRITTERS, Engine.BOTH_AXES, 3, TIME_BOARD_JUMP_DROP, false);
               Engine.setShake(Engine.SHAKE_BGS, Engine.BOTH_AXES, 3, TIME_BOARD_JUMP_DROP, false);
               Engine.setShake(Engine.SHAKE_BIGGS, Engine.BOTH_AXES, 3, TIME_BOARD_JUMP_DROP, false);
               //#endif
               
               //#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Nokia_3220 || Nokia_3220_Unobfuscated || Razr
               Level.s_board_state |= Level.BOARD_SCARE;
               setAnim(Anims.BIGGS_LANDING_J_SMASH_LEFT);
               //#endif
               m_state &= ~(STATE_DESCENDING | STATE_HOLD_DOWN);
               m_state |= STATE_DROP_BOARD;
               m_timer = TIME_BOARD_JUMP_DROP;
               Level.s_board_state |= Level.BOARD_DESCEND;
               Level.s_hold_down = 0;
               Level.s_board_timer_delay = 0;
               Level.s_board_timer = 0;
            }
            
            if(Level.s_state == Level.STATE_BIGGS_FALL) {
               m_state &= ~STATE_DESCENDING;
               setAnim(Anims.BIGGS_IDLE_LEFT);
               //#ifndef NO_SCREEN_SHAKING
               Engine.setShake(Engine.SHAKE_BGS, Engine.BOTH_AXES, 4, TIME_LANDING_SHAKE, false);
               //#endif
               Level.s_state = Level.STATE_BOARD_FALL;
            }
            else if(Level.s_state == Level.STATE_SCORE) {
               if((Level.s_type == Level.TYPE_ADVENTURE && Level.s_number + 1 < Level.LEVEL_COUNT) ||
                  (Level.s_type == Level.TYPE_PUZZLE && Level.s_number + 1 < Level.s_puzzles_unlocked) ||
                  (Level.s_type == Level.TYPE_TIMETRIAL && Level.s_number + 1 < Level.TIMETRIAL_COUNT)) {
                  if(Level.s_main_type == Level.TYPE_ADVENTURE) Level.init(Level.s_next_type, Level.s_next_number, Level.s_current_score);
                  else                                          Level.init(Level.s_type, ++Level.s_number, Level.s_current_score);        
               }
               else {
                  boolean all_puzzles_complete = true;
                  if (Level.s_type == Level.TYPE_PUZZLE) {
                     for (int i=0; i<Level.PUZZLE_COUNT; ++i) {
                        all_puzzles_complete = Level.S_COMPLETED_PUZZLES[i];
                        if (!Level.S_COMPLETED_PUZZLES[i]) break;
                     }
                  }
                  
                  // win the game conditions
                  if((Level.s_type == Level.TYPE_ADVENTURE && Level.s_number + 1 == Level.LEVEL_COUNT) ||
                     (Level.s_type == Level.TYPE_PUZZLE && Level.s_number + 1 == Level.PUZZLE_COUNT && all_puzzles_complete) ||
                     (Level.s_type == Level.TYPE_TIMETRIAL && Level.s_number + 1 == Level.TIMETRIAL_COUNT)) {
                     
                     if (!Level.s_game_win) {
                        
                        if (Level.s_type == Level.TYPE_PUZZLE && Level.s_main_type == Engine.FULL_BYTE) {
                           Menus.startTextBox(Locale.YOU_WIN_TEXT_PUZZLE, Menus.TEXT_TYPE_END);
                        } else if (Level.s_type == Level.TYPE_TIMETRIAL && Level.s_main_type == Engine.FULL_BYTE) {
                           Menus.startTextBox(Locale.YOU_WIN_TEXT_TIME_TRIAL, Menus.TEXT_TYPE_END);
                        } else {
                           Menus.startTextBox(Locale.YOU_WIN_TEXT_ADVENTURE, Menus.TEXT_TYPE_END);
                        }
                        
                        //Engine.s_engine.initEnding();
                        Level.s_game_win = true;
                     }
                  } else {
                     Engine.gotoTitle();
                  }
               }
            }
         }
      }
      if( ((m_state & STATE_ASCENDING) != 0) ) {
         if(m_y <= m_destination_y) {
            m_state &= ~STATE_ASCENDING;

            if((m_state & STATE_HOLD_DOWN) != 0) {
               m_state |= STATE_DESCENDING;
               m_destination_y = BIGGS_GROUND_Y;
               m_speed = SPEED_DROP;
               //#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Nokia_3220 || Nokia_3220_Unobfuscated || Razr
               setAnim(Anims.BIGGS_FALL);
               //#endif
            }
            
            if(Level.s_state == Level.STATE_BIGGS_FLY) {
               Level.s_clock = Level.TIME_BIGGS_EXIT;
            }
            else if(Level.s_state == Level.STATE_SCORE) {
               Menus.startStatsScreen(Level.s_type);
            }
         }
      }
      //#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Nokia_3220 || Nokia_3220_Unobfuscated || Razr
      if( ((m_state & STATE_WESTWARD) != 0) ) {
         m_next_x -= m_speed;
         if(m_next_x < Level.s_board_x + Level.SQUARE_HALF_W) stop();
      }
      if( ((m_state & STATE_EASTWARD) != 0) ) {
         m_next_x += m_speed;
         if(m_next_x > Level.s_board_x + Level.GAME_BOARD_W * Level.SQUARE_W - Level.SQUARE_HALF_W) stop();
      }
      //#else
//#       if( ((m_state & STATE_WESTWARD) != 0) ) {
//#          if(m_x <= m_destination_x) {
//#             stop();
//#             m_state &= ~(STATE_WESTWARD | STATE_IMMOBILE);
//#             setAnim(Anims.BIGGS_IDLE_LEFT);
//#          }
//#          else {
//#             m_next_x -= m_speed;
//#          }
//#       }
//#       if( ((m_state & STATE_EASTWARD) != 0) ) {
//#          if(m_x >= m_destination_x) {
//#             stop();
//#             m_state &= ~(STATE_EASTWARD | STATE_IMMOBILE);
//#             setAnim(Anims.BIGGS_IDLE_LEFT);
//#          }
//#          else {
//#             m_next_x += m_speed;
//#          }
//#       }
      //#endif
      if( ((m_state & STATE_EATING) != 0) ) {

⌨️ 快捷键说明

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