void ChargeShot::update(){
    
    if(status == s_charge){
        
        if(chargingFlag){
            if(chargeEnergy <= energyMax){
                chargeEnergy+=2;
                chargeLevel = chargeEnergy/20;
                radius      = chargeEnergy;
            }
        } else {
            status  = s_shot;
            vy      = -8;
        }
        
        chargingFlag = false;
    }
    if(status == s_shot){
        y += vy;
        
        if(y < 0){
            status  = s_ready;
            initShot();
        }
    }
    
}
void ChargeShot::shot(float x, float y){
    chargingFlag    = true;
    if(status == s_ready){
        startCharge();
    } else if(status == s_charge){
        this->x = x;
        this->y = y;
    } else if(status == s_shot){
        status == s_charge;
        initShot();
        startCharge();
    }
}
Beispiel #3
0
void stepSimulation(void)
{
   if(conf.debug & 1) printf("stepSimulation: %s:%d currentPlayer=%d currentPlayer.energy=%.4f currentPlayer.velocity=%.4f\n",__FILE__,__LINE__,currentPlayer,player[currentPlayer].energy, player[currentPlayer].velocity);
   if(  (  player[currentPlayer].active
        && (
             player[currentPlayer].shot[player[currentPlayer].currentShot].missile.live == 0
             && (conf.mode & GM_MULTIMISSILE) == 0
           )
        && (
            ( player[currentPlayer].didShoot && (conf.mode & GM_MULTIMISSILE) == 0)
            || (
	         player[currentPlayer].energy < player[currentPlayer].velocity
	         && (conf.mode & GM_ENERGY) != 0
               )
	   )
     )
     || player[currentPlayer].timeout == 0 
     || player[currentPlayer].watch 
     )
   {
      if(
	  player[currentPlayer].timeout == 0 
          && !player[currentPlayer].watch
        ) player[currentPlayer].timeoutcnt++;
      if(conf.debug & 1) printf("stepSimulation: %s:%d call nextPlayer\n",__FILE__,__LINE__);
      nextPlayer();
   }

   if(player[currentPlayer].active
      && player[currentPlayer].valid
      && !player[currentPlayer].didShoot
      && (player[currentPlayer].energy >= player[currentPlayer].velocity || (conf.mode & GM_ENERGY) == 0)
     )
   {
      player[currentPlayer].currentShot = (player[currentPlayer].currentShot + 1) % conf.numShots;
      initShot(currentPlayer);
      player[currentPlayer].valid = 0;
      if((conf.mode & GM_ENERGY) == 0) {
        player[currentPlayer].velocity = 10.0;
        player[currentPlayer].oldVelocity = 10.0;
      }
      player[currentPlayer].didShoot = 1;
   }
   simulate();
   killflash *= 0.95;
}
void ChargeShot::checkCollisionEnemy(AbstEnemy *enemy){
    if(status == s_shot && enemy->isHitable()){
        float diffX, diffY, sumRadius;

            diffX = x - enemy->getX();
            diffY = y - enemy->getY();
            sumRadius = radius/2 + enemy->getW()/2;
            
            // ヒットした時の処理
            if(pow(sumRadius, 2) > pow(diffX, 2) + pow(diffY, 2)){

                int enemyHitPoint = enemy->reactShotHit(chargeLevel);
                if(enemyHitPoint >= 0){
                    initShot();
                } else {
                    // オーバーキルならマイナスになっている敵の体力分減らす
                    chargeLevel = -enemyHitPoint;
                }
            }

    }
}
ChargeShot::ChargeShot(){
    init();
    initShot();
}