﻿#include "Shooting/ImageManager.h"
#include "Shooting/Tuning/GameTuning.h"

#include "Shooting/PlayerShot.h"

namespace dxgame::shooting
{
    void PlayerShot::Spawn(const Vector2& startPosition)
    {
        position = startPosition;
        isActive = true;
    }

    void PlayerShot::Update(float deltaTime)
    {
        if (!isActive)
            return;

        position.y -= tuning::playerShot::Speed * deltaTime;

        // DrawRect全体が画面の上へ出た弾を再利用できる状態に戻す
        Rect drawRect = GetDrawRect();
        if (drawRect.y + drawRect.height < 0.0f)
           Deactivate();
    }

    void PlayerShot::Draw(const ImageManager& images) const
    {
        if (!isActive)
            return;

        Rect drawRect = GetDrawRect();
        images.Draw(ImageManager::Id::PlayerShot, drawRect);
    }

    bool PlayerShot::IsActive() const
    {
        return isActive;
    }

    void PlayerShot::Deactivate()
    {
        isActive = false;
    }

    Rect PlayerShot::GetDrawRect() const
    {
        return tuning::playerShot::DrawRect.MovedBy(position);
    }

}
