//
//    CHAPTER 24
//    Class Source Name [MoverPonPon.java]
//    Package name      [userClass.App]
//                                    1996.3
//                 Author [ Junzo hagimoto ]

package  userClass.App;

import java.applet.*;
import java.awt.*;
import userClass.App.*;

                                                  
public class   MoverPonPon  extends  Mover {      
    static  int maxSpeed= 60 ;                        
    int     pingpong_y=0;                         
    double  time = 0;                          
    int     start_H = maxSpeed;                   
    boolean drawStart =false;                     
    boolean jump_Status =true ;                   
    int     x_nextJump;                           
                                                  
    //
    //  Moverの表示。
    //
    public void   drawImage(Graphics g){          
       if(drawStart){
            if( hitTimer ==0 ){
                g.drawImage(owner.img[imgCount++/3 + imgSelect ],x,y,owner.a);  
                if(imgCount / 3 == 3      ){                              
                    imgCount = 0;                                          
                }                                                          
             }else{
               g.drawImage(owner.img[(hitTimer/2) % owner.maxImage ],save_x,save_y,owner.a);
            }
        }
    }
    //
    //  Moverの次の表示座標を計算する。
    //
    public void   calcxy(Dimension d,int speed){                               
        int  x1 = x;                                                 
        super.calcxy(d,speed);                                       
        x = x1;                                                      
        if(jump_Status){                                             
            pingpong_y = (int)( start_H * time - 5.0 * time * time) ;
            time+=0.5;                                               
            if( d.height - pingpong_y  <  y &&                       
                d.height - pingpong_y+getImageHeight(0)  > y ){      
                drawStart=true;                                      
            }                                                        
            if(pingpong_y < 0 ){                                     
                pingpong_y= 3;                                       
                time=0.1;                                            
                start_H -= 3;                                        
                if(start_H < 0){                                     
                    jump_Status= false;                              
                    x_nextJump = (int)(Math.random() * 200)+1; 
                }                                                    
            }                                                        
       }else{                                                        
            x += 1 * x_Plus;
            x_nextJump--;                                    
            if( x_nextJump ==0){                                     
                jump_Status = true;                                  
                start_H = maxSpeed;                                        
            }                                                        
       }
       y =  d.height - pingpong_y - getImageHeight(0);
       if( y < 0 && maxSpeed == start_H ){
           maxSpeed--;  // オーバーしないよう調整する。
       }                                                            
    }
}
              //