游戏地图的加载与显示

====================

wid
This commit is contained in:
Mr.Wid 2013-04-05 00:04:10 +08:00
parent dc43627b63
commit a5ec9cf39b
5 changed files with 79 additions and 63 deletions

View File

@ -31,15 +31,13 @@ void InitBeginUI( HDC hdc, HINSTANCE hInst )
#define UNICODE
typedef struct GameMenu
struct GameMenu
{
int id;
TCHAR szName[10];
int xPos;
int yPos;
}GMenu;
GMenu menu[] = {
}menu[] = {
{ 1, TEXT("开始游戏"), 345, 250 },
{ 2, TEXT("查看帮助"), 345, 300 },
{ 3, TEXT("作者博客"), 345, 350 },

View File

@ -1,5 +1,5 @@
#include "Init_Playing_Map.h"
#include <stdio.h>
//////////////////////////////////////////////////////////////////////////
void InitPlayingMap( HWND hwnd, HDC hdc, HINSTANCE hInst )
@ -9,22 +9,13 @@ void InitPlayingMap( HWND hwnd, HDC hdc, HINSTANCE hInst )
//////////////////////////////////////////////////////////////////////////
//画砖块
//画四周砖块
void DrawBrickWall( HWND hwnd, HDC hdc )
{
int x = 0, y = 0;
RECT rect = {0};
HPEN hPen;
HBRUSH hBrush;
hPen = CreatePen( PS_SOLID, 3, RGB(128, 128, 128) );
hBrush = CreateSolidBrush( RGB(192, 192, 192) );
SelectObject( hdc, hPen );
SelectObject( hdc, hBrush );
GetClientRect( hwnd, &rect );
for( x; x < rect.right / 10 + 1; x++ )
@ -38,51 +29,67 @@ void DrawBrickWall( HWND hwnd, HDC hdc )
RoundRect( hdc, 0, y*10, 10, y*10+10, 3, 3 );
RoundRect( hdc, rect.right-10, y*10, rect.right, y*10+10, 3, 3 );
}
DeleteObject( hPen );
DeleteObject( hBrush );
}
//初始化随机墙壁坐标
void InitRandWallPos( HWND hwnd, POINT *pt )
{
RECT rect = {0};
GetClientRect( hwnd, &rect );
srand( (unsigned)time( NULL ) );
pt[0].x = rand() % (rect.right - 60);
pt[0].y = rand() % (rect.bottom - 60);
//////////////////////////////////////////////////////////////////////////
pt[1].x = rand() % (rect.right - 60);
pt[1].y = rand() % (rect.bottom - 60);
}
//画线
void drawWallLine( HDC, int, int, int, int );
//»­Ëæ»úǽ
void DrawRandWall( HWND hwnd, HDC hdc, POINT *pt )
void DrawRandWall( HWND hwnd, HDC hdc, CMAP *gm_map, int lev )
{
int i = 0, xPos = 0, yPos = 0, length = 0;
int i = 0;
RECT rect = {0};
CLINE line = {0};
HPEN hPen;
HBRUSH hBrush;
GetClientRect( hwnd, &rect );
hPen = CreatePen( PS_SOLID, 3, RGB(128, 128, 128) );
hBrush = CreateSolidBrush( RGB(192, 192, 192) );
SelectObject( hdc, hPen );
SelectObject( hdc, hBrush );
//绘制随机墙壁
/*
xPos = pt[0].x; yPos = pt[0].y;
length = (int)sqrt( (pt[1].x - pt[0].x)*(pt[1].x - pt[0].x) + (pt[1].y - pt[0].y)*(pt[1].y - pt[0].y) );
for( i; i < abs(length); i+=10 )
for( i; i < 5; i++ )
{
RoundRect( hdc, xPos, yPos, xPos+10, yPos+10, 3, 3 );
xPos += 10; yPos += 10;
}
*/
line.x1 = gm_map[lev].line[i].x1 * rect.right;
line.y1 = gm_map[lev].line[i].y1 * rect.bottom;
line.x2 = gm_map[lev].line[i].x2 * rect.right;
line.y2 = gm_map[lev].line[i].y2 * rect.bottom;
drawWallLine(
hdc,
(int)(line.x1) + 10 - (int)line.x1 % 10, //将坐标转换为整十数
(int)(line.y1) + 10 - (int)line.y1 % 10,
(int)(line.x2) + 10 - (int)line.x2 % 10,
(int)(line.y2) + 10 - (int)line.y2 % 10
);
}
}
void drawWallLine( HDC hdc, int x1, int y1, int x2, int y2 )
{
int i = 0;
int xPos = 0, yPos = 0;
FILE *fp;
fp = fopen( "D:\\a.txt", "a" );
fprintf( fp, "%d %d %d %d\n", x1, y1, x2, y2 );
fclose( fp );
if( x2-x1 == 0 )
{
yPos = y1;
for( i = 0; i < (y2-y1)/10; i++ )
{
RoundRect( hdc, x1, yPos, x1+10, yPos+10, 3, 3 );
yPos += 10;
}
}
if( y2-y1 == 0 )
{
xPos = x1;
for( i = 0; i < (x2-x1)/10; i++ )
{
RoundRect( hdc, xPos, y1, xPos+10, y1+10, 3, 3 );
xPos += 10;
}
}
DeleteObject( hPen );
DeleteObject( hBrush );
}

