-
Notifications
You must be signed in to change notification settings - Fork 65
/
Init_Playing_Map.c
126 lines (100 loc) · 2.76 KB
/
Init_Playing_Map.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "Init_Playing_Map.h"
#include <stdio.h>
//////////////////////////////////////////////////////////////////////////
void InitPlayingMap( HWND hwnd, HDC hdc, POINT ptFood, CMAP *gm_map, int level )
{
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 );
DrawBrickWall( hwnd, hdc );
DrawRandWall( hwnd, hdc, gm_map, level );
DrawRandomFood( hdc, ptFood );
DeleteObject( hPen );
DeleteObject( hBrush );
}
//////////////////////////////////////////////////////////////////////////
//画四周砖块
void DrawBrickWall( HWND hwnd, HDC hdc )
{
int x = 0, y = 0;
RECT rect = {0};
GetClientRect( hwnd, &rect );
for( x; x < rect.right / 10 + 1; x++ )
{
RoundRect( hdc, x*10, 0, x*10+10, 10, 3, 3 );
RoundRect( hdc, x*10, rect.bottom-10, x*10+10, rect.bottom, 3, 3 );
}
for( y; y < rect.bottom / 10 + 1; y++ )
{
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 );
}
}
//////////////////////////////////////////////////////////////////////////
//画线
void drawWallLine( HDC, int, int, int, int );
//画随机墙
void DrawRandWall( HWND hwnd, HDC hdc, CMAP *gm_map, int lev )
{
int i = 0;
RECT rect = {0};
CLINE line = {0};
GetClientRect( hwnd, &rect );
for( i; i < 5; i++ )
{
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;
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;
}
}
}
//////////////////////////////////////////////////////////////////////////
//绘制食物
void DrawRandomFood( HDC hdc, POINT ptFood )
{
HPEN hPen;
HBRUSH hBrush;
hPen = GetStockObject( WHITE_PEN );
hBrush = CreateSolidBrush( RGB(255, 0, 0) );
SelectObject( hdc, hPen );
SelectObject( hdc, hBrush );
Ellipse( hdc, ptFood.x, ptFood.y, ptFood.x+10, ptFood.y+10 );
DeleteObject( hPen );
DeleteObject( hBrush );
}
//////////////////////////////////////////////////////////////////////////