1. 背景画像を用意
  2. 画像を背景に貼る
  3. キャラ(Box)を準備
  4. キャラを描画
  5. とりあえず一定スピードで動かしてみる(等速直線運動)
Listing. 1: キャラを一定速度で移動
"theMain.cpp"
#include "DxLib.h"
//位置を表す構造体
struct Vec2D
{
	float x;
	float y;
};
 
namespace
{
	const int WIN_WIDTH = 1024;
	const int WIN_HEIGHT = 768;
	int hGroundImage = -1;
	float groundH = 600;
	int BoxW = 64;
	int BoxH = 128;
	Vec2D BoxPos = { 100, groundH - BoxH };
	float speed = 2;
}
 
void DxInit()
{
	ChangeWindowMode(true);
	SetWindowSizeChangeEnableFlag(false, false);
	SetMainWindowText("TITLE");
	SetGraphMode(WIN_WIDTH, WIN_HEIGHT, 32);
	SetWindowSizeExtendRate(1.0);
	SetBackgroundColor(255, 250, 205);
 
	// DXライブラリ初期化処理
	if (DxLib_Init() == -1)
	{
		DxLib_End();
	}
 
	SetDrawScreen(DX_SCREEN_BACK);
}
 
 
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
	DxInit();
 
	hGroundImage = LoadGraph("Image\\bg_dote.jpg");
 
	while (true)
	{
		ClearDrawScreen();
 
		//ここにやりたい処理を書く
		//画像自体を画面の大きさに合わせてもいいよ
		//DrawRotaGraph(WIN_WIDTH /2, WIN_HEIGHT /2, 
		//	          WIN_WIDTH /(float)groundH, 0, hGroundImage, FALSE, FALSE);
		DrawExtendGraph(0, 0, WIN_WIDTH, WIN_HEIGHT + 1, hGroundImage, FALSE);
		DrawLine(0, groundH, WIN_WIDTH, groundH, GetColor(255, 0, 0), 2);
 
		DrawBox(BoxPos.x, BoxPos.y, BoxPos.x + BoxW, BoxPos.y + BoxH, GetColor(0, 255, 0), TRUE);
		BoxPos.x = BoxPos.x + speed;
 
		ScreenFlip();
		WaitTimer(16);
		if (ProcessMessage() == -1)
			break;
		if (CheckHitKey(KEY_INPUT_ESCAPE) == 1)
			break;
	}
 
	DxLib_End();
	return 0;
}
  • game-engineer/classes/2024/game-creation-1/oreno-jump-1.txt
  • 最終更新: 15カ月前
  • by root