View File

@ -6,6 +6,8 @@
#include <math.h>
#include <windows.h>
#include "cu_map.h"
#include "MacroDefine.h"
//////////////////////////////////////////////////////////////////////////
@ -14,9 +16,6 @@ void InitPlayingMap( HWND, HDC, HINSTANCE );
//////////////////////////////////////////////////////////////////////////
void DrawBrickWall( HWND, HDC ); //画砖块
void InitRandWallPos( HWND, POINT* ); //初始化随机墙壁坐标
void DrawRandWall( HWND, HDC, POINT* ); //随机墙壁
void DrawBrickWall( HWND, HDC ); //画四周砖块
void DrawRandWall( HWND, HDC, CMAP*, int ); //随机墙壁

View File

@ -1,4 +1,5 @@
#include "PlayingProc.h"
#include "map_data.h"
//////////////////////////////////////////////////////////////////////////
@ -6,8 +7,8 @@ LRESULT PlayingProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
HDC hdc;
PAINTSTRUCT ps;
POINT ptWall[2] = {0};
HPEN hPen;
HBRUSH hBrush;
switch( message )
{
@ -18,12 +19,13 @@ LRESULT PlayingProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
SetTimer( hwnd, TMR_PLAYING_READY, 1000*60, NULL ); //调整定时器为60秒
PlaySound( MAKEINTRESOURCE( IDR_READY ), (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE ), SND_RESOURCE | SND_ASYNC );
KillTimer( hwnd, TMR_PLAYING_READY );
SetTimer( hwnd, TMR_PLAYING_GO, 2000, NULL ); //启动游戏启动定时器
SetTimer( hwnd, TMR_PLAYING_GO, 1500, NULL ); //启动游戏启动定时器
break;
case TMR_PLAYING_GO:
KillTimer( hwnd, TMR_PLAYING_GO );
PlaySound( MAKEINTRESOURCE( IDR_GO ), (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE ), SND_RESOURCE | SND_ASYNC );
//MessageBox( hwnd, TEXT("游戏开始!"), TEXT("消息"), MB_OK );
//游戏开始
break;
}
@ -31,9 +33,18 @@ LRESULT PlayingProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
case WM_PAINT:
hdc = BeginPaint( hwnd, &ps );
hPen = CreatePen( PS_SOLID, 3, RGB(128, 128, 128) );
hBrush = CreateSolidBrush( RGB(192, 192, 192) );
SelectObject( hdc, hPen );
SelectObject( hdc, hBrush );
InitPlayingMap( hwnd, hdc, (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE ) );
InitRandWallPos( hwnd, ptWall );
DrawRandWall( hwnd, hdc, ptWall );
DrawRandWall( hwnd, hdc, gm_map, 9 );
DeleteObject( hPen );
DeleteObject( hBrush );
EndPaint( hwnd, &ps );
return 0;
@ -43,4 +54,4 @@ LRESULT PlayingProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
}
return DefWindowProc( hwnd, message, wParam, lParam );
}
}

View File

@ -6,6 +6,7 @@
#include "Init_Playing_Map.h"
#include "MacroDefine.h"
#include "cu_map.h"
#include "resource.h"
//////////////////////////////////////////////////////////////////////////