クラスの復習しながら、双六チックなやつを作っていく

1時間目

"theMain.cpp"
#include "DxLib.h"
#include "globals.h"
#include "input.h"
#include "Vector2D.h"
 
//ファイルの中だけで使えるグローバル変数
namespace
{
	const int BGCOLOR[3] = {255, 250, 205}; // 背景色{ 255, 250, 205 }; // 背景色
	int crrTime;
	int prevTime;
	float atTime;//フレーム間時間表示用の変数
	Vector2D a(0, 0);
	Vector2D b(50, 0);
}
 
 
float gDeltaTime = 0.0f; // フレーム間の時間差
 
void DxInit()
{
	ChangeWindowMode(true);
	SetWindowSizeChangeEnableFlag(false, false);
	SetMainWindowText("TITLE");
	SetGraphMode(WIN_WIDTH, WIN_HEIGHT, 32);
	SetWindowSizeExtendRate(1.0);
	SetBackgroundColor(BGCOLOR[0],BGCOLOR[1],BGCOLOR[2]);
 
	// DXライブラリ初期化処理
	if (DxLib_Init() == -1)
	{
		DxLib_End();
	}
 
	SetDrawScreen(DX_SCREEN_BACK);
}
 
void MyGame()
{
	DrawFormatString(100, 100, GetColor(0, 0, 0), "ウィンドウのテスト");
	static int timer = 0;
	timer++;
	DrawFormatString(100, 150, GetColor(0, 0, 0), "%010d", timer);
}
 
//ゲーム内容の初期化
void Initialize()
{
	atTime = 0.0f;
}
 
//ゲーム内容の更新
void Update()
{
	atTime = gDeltaTime; //フレーム間時間
}
 
//ゲーム内容の描画
void Draw()
{
	//atTimeを表示
	DrawFormatString(100, 50, GetColor(0, 0, 0), "%8.3lf", atTime);
 
	DrawFormatString(100, 100, GetColor(20, 255, 20), "a点:(%5.2lf, %5.2lf)", a.x, a.y);
	DrawFormatString(100, 130, GetColor(20, 255, 20), "b点:(%5.2lf, %5.2lf)", b.x, b.y);
	//Vector2D tmpを宣言して a+bのベクトルを表示
	//aとbの距離を表示
 
}
 
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
	DxInit();
	crrTime = GetNowCount();
	prevTime = GetNowCount();
 
	Initialize();
 
	while (true)
	{
		ClearDrawScreen();
		Input::KeyStateUpdate(); // キー入力の状態を更新
 
		crrTime = GetNowCount(); // 現在の時間を取得
		// 前回の時間との差分を計算
		float deltaTime = (crrTime - prevTime) / 1000.0f; // 秒単位に変換
		gDeltaTime = deltaTime; // グローバル変数に保存
 
		//ここにやりたい処理を書く
		Update();
 
		Draw();
 
		ScreenFlip();
		WaitTimer(16);
 
		prevTime = crrTime; // 現在の時間を前回の時間として保存
 
		if (ProcessMessage() == -1)
			break;
		if (CheckHitKey(KEY_INPUT_ESCAPE) == 1)
			break;
	}
 
	DxLib_End();
	return 0;
}

"Vector2D.h"
#pragma once
class Vector2D
{
public:
	float x, y;//メンバ変数
	Vector2D(float _x, float _y);
	Vector2D Add(const Vector2D& _v); // this = this + _v;
	float Distance(const Vector2D& _v); //thisと_vの距離
};

"Vector2D.cpp"
#include "Vector2D.h"
#include <cmath>
 
Vector2D::Vector2D(float _x, float _y)
	:x(_x), y(_y)
{
}
 
Vector2D Vector2D::Add(const Vector2D& _v)
{   //tmp => temporaly 一時的なもの
	Vector2D tmp(x + _v.x, y + _v.y);
	//tmp.x = x + _v.x;
	//tmp.y = y + _v.y;
	return tmp;
}
 
float Vector2D::Distance(const Vector2D& _v)
{
	float dist2 = (_v.x - x)* (_v.x - x) + (_v.y - y)* (_v.y - y);
 
	return sqrt(dist2);
}