﻿#pragma once

#include "Common.h"
#include "ImageManager.h"
#include "Stage.h"

// プレイヤーの状態を表す構造体
struct Player
{
    // 位置と大きさは、左上を基準にした矩形で扱う
    int x;
    int y;
    int width;
    int height;

    // 縦横の速度と、1ピクセル未満の移動量
    float vx;
    float vy;
    float remainderX;
    float remainderY;

    // 接地しているかどうかのフラグ true の時のみジャンプ可能
    bool onGround;
};

// ゲーム全体を管理するクラス
class Game
{
public:
    bool Initialize();
    void MainLoop();

private:
    // ゲームの状態を表す列挙型
    enum GameState
    {
        Playing,
        GameClear,
        GameOver
    };

    void StartPlay();
    void ResetPlay();
    void ResetPlayer();

    void Update();
    void UpdatePlaying();
    void UpdateResult();
    void UpdatePlayerInput();
    void UpdatePlayerPhysics();
    void UpdateCamera();
    void UpdateDebugToggle();

    void MoveHorizontal(float move);
    void MoveVertical(float move);

    Rect PlayerRect() const;
    Rect PlayerImageRect() const;

    void Draw();
    void DrawBackground() const;
    void DrawPlaying() const;
    void DrawResult() const;
    void DrawPlayer() const;
    void DrawHud() const;
    void DrawDebug() const;

private:
    // 画面サイズ
    static const int screenWidth = 640;
    static const int screenHeight = 480;

    // プレイヤーの動きに関係する調整値
    static constexpr float accel = 0.35f;
    static constexpr float maxSpeed = 4.5f;
    static constexpr float friction = 0.25f;
    static constexpr float gravity = 0.55f;
    static constexpr float maxFallSpeed = 12.0f;

    // 画像の原寸にかかわらず、画面へ表示する大きさを固定する
    static const int playerDrawWidth = 32;
    static const int playerDrawHeight = 48;
    static constexpr float jumpPower = -11.0f;

    ImageManager images;
    Stage stage;
    Player player = {};
    int cameraX = 0;
    GameState gameState = Playing;
    bool debugVisible = false;
    bool previousF1 = false;
};
