#----------------------------------------------------------
#Function for the event procedure
#----------------------------------------------------------
use mpfc;
sub update_ep {
  my ($object) = @_;
  $num = $#invader_list_x +1;
  if ($num == 0){
    mpfc::WSCbase_setProperty($newvtim_001,"running",False);
    mpfc::WSCbase_setProperty(mpfc::WSGIappMessageDialog(),"labelString",
                              "당신이 이겼습니다.");
    mpfc::WSCbase_setVisible(mpfc::WSGIappMessageDialog(),$mpfc::True);
  }
  $key = mpfc::WSDkeyboard_getKey(mpfc::WSGIappKeyboard());
  if ( mpfc::WSDkeyboard_isPressed(mpfc::WSGIappKeyboard()) != False){
    if ($key == $mpfc::WSK_Right){
      $my_base_x+=5;
      if ($my_base_x > 380){
        $my_base_x = 380;
      }
    }elsif ($key == $mpfc::WSK_Left){
      $my_base_x-=5;
      if ($my_base_x < 0){
        $my_base_x = 0;
      }
    }elsif ($key == $mpfc::WSK_space){
      push(@my_missile_list_x, $my_base_x+5);
      push(@my_missile_list_y, $my_base_y);
      mpfc::WSDkeyboard_setKey(mpfc::WSGIappKeyboard(),0);
    }
  }
  $num = $#invader_missile_list_x +1;
  for($i=0; $i < $num; $i++){
    $mpt_x = $invader_missile_list_x[$i];
    $mpt_y = $invader_missile_list_y[$i];
    if ($my_base_x < $mpt_x && $mpt_x < $my_base_x + 10 &&
        $my_base_y < $mpt_y && $mpt_y < $my_base_y + 10){
      mpfc::WSCbase_setProperty($newvtim_001,"running",False);
      mpfc::WSCbase_setProperty( mpfc::WSGIappMessageDialog(),
                                 "labelString","당신이 쳤습니다.");
      mpfc::WSCbase_setVisible( mpfc::WSGIappMessageDialog(),$mpfc::True);
      break;
    }

    $fnum = $#fence_list_x+1;
    for($j=0; $j < $fnum; $j++){
      $fpt_x = $fence_list_x[$j];
      $fpt_y = $fence_list_y[$j];
      if ($fpt_x < $mpt_x && $mpt_x < $fpt_x + 5 &&
          $fpt_y < $mpt_y && $mpt_y < $fpt_y + 5){
        splice(@fence_list_x,$j,1);
        splice(@fence_list_y,$j,1);
        splice(@invader_missile_list_x,$i,1);
        splice(@invader_missile_list_y,$i,1);
        $num--;
        $i--;
        break;
      }
    }
  }
  $num = $#my_missile_list_x +1;
  for($i=0; $i < $num; $i++){
    $mpt_x = $my_missile_list_x[$i];
    $mpt_y = $my_missile_list_y[$i];
    $fnum = $#fence_list_x +1;
    for($j=0; $j < $fnum; $j++){
      $fpt_x = $fence_list_x[$j];
      $fpt_y = $fence_list_y[$j];
      if ($fpt_x < $mpt_x && $mpt_x < $fpt_x + 5 &&
          $fpt_y < $mpt_y && $mpt_y < $fpt_y + 5){
        splice(@fence_list_x,$j,1);
        splice(@fence_list_y,$j,1);
        splice(@my_missile_list_x,$i,1);
        splice(@my_missile_list_y,$i,1);
        $num--;
        $i--;
        break;
      }
    }
    $fnum = $#invader_list_x +1;
    for($j=0; $j < $fnum; $j++){
      $fpt_x = $invader_list_x[$j];
      $fpt_y = $invader_list_y[$j];
      if ($fpt_x < $mpt_x && $mpt_x < $fpt_x + 10 &&
          $fpt_y < $mpt_y && $mpt_y < $fpt_y + 10){
        splice(@invader_list_x,$j,1);
        splice(@invader_list_y,$j,1);
        splice(@my_missile_list_x,$i,1);
        splice(@my_missile_list_y,$i,1);
        $num--;
        $i--;
        $val = mpfc::WSCbase_getProperty($newvlab_001,"labelString");
        $score = mpfc::WSCvariant_getLong($val);
        mpfc::WSCbase_setProperty($newvlab_001,"labelString",int($score + 10));
        break;
      }
    }
  }
  mpfc::WSCbase_redraw($newvdra_001);
}
1;
