📄 particles.java
字号:
/****************************************************************************
** Variables
***************************************************************************/
public static byte[] m_type = new byte[MAX_PARTICLES]; // particle type
public static byte[] m_layer = new byte[MAX_PARTICLES]; // rendering layer
public static short[] m_life = new short[MAX_PARTICLES]; // life span
public static short[] m_age = new short[MAX_PARTICLES]; // current age
public static int[] m_fp_x = new int[MAX_PARTICLES]; // x position, fp
public static int[] m_fp_y = new int[MAX_PARTICLES]; // y position, fp
public static int[] m_fp_vx = new int[MAX_PARTICLES]; // x velocity component, fp
public static int[] m_fp_vy = new int[MAX_PARTICLES]; // y velocity component, fp
public static int[] m_fp_fx = new int[MAX_PARTICLES]; // x acceleration component, fp
public static int[] m_fp_fy = new int[MAX_PARTICLES]; // y acceleration component, fp
public static int[] m_p1 = new int[MAX_PARTICLES]; // misc. property 1
public static int[] m_p2 = new int[MAX_PARTICLES]; // misc. property 2
public static int m_clock = 0;
// class initializer.
public static void poke() {}
// remove all particles
public static final void clear() {
for (int i=0; i<MAX_PARTICLES; i++) { remove(i); }
}
// remove a particle
public static final void remove(int id) {
m_type[id] = TYPE_NONE;
}
// return an empty spot. If none found, remove the oldest particle and return that spot.
// HUD layer effects are exempt from early removals
public static final int findFree() {
int oldest = -1;
for (int i=0; i<MAX_PARTICLES; ++i) {
if (m_type[i] < 0) return i;
if (m_layer[i] == LAYER_HUD) continue;
if (oldest == -1) oldest = i;
else if (m_age[i] > m_age[oldest]) oldest = i;
}
if (oldest == -1) oldest = MAX_PARTICLES-1; // bad situation! there is nothing left but HUD layer effects to remove!
remove(oldest);
return oldest;
}
public static final int create(int type, int layer, int life, int x, int y, int vx, int vy, int fx, int fy) {
return create(type, layer, life, x, y, vx, vy, fx, fy, 0, 0);
}
public static final int create(int type, int layer, int life, int x, int y, int vx, int vy, int fx, int fy, int p1, int p2) {
int id = findFree();
m_type[id] = (byte)type;
m_layer[id] = (byte)layer;
m_life[id] = (short)life;
m_age[id] = 0;
m_fp_x[id] = x;
m_fp_y[id] = y;
m_fp_vx[id] = vx;
m_fp_vy[id] = vy;
m_fp_fx[id] = fx;
m_fp_fy[id] = fy;
m_p1[id] = p1;
m_p2[id] = p2;
return id;
}
// create text effects (centered on x,y) on whatever text is current in the string buffer
public static final int textEffect(int type, int layer, int x, int y) {
int dx, dy, vx, vy, width;
int old_x, old_y;
int id = 0;
Engine.s_current_font = EFFECTS_FONT;
int space = EFFECTS_FONT_SPACING;
//#if Nokia_3220 || Nokia_3220_Unobfuscated
//# if (type==TYPE_TEXT_SLIDE_LEFT || type==TYPE_TEXT_SLIDE_RIGHT) {
//# Engine.s_current_font = Engine.CUSTOM_FONT_BIG;
//# space = Engine.CUSTOM_FONT_BIG_H_SPACING;
//# }
//#endif
width = Engine.stringBufferWidth() + space;
x = (x>>FP_SHIFT) - (width>>1);
if (x < 0) x = 0;
if (x > Engine.SCREEN_WIDTH - width) { x = Engine.SCREEN_WIDTH - width; }
switch (type) {
case TYPE_TEXT_BOUNCE:
// clear all other point pop-ups
for (int p=0; p<MAX_PARTICLES; p++) if (m_type[p]==TYPE_BOUNCE_LETTER) m_type[p] = TYPE_NONE;
for (int p=0; p<Engine.m_stringBufferLength; p++) {
id = create(TYPE_BOUNCE_LETTER, layer, TEXT_LIFE, (x<<FP_SHIFT), y, 0, TEXT_BOUNCE_Y_SPEED_FP,
0, TEXT_BOUNCE_Y_FORCE_FP, (int)Engine.m_stringBuffer[p], y);
m_age[id] -= p;
m_life[id] -= p;
x+=Engine.CustomFontCharWidth(Engine.m_stringBuffer[p]) + space;
}
break;
case TYPE_TEXT_STRETCH:
old_x = (x + width/2)<<FP_SHIFT;
for (int p=0; p<Engine.m_stringBufferLength; p++) {
id = create(TYPE_STRETCH_LETTER, layer, TEXT_LIFE-(TEXT_LIFE>>2), old_x, y, ((x<<FP_SHIFT)-old_x)>>1, 0, 0, 0, (int)Engine.m_stringBuffer[p], x<<FP_SHIFT);
x+=Engine.CustomFontCharWidth(Engine.m_stringBuffer[p]) + space;
}
break;
case TYPE_TEXT_SHAKE:
case TYPE_TEXT_DROP:
for (int p=0; p<Engine.m_stringBufferLength; p++) {
id = create(TYPE_SHAKE_LETTER, layer, TEXT_LIFE, x<<FP_SHIFT, y, 0, 0, 0, 0, (int)Engine.m_stringBuffer[p], 0);
x+=Engine.CustomFontCharWidth(Engine.m_stringBuffer[p]) + space;
if (type == TYPE_TEXT_DROP) m_age[id] = (short)(m_life[id]>>1);
}
break;
case TYPE_TEXT_SLIDE_LEFT:
case TYPE_TEXT_SLIDE_RIGHT:
for (int p=0; p<Engine.m_stringBufferLength; p++) {
id = create((type==TYPE_TEXT_SLIDE_LEFT)?TYPE_SLIDE_LEFT_LETTER:TYPE_SLIDE_RIGHT_LETTER, layer, TEXT_LIFE*2,
((type==TYPE_TEXT_SLIDE_LEFT)?(x+Engine.SCREEN_WIDTH+p):(x-Engine.SCREEN_WIDTH-p))<<FP_SHIFT, y,
((type==TYPE_TEXT_SLIDE_LEFT)?-32:32)<<FP_SHIFT, 0, 0, 0, (int)Engine.m_stringBuffer[p], x<<FP_SHIFT);
x+=Engine.CustomFontCharWidth(Engine.m_stringBuffer[p]) + space;
}
break;
case TYPE_TEXT_SPIN:
old_x = x + width/2;
for (int p=0; p<Engine.m_stringBufferLength; p++) {
id = create(TYPE_SPIN_LETTER, layer, TEXT_LIFE, x<<FP_SHIFT, y, 0, 0, 0, 0, (int)Engine.m_stringBuffer[p], x-old_x);
x+=Engine.CustomFontCharWidth(Engine.m_stringBuffer[p]) + space;
}
break;
case TYPE_TEXT_GATHER:
// clear all other gather pop-ups
for (int p=0; p<MAX_PARTICLES; p++) if (m_type[p]==TYPE_GATHER_LETTER) m_type[p] = TYPE_NONE;
for (int p=0; p<Engine.m_stringBufferLength; p++) {;
id = create(TYPE_GATHER_LETTER, layer, TEXT_LIFE, x<<FP_SHIFT, y, 0, 0, 0, 0, (int)Engine.m_stringBuffer[p], Engine.getRandom(360));
x+=Engine.CustomFontCharWidth(Engine.m_stringBuffer[p]) + space;
}
break;
}
return id;
}
// create composite effects
public static final int create(int type, int layer, int x, int y) {
return create(type, layer, x, y, 0);
}
public static final int create(int type, int layer, int x, int y, int sub_type) {
int dx, dy, vx, vy, offset, size, density, timer;
int rgb1 = 0; int rgb2 = 0;
int id = 0;
int p;
int color0 = getCreatureColor(sub_type, 0);
int color1 = getCreatureColor(sub_type, 1);
int color2 = getCreatureColor(sub_type, 2);
switch (type) {
case TYPE_CREATURE_POP:
for (p=0; p<GOO_DENSITY; ++p) {
rgb1 = (p%2==0) ? color0 : color1;
rgb2 = (p%2==0) ? color1 : color2;
vx = getRandomFP(GOO_X_SPEED_FP);
vy = getRandomFP(GOO_Y_SPEED_FP) -(1<<FP_SHIFT);
id = create( (p<(GOO_DENSITY>>1))?TYPE_GOO_SPIN:TYPE_GOO, layer, Engine.getRandom(GOO_LIFE_MIN,GOO_LIFE_MAX), x+vx, y+vy, vx, vy, 0,(1<<FP_SHIFT)>>1, rgb1, rgb2);
if (p<3) m_age[id] = (short)-p;
if (p==1) {
id = create(TYPE_CROSS, layer, CROSS_LIFE, x, y, 0,0,0,0,rgb1,rgb2);
m_age[id] = -1;
//#ifndef PARTICLES_LOW
id = create(TYPE_RING, layer, RING_BIG_LIFE, x, y, RING_SPEED_FP, RING_SPEED_FP, 0, 0, rgb1, rgb2);
//#endif
}
}
//#ifndef PARTICLES_LOW
// create some stars
for (p=0; p<STAR_DENSITY; ++p) {
vx = getRandomFP(STAR_SPEED_FP);
vy = getRandomFP(STAR_SPEED_FP);
id = create(TYPE_STAR, layer, Engine.getRandom(STAR_LIFE_MIN,STAR_LIFE_MAX), x+2*vx, y+2*vy, vx, vy, 0, (1<<FP_SHIFT)>>2);
m_age[id] -= p;
}
//#endif
//#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Razr
if (Engine.getRandom(3)==0) Particles.create(Particles.TYPE_FALLING_LEAF, Particles.LAYER_FOREGROUND, x, y, Level.s_vines_rgb);
//#endif
break;
case TYPE_CREATURE_PUFF:
for (p=0; p<PUFF_DENSITY; ++p) {
rgb1 = (p%2==0) ? color0 : color1;
rgb2 = (p%2==0) ? color1 : color2;
vx = getRandomFP(PUFF_SPEED_FP);
vy = getRandomFP(PUFF_SPEED_FP);
//#ifndef PARTICLES_LOW
id = create(TYPE_PUFF_UNIT, layer, Engine.getRandom(PUFF_LIFE_MIN,PUFF_LIFE_MAX), x+2*vx, y+2*vy, vx, vy, -vx>>2, PUFF_Y_FORCE_FP, rgb1, rgb2);
id = create(TYPE_GOO_SPIN, layer, Engine.getRandom(PUFF_LIFE_MIN,PUFF_LIFE_MAX), x+2*vx, y+2*vy, 2*vx, 2*vy, -vx>>2, PUFF_Y_FORCE_FP, rgb1, rgb2);
//#else
//# id = create(TYPE_GOO_SPIN, layer, Engine.getRandom(PUFF_LIFE_MIN,PUFF_LIFE_MAX), x+vx, y+vy, 2*vx, 2*vy, -vx>>2, PUFF_Y_FORCE_FP, rgb1, rgb2);
//#endif
}
id = create(TYPE_CROSS, layer, CROSS_LIFE, x, y, 0,0,0,0,color1,color2);
m_age[id] = -1;
//#ifndef PARTICLES_LOW
id = create(TYPE_RING, layer, RING_BIG_LIFE, x, y, RING_SPEED_FP, RING_SPEED_FP, 0, 0, rgb1, rgb2);
//#endif
//#ifndef PARTICLES_LOW
// create some stars
for (p=0; p<STAR_DENSITY; ++p) {
vx = getRandomFP(STAR_SPEED_FP);
vy = getRandomFP(STAR_SPEED_FP);
id = create(TYPE_STAR, layer, Engine.getRandom(STAR_LIFE_MIN,STAR_LIFE_MAX), x+2*vx, y+2*vy, vx, vy, 0, (1<<FP_SHIFT)>>2);
m_age[id] -= p;
}
//#endif
//#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Razr
if (Engine.getRandom(3)==0) Particles.create(Particles.TYPE_FALLING_LEAF, Particles.LAYER_FOREGROUND, x, y, Level.s_vines_rgb);
//#endif
break;
case TYPE_TOXIC_SPLAT:
for (p=0; p<TOXIC_DENSITY; ++p) {
vx = getRandomFP(TOXIC_GOO_X_SPEED_FP);
vy = -Engine.getRandom(TOXIC_GOO_Y_SPEED_FP);
rgb1 = (p<TOXIC_DENSITY/3) ? getCreatureColor(Critter.CREATURE_TOXIC, 0) : getCreatureColor(Critter.CREATURE_TOXIC, 1);
rgb2 = (p<TOXIC_DENSITY/3) ? getCreatureColor(Critter.CREATURE_TOXIC, 1) : getCreatureColor(Critter.CREATURE_TOXIC, 2);
id = create((p<(TOXIC_DENSITY>>1))?TYPE_GOO_SPIN:TYPE_GOO, layer, Engine.getRandom(GOO_LIFE_MIN,GOO_LIFE_MAX), x+vx, y+vy, vx, vy, 0, (2<<FP_SHIFT), rgb1, rgb2);
}
//#ifndef PARTICLES_LOW
id = create(TYPE_RING, layer, RING_BIG_LIFE, x, y, RING_SPEED_FP, RING_SPEED_FP, 0, 0, rgb1, rgb2);
//#endif
break;
case TYPE_TNT_POP:
//#ifndef PARTICLES_LOW
for (p=0; p<TNT_PUFF_DENSITY; ++p) {
vx = getRandomFP(PUFF_SPEED_FP);
vy = getRandomFP(PUFF_SPEED_FP);
id = create(TYPE_PUFF_UNIT, layer, Engine.getRandom(PUFF_LIFE_MIN,PUFF_LIFE_MAX), x+2*vx, y+2*vy, vx, vy, -vx>>2, PUFF_Y_FORCE_FP, TNT_PUFF_RGB_1, TNT_PUFF_RGB_2);
id = create(TYPE_GOO_SPIN, layer, Engine.getRandom(PUFF_LIFE_MIN,PUFF_LIFE_MAX), x+2*vx, y+2*vy, 2*vx, 2*vy, -vx>>2, PUFF_Y_FORCE_FP, TNT_PUFF_RGB_1, TNT_PUFF_RGB_2);
}
//#endif
for (p=0; p<TNT_DENSITY; ++p) {
dx = getRandomFP(TNT_SPREAD_X_FP);
dy = getRandomFP(TNT_SPREAD_Y_FP);
id = create(TYPE_TNT_UNIT, layer, TNT_LIFE, x+(dx>>1), y+(dy>>1), 0, 0, 0, 0);
m_p1[id] = (dx>>FP_SHIFT);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -