El diseño del juego de guerra de aviones digitales basado en Visual Studio

Tabla de contenido

  1. Juego Introducción 1
  2. Flujo de juego 1
  3. diseño de interfaz 2
  4. Esquema de diseño 2
    4.1 Arquitectura del sistema 2
    4.2 Flujo de código central 2
  5. Resumen y perspectivas 3
  6. Referencia 3
    4.2 Flujo del código central
    A continuación se muestra la parte principal de la lógica del juego, donde se encuentra el código central y el flujo de la función Run_Timer.
    Inicio del proceso: llamado por WinProc.
    S0: Actualización de variables globales del temporizador.
    S1: atraviesa todos los aviones enemigos, llama a HitHero para juzgar si choca con nuestro avión (como colisión, marca el avión enemigo).
    S2: atravesar todas las balas y todos los aviones, llamando a Hit para juzgar si golpea (como golpear, marcar balas y aviones).
    S3: recorrer todos los accesorios, llamar a GetToy para juzgar si la máquina los recoge (como recoger, marcar los accesorios, generar efectos de accesorios y establecer las variables globales correspondientes).
    S4: juzgue la puntuación y el nivel actuales, y actualice el nivel si es necesario.
    S5: Juzgue el valor de la variable global del temporizador, si cumple con el requisito de frecuencia, cree un nuevo avión enemigo.
    S6: Atraviesa todos los aviones enemigos y genera desplazamiento.
    S7: Juzga el valor de la variable global del temporizador, si cumple con el requisito de frecuencia, haz que el avión enemigo genere aleatoriamente nuevas balas con cierta probabilidad.
    S8: atravesar todos los aviones enemigos, si salen volando de la pantalla, llama a DestroyPlane para despejarlos.
    S9: atraviesa todas las balas y genera desplazamiento.
    S10: Atraviesa todos los puntales para generar desplazamiento.
    S11: Juzgue el valor de la variable global del temporizador, si cumple con el requisito de frecuencia, haga que mi máquina genere nuevas balas. De acuerdo con la información del artículo registrada en la variable global, se generan diferentes viñetas y se actualiza la variable global del tiempo de enfriamiento del artículo.
    S12: Puntos extra.
    S13: Borrar aviones inválidos. Atravesando todos los aviones enemigos, si se encuentra marcado, llame a DestroyPlane para eliminarlo. Los accesorios se generan cuando se despeja el avión grande, y toyBLD se genera con mayor probabilidad cuando el héroe está casi sin salud.
    S14: Borrar viñetas no válidas. Atraviese todas las viñetas, si encuentra que están marcadas, llame a DestoryBullet para borrarlas.
    S15: Borrar accesorios inválidos. Atraviesa todos los accesorios, si se encuentran marcados, llama a DestoryToy para limpiarlo.
    S16: El cuadro de animación avanza.
    Al final del proceso, el flujo de control se devuelve a WinProc para el dibujo.
#include "DigitPlane.h"

int WINAPI WinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpCmdLine,
	int nCmdShow)
{
	WNDCLASSEX wcex;
	HWND hWnd;
	MSG msg;

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = szWindowClass;
	wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

	if (!RegisterClassEx(&wcex))
	{
		MessageBox(NULL,
			_T("Call to RegisterClassEx failed!"),
			_T("Mega Plane"),
			MB_OK);

		return 1;
	}

	// The parameters to CreateWindow explained:
	// szWindowClass: the name of the application
	// szTitle: the text that appears in the title bar
	// WS_OVERLAPPEDWINDOW: the type of window to create,~WS_THICKFRAME  fixed window size
	// CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
	// WNDWIDTH, WNDHEIGHT: initial size (width, length)
	// NULL: the parent of this window
	// NULL: this application does not have a menu bar
	// hInstance: the first parameter from WinMain
	// NULL: not used in this application
	hWnd = CreateWindow(
		szWindowClass,
		szTitle,
		WS_OVERLAPPEDWINDOW, //& ~WS_THICKFRAME,
		//CW_USEDEFAULT, CW_USEDEFAULT,
		20,20,
		O_WNDWIDTH + WNDWIDTH_PLUS, O_WNDHEIGHT + WNDHEIGHT_PLUS,
		NULL,
		NULL,
		hInstance,
		NULL
		);

	if (!hWnd)
	{
		MessageBox(NULL,
			_T("Call to CreateWindow failed!"),
			_T("Mega Plane"),
			MB_OK);

		return 1;
	}

	// The parameters to ShowWindow explained:
	// hWnd: the value returned from CreateWindow
	// nCmdShow: the fourth parameter from WinMain
	ShowWindow(hWnd,
		nCmdShow);
	UpdateWindow(hWnd);

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return (int)msg.wParam;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	BITMAP bmp;
	POINT ptMouse;
	

	int i;

	switch (message)
	{
	case WM_CREATE:
		

		//加载位图资源
		m_hBackgroundBmp = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
			MAKEINTRESOURCE(IDB_BACKGROUND));
		m_hHeroBmp = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
			MAKEINTRESOURCE(IDB_HERO));
		m_hHeroBulletBmp = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
			MAKEINTRESOURCE(IDB_HERO_BULLET));
		for (i = 0; i < ENEMY_TYPE_NUM; i++)
		{
			m_hEnemyBmp[i] = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
				MAKEINTRESOURCE(m_enemyBmpNames[i]));
		}
		m_hGameStatusBmp = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
			MAKEINTRESOURCE(IDB_GAME_STATUS));
		m_hToysBmp = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
			MAKEINTRESOURCE(IDB_TOYS));

		Initialize_Game();
		
		m_gameStatus.isPaused = FALSE;
		m_gameStatus.isStarting = TRUE;


		{
			//位图相关
			GetObject(m_hGameStatusBmp, sizeof(BITMAP), &bmp);
			m_gameStatus.size.cx = bmp.bmWidth;
			m_gameStatus.size.cy = bmp.bmHeight / 2;
			m_gameStatus.hBmp = m_hGameStatusBmp;
		}

		srand((unsigned int)time(NULL));
		timer_i = 0;
		
		//开始背景音乐
		PlaySound(MAKEINTRESOURCE(IDR_WAVE1),GetModuleHandle(NULL),SND_LOOP|SND_ASYNC|SND_RESOURCE);

		break;
	case WM_SIZE:
		cxClient = LOWORD(lParam);
		cyClient = HIWORD(lParam);
		break;
	case WM_PAINT:
		
		hdc = BeginPaint(hWnd, &ps);
		//绘制
		Render(hdc);
		EndPaint(hWnd, &ps);
		break;
	case WM_KEYUP:
		switch (wParam)
		{
		case VK_LEFT:
		case VK_RIGHT:
		case VK_UP:
		case VK_DOWN:
			MOVE_HERO = 0;
			break;
		}
		break;
	case WM_KEYDOWN:
		switch (wParam)
		{
		case VK_LEFT:
		case VK_RIGHT:
		case VK_UP:
		case VK_DOWN:
			MOVE_HERO = wParam;
			break;

		case VK_SPACE:

			if(m_Planes[0].status == 0)
			{
				//Restart_Game
				Initialize_Game();
				
			}
			else
			{
				if(m_gameStatus.isStarting)
				{
					SetTimer(hWnd, TIMER, 50, NULL);
					m_gameStatus.isStarting = FALSE;
					InvalidateRect(hWnd, NULL, FALSE);
				}
				else 
					Pause_Game(hWnd);
			}
			break;
		case 'B':
			m_Toys[Toy_Count] = CreateToy(toyBLD);
			break;
		case 'D':
			m_Toys[Toy_Count] = CreateToy(toyDBL);
			break;
		case 'C':
			m_Toys[Toy_Count] = CreateToy(toyCLS);
			break;
		case 'R':
			m_Toys[Toy_Count] = CreateToy(toyRAD);
			break;
		case 'S':
			m_Toys[Toy_Count] = CreateToy(toySUB);
			break;
		case 'M'://狂躁模式,各种子弹特效全开
			DBLBullet = TRUE;
			RADBullet = TRUE;
			SUBBullet = TRUE;
			break;
		default:
			break;
		}
		break;
	case WM_LBUTTONDOWN:
		ptMouse.x = LOWORD(lParam);
		ptMouse.y = HIWORD(lParam);

inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí

Supongo que te gusta

Origin blog.csdn.net/sheziqiong/article/details/130872881
Recomendado
Clasificación