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

📄 particles.java

📁 Critter_Crunch_J2ME 游戏源
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                  if (m_fp_x[i] <= (Engine.BOARD_MARGIN_LEFT<<FP_SHIFT)) {
                     m_fp_vx[i] = 0; 
                     m_fp_x[i] = (Engine.BOARD_MARGIN_LEFT<<FP_SHIFT);
                  }
                  else create(TYPE_FIRE_LEFT_UNIT, LAYER_FOREGROUND, FIRE_UNIT_LIFE, m_fp_x[i], m_fp_y[i], 0, 0, 0, 0, i, 0);    // remember the id of it's emitter
                  
                  break;
               case EMITTER_FIRE_RIGHT:
                  if (m_fp_x[i] >= ((Engine.SCREEN_WIDTH - Engine.BOARD_MARGIN_RIGHT)<<FP_SHIFT)) {
                     m_fp_vx[i] = 0;
                     m_fp_x[i] = ((Engine.SCREEN_WIDTH - Engine.BOARD_MARGIN_RIGHT)<<FP_SHIFT);
                  }
                  else create(TYPE_FIRE_RIGHT_UNIT, LAYER_FOREGROUND, FIRE_UNIT_LIFE, m_fp_x[i], m_fp_y[i], 0, 0, 0, 0, i, 0);   // remember the id of it's emitter
                  break;
            }
         }
         
         
         
         switch (m_type[i]) {
            case TYPE_SPARKLE:
               // bounce when they hit the floor?
               if ((m_fp_y[i]>>FP_SHIFT) > Engine.SCREEN_HEIGHT - 10 - (i%5)) {
                  m_fp_y[i] = (Engine.SCREEN_HEIGHT - 10 - (i%5))<<FP_SHIFT;
                  m_fp_vy[i] = -m_fp_vy[i]>>1;
               }
               break;
         //#ifndef PARTICLES_LOW      
            case TYPE_RING:
               // undo movement
               m_fp_x[i] -= m_fp_vx[i];
               m_fp_y[i] -= m_fp_vy[i];
               break;
         //#endif
               
            case TYPE_DEATH_CRITTER:
               // if m_p2 == 0 then this is a creature jumping at biggs
               
               if (m_p2[i]==0 && m_fp_y[i]>>FP_SHIFT > Engine.SCREEN_HEIGHT - 10 - (i%5)) {
                  m_age[i] = 0;
                  m_fp_vy[i] *= -1;
               }
               
               if (Engine.collide(Level.s_player.getBox(), m_fp_x[i]>>FP_SHIFT, m_fp_y[i]>>FP_SHIFT, (m_fp_x[i]>>FP_SHIFT)+1, (m_fp_y[i]>>FP_SHIFT)+1)) {
                  Level.s_player.m_state &= ~(Avatar.STATE_SCARED);
                  Level.s_player.m_state |= Entity.STATE_DYING;
                  if (m_p2[i]==0) remove(i);
               }
               
            case TYPE_CLOUD_SMALL:
            case TYPE_CLOUD_LARGE:
               if (m_fp_x[i]>>FP_SHIFT > Engine.SCREEN_WIDTH + 20) {
                  m_fp_x[i] = (-20-Engine.getRandom(20))<<FP_SHIFT;
                  m_fp_y[i] = Engine.getRandom(Engine.SCREEN_HALF_HEIGHT)<<FP_SHIFT;
                  m_age[i] = 0;
               }
               break;
               
            default:
               if (m_layer[i]==LAYER_HUD) break;
               if ((m_fp_y[i]>>FP_SHIFT) > Engine.SCREEN_HEIGHT - 10 - (i%5)) {
                  m_fp_y[i] = (Engine.SCREEN_HEIGHT - 10 - (i%5))<<FP_SHIFT;
                  m_fp_vy[i] = 0;
                  m_fp_vx[i] = m_fp_vx[i]>>1;
               }
               break;
         }
         
         
         // age the particle
         m_age[i]++;
      }
      
      m_clock++;
   }
   
   
   
   // render all particles within the specified layer
   public static final void render(Graphics g, int layer) {
      
      // Keep the entire screen clipped so don't have to keep clipping for all primitive draws.
      // If clips have to be done for image draws, just reclip the screen again right after.
      Engine.clipScreen(g);
      
      int x,y,vx,vy,fx,fy;
      
      // variables reused for calculations
      int dr,dg,db;
      int width, height, offset, length, angle, segments, radius, density, rgb;
      int x1, y1, x2, y2;
      int image = -1;
      int p;
      
      for (int i=0; i<MAX_PARTICLES; i++) {
         
         if (m_type[i] == TYPE_NONE) continue;
         if (m_layer[i] != layer) continue;     // only render the particles in this layer
         if (m_age[i] < 0) continue;            // don't render particles that aren't born yet
         
         x = (m_fp_x[i])>>FP_SHIFT;
         y = (m_fp_y[i])>>FP_SHIFT;
         vx = (m_fp_vx[i])>>FP_SHIFT;
         vy = (m_fp_vy[i])>>FP_SHIFT;
         fx = (m_fp_fx[i])>>FP_SHIFT;
         fy = (m_fp_fy[i])>>FP_SHIFT;
         
         // render the particle
         switch (m_type[i]) {
            
            case TYPE_BOUNCE_LETTER:
               // m_p1 used for letter
               // m_p2 used for y coord of bounce
               if (m_fp_y[i] > m_p2[i]) { 
                  m_fp_y[i] = m_p2[i];
                  m_fp_vy[i] = -(m_fp_vy[i]*3)>>2;
               }
               y = (m_fp_y[i]>>FP_SHIFT);
               Engine.s_current_font = EFFECTS_FONT;
               //#if PARTICLES_MID || PARTICLES_LOW
//#                if (m_age[i]<4) Engine.setFontColor(blendRGB(g, BOUNCE_LETTER_RGB_1, BOUNCE_LETTER_RGB_3, m_age[i], 4));
//#                else if (m_age[i]==10) Engine.setFontColor(SPARKLE_RGB_2);
//#                else Engine.setFontColor(BOUNCE_LETTER_RGB_3);
               //#else
               if (m_age[i]<4) Engine.setFontColor(blendRGB(g, BOUNCE_LETTER_RGB_1, BOUNCE_LETTER_RGB_3, m_age[i], 4), blendRGB(g, BOUNCE_LETTER_RGB_1, BOUNCE_LETTER_RGB_2, m_age[i], 4));
               else if (m_age[i]==10) Engine.setFontColor(SPARKLE_RGB_2);
               else Engine.setFontColor(BOUNCE_LETTER_RGB_3, BOUNCE_LETTER_RGB_2);
               //#endif
               
               Engine.CustomFontDrawChar(g, (char)m_p1[i], x, y);
               Engine.clipScreen(g);
               break;
               
            case TYPE_STRETCH_LETTER:
               // m_p1 used for letter
               // m_p2 used for x coord of destination
               if (m_fp_x[i] > m_p2[i] || m_fp_x[i] < m_p2[i]) {
                  m_fp_vx[i] = (m_p2[i] - m_fp_x[i]) + ((m_p2[i] - m_fp_x[i])>>1);
               }
               if (m_fp_vx[i] < (2<<FP_SHIFT) && m_fp_vx[i] > (-2<<FP_SHIFT)) {
                  m_fp_vx[i] = 0;
                  m_fp_x[i] = m_p2[i];
               }
               
               Engine.s_current_font = EFFECTS_FONT;
               //#if PARTICLES_MID || PARTICLES_LOW
//#                Engine.setFontColor(STRETCH_LETTER_RGB_3);
               //#else
               Engine.setFontColor(STRETCH_LETTER_RGB_1, STRETCH_LETTER_RGB_2);
               //#endif
               
               Engine.CustomFontDrawChar(g, (char)m_p1[i], x, y);
               Engine.clipScreen(g);
               break;
               
            case TYPE_SHAKE_LETTER:
               offset = ((m_life[i]>>1) - m_age[i] > 0) ? (m_life[i]>>1) - m_age[i] : 0;
               x1 = (offset > 0) ? Engine.getRandom(offset)-(offset>>1) : 0;
               y1 = (offset > 0) ? Engine.getRandom(offset)-(offset>>1) : 0;
               x += x1;
               y += y1;
               
               if (offset==0) m_fp_fy[i] = 2<<FP_SHIFT;
               
               Engine.s_current_font = EFFECTS_FONT;
               //#ifndef PARTICLES_LOW
               Engine.setFontColor(SHAKE_LETTER_RGB_1, SHAKE_LETTER_RGB_2);
               //#endif
               
               Engine.CustomFontDrawChar(g, (char)m_p1[i], x, y);
               Engine.clipScreen(g);
               break;
               
            case TYPE_SLIDE_LEFT_LETTER:
            case TYPE_SLIDE_RIGHT_LETTER:
               // m_p1 used for letter
               // m_p2 used for x coord of destination
               
               if (m_type[i] == TYPE_SLIDE_LEFT_LETTER) {
                  if (m_age[i] > (m_life[i]>>1)) m_fp_fx[i] = -8<<FP_SHIFT;
                  else if (m_fp_x[i] < m_p2[i] + (10<<FP_SHIFT)) m_fp_vx[i] = (m_p2[i] - m_fp_x[i])>>1;
                  
               } else {
                  if (m_age[i] > (m_life[i]>>1)) m_fp_fx[i] = 8<<FP_SHIFT;
                  else if (m_fp_x[i] > m_p2[i] - (10<<FP_SHIFT)) m_fp_vx[i] = (m_p2[i] - m_fp_x[i])>>1;
               }
               
               Engine.s_current_font = EFFECTS_FONT;
               //#if PARTICLES_MID || PARTICLES_LOW
//#                Engine.setFontColor(SLIDE_LETTER_RGB_3);
               //#else
               Engine.setFontColor(SLIDE_LETTER_RGB_1, SLIDE_LETTER_RGB_2);
               //#endif
               
               //#if Nokia_3220 || Nokia_3220_Unobfuscated
//#                // special case use the big letters for this particular effect in mid end
//#                Engine.s_current_font = Engine.CUSTOM_FONT_BIG;
//#                Engine.setFontColor(SLIDE_LETTER_RGB_1, SLIDE_LETTER_RGB_2);
               //#endif
               
               Engine.CustomFontDrawChar(g, (char)m_p1[i], x, y);
               Engine.clipScreen(g);
               break;
               
            case TYPE_SPIN_LETTER:
               // m_p1 used for letter
               // m_p2 used for distance from center of effect
               if (m_age[i]<=TEXT_SPIN_TIME) angle = 360 - (360*m_age[i])/TEXT_SPIN_TIME;
               else angle = 0;
               
               angle = angle*angle/360;   // make parabolic!
               angle += 90;
               
               Engine.s_current_font = EFFECTS_FONT;
               //#if PARTICLES_MID || PARTICLES_LOW
//#                Engine.setFontColor(SPIN_LETTER_RGB_2);
               //#else
               Engine.setFontColor(SPIN_LETTER_RGB_1, SPIN_LETTER_RGB_2);
               //#endif
               
               x += -m_p2[i] + ((m_p2[i]*Engine.sin(angle))>>FP_SHIFT);
               y += (m_p2[i]*Engine.cos(angle))>>FP_SHIFT;
               Engine.CustomFontDrawChar(g, (char)m_p1[i], x, y);
               Engine.clipScreen(g);
               break;
               
            case TYPE_GATHER_LETTER:
               if (m_age[i]<0) break;
               
               x1 = (Level.RIGHT_X<<FP_SHIFT) - m_fp_x[i];
               y1 = (Level.BOTTOM_Y<<FP_SHIFT) - m_fp_y[i];

               x1 = x1/((m_age[i]*m_age[i])+1);
               y1 = y1/((m_age[i]*m_age[i])+1);

               x = (m_fp_x[i] + x1)>>FP_SHIFT;
               y = (m_fp_y[i] + y1)>>FP_SHIFT;
               
               Engine.s_current_font = EFFECTS_FONT;
               //#if PARTICLES_MID || PARTICLES_LOW
//#                Engine.setFontColor(BOUNCE_LETTER_RGB_3);
               //#else
               Engine.setFontColor(BOUNCE_LETTER_RGB_3, BOUNCE_LETTER_RGB_2);
               //#endif
               
               
               Engine.CustomFontDrawChar(g, (char)m_p1[i], x, y);
               Engine.clipScreen(g);
               break;
               
               
            case TYPE_TRAIL:
               //#ifndef PARTICLES_LOW
               // m_pl used for colour
               g.setColor(m_p1[i]);
               fillSquare(g,x,y,2); //g.fillRect(x, y, 2, 2);
               g.drawLine(x,y,x-vx,y-vy);
               //#endif
               break;
               
            case TYPE_CURVE_TRAIL:
               //#ifndef PARTICLES_LOW
               // m_p1 used for colour, m_p2 is how many segments to make up the curve
               g.setColor(m_p1[i]);
               fillSquare(g,x,y,2); //g.fillRect(x, y, 2, 2);
               g.drawLine(x,y,x-vx,y-vy);
               
               for(p=0; p<m_p2[i]; p++) {
                  x-=vx; y-=vy; vx-=fx; vy-=fy;
                  g.drawLine(x,y,x-vx,y-vy);
               }
               //#endif
               break;
            
            case TYPE_GOO_SPIN:
            case TYPE_GOO:
               if (m_type[i]==TYPE_GOO_SPIN) {  // spirally goo bits

⌨️ 快捷键说明

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