コード例 #1
0
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd) {

	xxd.SetScreenResolution(ScreenWidth, ScreenHeight);

	WNDCLASSEX pencere;
	ZeroMemory(&pencere, sizeof(WNDCLASSEX));

	pencere.cbClsExtra = NULL;
	pencere.cbSize = sizeof(WNDCLASSEX);
	pencere.cbWndExtra = NULL;
	pencere.hCursor = LoadCursor(NULL, IDC_ARROW);
	pencere.hIcon = NULL;
	pencere.hIconSm = NULL;
	pencere.hInstance = hInst;
	pencere.lpfnWndProc = (WNDPROC)WinProc;
	pencere.lpszClassName = "Pencere";
	pencere.lpszMenuName = NULL;
	pencere.style = CS_HREDRAW | CS_VREDRAW;

	RegisterClassEx(&pencere);

	ID2D1Factory* directx = NULL;
	D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,&directx);

	HWND hWnd = NULL;
	hWnd = CreateWindowEx(NULL, "Pencere", "Direct2D",WS_POPUP | WS_EX_TOPMOST, 0, 0, ScreenWidth, ScreenHeight, NULL, NULL, hInst, NULL);
	
	ShowWindow(hWnd, nShowCmd);

	/*D2D1Rect*/

	RECT rect;
	GetClientRect(hWnd, &rect);

	ID2D1HwndRenderTarget* RenderTarget = NULL;
	directx->CreateHwndRenderTarget(
		D2D1::RenderTargetProperties(),
		D2D1::HwndRenderTargetProperties(hWnd,D2D1::SizeU(rect.right - rect.left, rect.bottom - rect.top)),
		&RenderTarget);

	/*D2D1Rect*/
	/* D2D1Brush */

	/*ID2D1SolidColorBrush* Brush = NULL;
	RenderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &Brush);*/

	/* D2D1Brush */

	MSG msg;
	ZeroMemory(&msg, sizeof(MSG));

	/*D2D1_ELLIPSE ellipse = D2D1::Ellipse(
		D2D1::Point2F(100.f, 100.f),
		50.f,
		50.f
	);*/

	/*POINT pts;
	pts.x = (ScreenWidth/2) - 25;
	float gravity = 1.0f;
	float y = 20;
	int alo = 0;
	pts.y = (ScreenHeight/2) - 80;*/

	ID2D1Bitmap* Bitmap = NULL;
	IWICImagingFactory* ImagingFactory = NULL;
	CoInitializeEx(NULL, COINIT_MULTITHREADED);
	CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&ImagingFactory);
	/*lb.LoadBitmapFromFile(RenderTarget, ImagingFactory, L"Oyuncu/Dokular/Aylak/ön.png", &Bitmap);
	D2D1_SIZE_F size = Bitmap->GetSize();
	D2D1_POINT_2F upperLeftCorner;*/

	btn.InitFactory(ImagingFactory);
	btn.InitTarget(RenderTarget);
	btn.setPos(100, 100);
	btn.getImages();
	btn.InitText(L"Buton Bura Oglim");

	Bush trn;
	trn.InitGadgets(RenderTarget,ImagingFactory);
	trn.InitImage();
	trn.CalcThat();
	trn.InitThat();

	Player plyr;
	plyr.InitFactories(ImagingFactory,RenderTarget);
	plyr.InitIdleImages();
	plyr.InitMoveImages();

	DWORD baslangic_noktasi;
	float deltaTime, oldTime = 0;
	while (TRUE){
		baslangic_noktasi = GetTickCount();
		deltaTime = baslangic_noktasi - oldTime;
		oldTime = baslangic_noktasi;

		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
			if (msg.message == WM_QUIT) {
				break;
			}

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		//KEY
		if (TUS(VK_SPACE)) {
			//alo = 1;
		}
		if (TUS(VK_LEFT)) {
			tp.x += 2;
			//pts.x -= 2;
		}
		if (TUS(VK_RIGHT)) {
			tp.x -= 2;
			//pts.x += 2;
		}
		if (TUS(VK_UP)) {
			tp.y += 2;
			//pts.y -= 2;
		}
		if (TUS(VK_DOWN)) {
			tp.y -= 2;
			//pts.y += 2;
		}

		plyr.HandleKeysForIdle();
		plyr.HandleKeysForMove(deltaTime);

		/*if (alo == 1) {
			y -= gravity;
			pts.y -= y;
			if (y == -19) {
				alo = 0;
				y = 20.f;
			}
		}*/

		/*if (clps.x != 0 && clps.y!= 0) {
			text.setPos(clps.x, clps.y);
		}*/
		/*upperLeftCorner = D2D1::Point2F(pts.x, pts.y);*/

		//text.setFont(L"Comic Sans MS");
		//LOOP
		RenderTarget->BeginDraw();
		RenderTarget->Clear(D2D1::ColorF(0.25f,0.80f,0.22f,1.f));

		/*Terrain*/
		trn.drawBush();
		/*Terrain*/
		
		//RenderTarget->DrawRectangle(D2D1::RectF(100,100,200,300), Brush);
		//RenderTarget->DrawEllipse(ellipse, Brush, 2.f);
		RenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(0 + tp.x,0 + tp.y));
		/*RenderTarget->DrawBitmap(
			Bitmap,
			D2D1::RectF(
				upperLeftCorner.x,
				upperLeftCorner.y,
				upperLeftCorner.x + 50,
				upperLeftCorner.y + 160),
				1.0,
				D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR
			);*/
		//text.drawatext(50,L"Merhaba",RenderTarget,Brush);

		plyr.Render();

		btn.RenderIt(cups, clk, tp);

		RenderTarget->EndDraw();
		/*if (TUS(VK_ESCAPE)) {
			break;
			PostMessage(hWnd, WM_DESTROY, 0, 0);
		}*/
		//
	}

	directx->Release();
	RenderTarget->Release();
	/*Brush->Release();*/
	Bitmap->Release();
	ImagingFactory->Release();
	xxd.RestoreScreenResolution();
	return 0;
}
コード例 #2
0
void MWinDeviceImpl::SetOrigin(
	int32		inX,
	int32		inY)
{
	mRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(inX, inY));
}