#include "PlayerShot.h"
#include "Level.h"
#include "LD.h"



PlayerShot::PlayerShot()
{
  TexSection = LD::TEX_PLAYER_SHOT;
  Type = LD::GO_PLAYER_SHOT;
  Color = 0xffffff00;
  Size = 5;
}



void PlayerShot::Update( Level& theLevel, float ElapsedTime )
{
  LD::Point     tilePos = TilePos();

  if ( ( tilePos.x >= 0 )
  &&   ( tilePos.x < 32 )
  &&   ( tilePos.y >= 0 )
  &&   ( tilePos.y < 24 ) )
  {
    if ( theLevel.Grid[tilePos.x][tilePos.y] > 0 )
    {
      --theLevel.Grid[tilePos.x][tilePos.y];
      RemoveMe = true;

      theLevel.Score += 10;

      if ( theLevel.Grid[tilePos.x][tilePos.y] == 0 )
      {
        // remove grid
        theApp.PlaySoundA( LD::SOUND_WIN_TILE );

        theLevel.CheckCloud( tilePos.x - 1, tilePos.y - 1, tilePos.x, tilePos.y );
        theLevel.CheckCloud( tilePos.x, tilePos.y - 1, tilePos.x + 1, tilePos.y );
        theLevel.CheckCloud( tilePos.x - 1, tilePos.y, tilePos.x, tilePos.y + 1 );
        theLevel.CheckCloud( tilePos.x, tilePos.y, tilePos.x + 1, tilePos.y + 1 );
      }
    }
  }

  FractPos += Speed * ElapsedTime;
  AdjustFractPos();

  Unit::Update( theLevel, ElapsedTime );
}