📄 critter.java
字号:
/*******************************************************************************
**
** Class: Critter (Critter.java)
**
** The "Critter" class encapsulates all the data and functionality associated
** with all the different bugs and items in the game.
**
******************************************************************************/
// Critter header.
import javax.microedition.lcdui.Graphics;
// the Critter class itself.
public class Critter extends Entity {
/****************************************************************************
** Constants
***************************************************************************/
public static final int CREATURE_GREEN = 0; // generic green Critter.
public static final int CREATURE_RED = 1; // generic red Critter.
public static final int CREATURE_BLUE = 2; // generic blue Critter.
public static final int CREATURE_BLOCKER = 3; // blocker Critter.
public static final int CREATURE_TNT = 4; // exploding Critter.
public static final int CREATURE_WILDCARD = 5; // wildcard Critter.
public static final int CREATURE_TOXIC = 6; // toxic Critter.
public static final int CREATURE_ORANGE = 7; // generic orange Critter.
public static final int CREATURE_PURPLE = 8; // generic purple Critter.
public static final int ALL_CREATURES = 9; // number of different Critters in the whole game.
public static final int ITEM_WATERMELON = 0; // watermelon powerup.
public static final int ITEM_PEPPER = 1; // chili pepper powerup.
public static final int ITEM_ONION = 2; // onion powerup.
public static final int ALL_ITEMS = 6; // number of different item types.
public static final int ITEM_GEM_1 = 3; // gem type #1.
public static final int ITEM_GEM_2 = 4; // gem type #2.
public static final int ITEM_GEM_3 = 5; // gem type #3.
//#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Nokia_3220 || Nokia_3220_Unobfuscated || Razr
public static final int ITEM_GEM_4 = 6; // gem type #4.
public static final int ITEM_GEM_5 = 7; // gem type #5.
public static final int ITEM_GEM_6 = 8; // gem type #6.
public static final int ITEM_GEM_7 = 9; // gem type #7.
public static final int ITEM_GEM_8 = 10; // gem type #8.
public static final int ITEM_GEM_9 = 11; // gem type #9.
public static final int ITEM_GEM_OFFSET = ITEM_GEM_1 - 1; // offset for synching up gems with combos.
public static final int ITEM_GEM_TOXIC = 12; // the toxic gem.
public static final int ITEM_COIN = 13; // spinning coin.
public static final int ITEM_SEED = 14; // a seed from the watermelon.
//#else
//# public static final int ITEM_GEM_TOXIC = 6; // the toxic gem.
//# public static final int ITEM_COIN = 7; // spinning coin.
//# public static final int ITEM_SEED = 8; // a seed from the watermelon.
//#endif
public static final int STATE_TONGUED = 0x00001000; // being snatched by the player.
public static final int STATE_SPAT = 0x00002000; // being spat out by the player.
public static final int STATE_BEING_EATEN = 0x00004000; // being eaten by another Critter/boss.
public static final int STATE_CHEWING = 0x00008000; // chewing on another Critter.
public static final int STATE_CHILI_BLAST = 0x00010000; // Critter will take out a whole row.
public static final int STATE_BONUS = 0x00020000; // this is a bonus Critter and will be worth more points when popped.
public static final int STATE_CLIMBING = 0x00040000; // climbing up a vine.
public static final int STATE_DONE_CLIMB = 0x00080000; // finished climbing.
public static final int STATE_FOOD_CHAIN = 0x00100000; // part of a food chain.
public static final int STATE_FINAL_FALL = 0x00200000; // Critters are about to fall and attack Biggs.
public static final int STATE_ATTACKING = 0x00400000; // Critters have reached the ground and are assualting poor little biggs!
public static final int STATE_TOXIC = 0x01000000; // Critter is poisoned.
public static final int STATE_POISONED = 0x02000000; // Critter will be poisoned once he finishes eating.
public static final int STATE_SPAWN_DROP = 0x04000000; // gem-drop after a combo.
public static final int STATE_BLOCKER_PUFF = 0x08000000; // puff up a blocker when Biggs tries to grab him.
public static final int STATE_DROP_MELON = 0x10000000; // sheduled for watermelon drop.
public static final int STATE_DROP_PEPPER = 0x20000000; // sheduled for pepper drop.
public static final int STATE_DROP_ONION = 0x40000000; // sheduled for onion drop.
public static final int TYPE_CREATURE = 0; // creature-type creature.
public static final int TYPE_ITEM = 1; // item-type creature.
public static final int SIZE_INEDIBLE = 0; // can't be eaten by any Critters.
public static final int SIZE_SMALL = 1; // smallest Critter, can't eat anything, eaten by medium Critters.
public static final int SIZE_MEDIUM = 2; // medium Critter, can eat small and be eaten by big.
public static final int SIZE_BIG = 8; // biggest Critter, can't be eaten by regular Critters, consumes medium ones.
public static final int SIZE_ALL = 16; // edible by all Critters.
public static final int TNT_COMBO = 4; // value of bomber combos.
public static byte MIN_SPEED_DROP; // min speed at which the Critters fall.
public static byte MAX_SPEED_DROP; // max speed at which the Critters fall.
public static byte SPEED_BLOCKER_DIE; // speed at which the blocker falls down.
public static byte SPEED_CLIMB; // speed at which the Critters climb up the vines.
public static byte SPEED_SPAWN_ASCEND; // speed at which items ascend at spawnpoint.
public static byte SPEED_SPAWN_DROP; // speed at which items descend at spawnpoint.
public static byte SPEED_MIN_JEWEL_DROP; // minimum speed at which jewels drop at the end of the level.
public static byte SPEED_MAX_JEWEL_DROP; // maximum speed at which jewels drop at the end of the level.
//#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Nokia_3220 || Nokia_3220_Unobfuscated || Razr
public static final int TIME_EAT = 5; // pause when eating.
//#else
//# public static final int TIME_EAT = 2; // pause when eating.
//#endif
public static final int TIME_CHEW = 6; // pause when chewing.
public static final int TIME_EXPLODE = 2; // pause when exploding.
public static final int TIME_EAT_TO_CHEW = 2; // time offset that checks whether the Critter should start chewing before the eating animation ends.
public static final int TIME_FALL_DELAY = 1; // delay for the Critters' final fall.
public static final int TIME_MAX_FALL_DELAY = 3; // max offset value for creatures' final fall.
public static final int TIME_POP_DELAY = 3; // delay for a domino effect when exploding.
public static final int TIME_TNT_DETONATE = 5; // time offset between which adjacent Critters to the detonator explode.
public static final int TIME_INITIAL_TOXIC_A = TOTFC.FRAMES_PER_SECOND * 32; // lower limit for toxic timer for toxics just spawning.
public static final int TIME_INITIAL_TOXIC_B = TOTFC.FRAMES_PER_SECOND * 37; // upper limit for toxic timer for toxics just spawning.
public static final int TIME_TOXIC_TIMER_A = TOTFC.FRAMES_PER_SECOND * 24; // lower limit for ticks before a toxic guy explodes.
public static final int TIME_TOXIC_TIMER_B = TOTFC.FRAMES_PER_SECOND * 29; // upper limit for ticks before a toxic guy explodes.
public static final int TIME_TOXIC_FLASH = 24; // tick at which a toxic guy starts flashing, indicating he's about to poison a random adjacent creature.
public static final int TIME_POISON_TIMER = 52; // ticks before a flashing Critter turns into a toxic one.
public static final int TIME_TOXIC_PENALTY = TOTFC.FRAMES_PER_SECOND / 2; // amount of ticks per which the foodbar goes down while holding a toxic Critter.
public static final int TIME_BLOCKER_PUFF = 4; // amount of ticks during which a blocker puffs up.
public static final int TIME_GROUND_DEATH = TOTFC.
FRAMES_PER_SECOND; // amount of time items can rest on the ground before expiring.
public static final int TIME_EFFECT_SHAKE = 10; // amount of time that various shake effects are turned on for.
public static final int TIME_ITEM_SENTENCE = 1; // amount of time to wait when sentencing an item for popping.
public static final int TIME_COIN_DURATION = TOTFC.FRAMES_PER_SECOND *
10; // duration of coin bonus.
public static int TIME_COIN_DIVISOR; // divisor of coin timer.
public static final int TNT_RADIUS = 3; // amount of squares in the vicinity of the exploder that can pop upon detonation.
public static final int COMBO_MULTIPLIER = 12; // points multiplier for combos.
public static final int AMMO_MAX = 9; // max amount of ammo for any item.
public static final int AMMO_MELON = 3; // amount of ammo a watemelon starts with.
public static final int AMMO_PEPPER = 1; // amount of ammo a chili pepper starts with.
public static final int AMMO_ONION = 1; // amount of ammo an onion starts with.
public static final int REGULAR_FULL = 2; // amount of Critters that need to be consumed before a regular Critter pops.
public static final int EXTRA_FULL = Engine.FULL_BYTE; // extra amount of "fullness" for any creature.
public static final int POWERUP_DIVISOR = 3; // divisor for food hunger levels.
public static byte [] S_BOX; // Critter's collision box.
/****************************************************************************
** Variables
***************************************************************************/
public byte m_type; // type of the Critter object, e.g. powerup, icon, Critter.
public byte m_size; // size of the Critter, used for checking who can eat whom.
public byte m_consumed; // amount of Critters this one has eaten.
public short m_special_timer; // special-function timer for things such as toxicity.
/****************************************************************************
** 'tors
***************************************************************************/
// class initializer.
public static void poke() { Thread.yield(); }
// Critter constructor with an id -- will be generated off-screen.
public Critter(int type, int id) { this(type, id, STATE_DEFAULT, Anims.GREEN_IDLE, -Engine.FULL_INT, -Engine.FULL_INT, -Engine.FULL_INT, -Engine.FULL_INT, Engine.FULL_INT, Engine.FULL_INT, 0); }
// Critter constructor with board positions.
public Critter(int type,
int id,
int state,
int anim_state,
int x,
int y,
int destination_x,
int destination_y,
int board_x,
int board_y,
int speed) {
m_type = (byte)type;
m_id = (byte)id;
m_state = state;
setAnim(anim_state);
if(Engine.ANIMS[m_anim_state].length < 1) Engine.printLine("oh, oh: " + toString());
else m_frame = (byte)Engine.getRandom(Engine.ANIMS[m_anim_state].length);
m_x = m_next_x = (short)x;
m_y = m_next_y = (short)y;
if((m_state & STATE_DESCENDING) != 0) m_next_y += m_speed;
if((m_state & STATE_ASCENDING) != 0) m_next_y -= m_speed;
if((m_state & STATE_WESTWARD) != 0) m_next_x -= m_speed;
if((m_state & STATE_EASTWARD) != 0) m_next_x += m_speed;
m_destination_x = (short)destination_x;
m_destination_y = (short)destination_y;
m_board_x = (byte)board_x;
m_board_y = (byte)board_y;
m_speed = (byte)speed;
m_consumed = 0;
m_timer = m_special_timer = 0;
mapSize();
specialInit(id, true);
}
// extra init functionality based on the id of the Critter.
public void specialInit(int id, boolean spawn) {
if(m_type == TYPE_CREATURE) {
if(id == CREATURE_BLOCKER) m_state |= STATE_IMMOBILE;
if((m_state & STATE_TOXIC) != 0) m_special_timer = (short)(spawn ? Engine.getRandom(TIME_INITIAL_TOXIC_A, TIME_INITIAL_TOXIC_B) : Engine.getRandom(TIME_TOXIC_TIMER_A, TIME_TOXIC_TIMER_B));
}
else if(m_type == TYPE_ITEM) { }
}
/****************************************************************************
** Extended Methods
***************************************************************************/
// process the Critter's functionality.
public void process() {
super.process();
Critter c = null;
if((m_state & STATE_FINAL_FALL) != 0) { // == STATE_FINAL_FALL) {
if(m_timer <= 0 && ((m_state & STATE_DESCENDING) == 0)) {
//removeState(STATE_FINAL_FALL);
m_state |= STATE_DESCENDING;
if(Level.s_state == Level.STATE_ACTIVE && !basic()) {
m_speed = (byte)SPEED_BLOCKER_DIE;
}
m_destination_y = Level.GROUND;
}
}
if((m_state & STATE_BEING_EATEN) != 0) {
if(m_y <= m_destination_y) die();
}
if((m_state & STATE_ASCENDING) != 0) {
if(m_y <= m_destination_y) {
m_state &= ~STATE_ASCENDING;
setIdleAnim();
}
if((m_state & STATE_SPAWN_DROP) != 0) {
if(m_speed == 0) {
m_state &= ~STATE_ASCENDING;
m_state |= STATE_DESCENDING;
m_destination_y = Level.GROUND;
}
else {
m_speed--;
}
}
}
if((m_state & STATE_DESCENDING) != 0) {
if( ((m_state & STATE_SPAWN_DROP) != 0) && Level.s_state == Level.STATE_ACTIVE && m_speed < SPEED_SPAWN_DROP) m_speed++;
if(m_y >= m_destination_y) {
m_state &= ~STATE_DESCENDING;
if(Level.s_state == Level.STATE_BOARD_FALL) {
//#ifndef NO_SCREEN_SHAKING
Engine.clearAllShakes();
//#endif
Level.recountCreatures();
Level.s_clock = 0;
Level.s_state = /*(Level.s_type == Level.TYPE_TIMETRIAL) ? (byte)Level.STATE_PRESS_OK :*/ Level.STATE_ACTIVE;
Level.alterBoard(Level.BOARD_IDLE);
}
if((m_state & STATE_SPAWN_DROP) != 0) {
//Level.s_combo = 0;
if(Level.s_state != Level.STATE_ACTIVE || m_id == ITEM_GEM_TOXIC) {
explode();
}
else {
m_state |= STATE_FLASHING;
sentence(TIME_GROUND_DEATH);
}
}
else if((m_state & STATE_FINAL_FALL) != 0) {
sentence();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -