#pragma once

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

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

    // 縦横の速度、1フレームあたりに動くピクセル数
    int vx;
    int vy;

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

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

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

    void ResetPlay();
    void ResetPlayer();

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

    void MoveHorizontal(int move);
    void MoveVertical(int move);

    Rect PlayerRect() const;

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

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

    // プレイヤーの動きに関係する調整値
    static const int accel = 1;
    static const int maxSpeed = 5;
    static const int friction = 1;
    static const int gravity = 1;
    static const int maxFallSpeed = 16;
    static const int jumpPower = -16;

    Stage stage;
    Player player = {};
    GameState gameState = Playing;
};
