-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
185 lines (177 loc) · 4.08 KB
/
main.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#pragma once
#include "hge.h"
/*
using namespace std;
DWORD WINAPI ThreadProc(LPVOID);
LPCTSTR EVENT_NAME = _T("TEST");
*/
struct BWpic
{
bool **bools;
int number;
int width;
int height;
};
static void getRange(int *arr, int size, int *max, int *min)
{
int *p = arr, *endp = arr + size;
if (size % 2 != 0)
{
*max = *min = *p++;
}
else
{
if (*p > *(p + 1))
{
*max = *p;
*min = *(p + 1);
}
else
{
*max = *(p + 1);
*min = *p;
}
p += 2;
}
while (p != endp)
{
if (*p > *(p + 1))
{
if (*p > *max) *max = *p;
if (*(p + 1) < *min) *min = *(p + 1);
}
else
{
if (*(p + 1) > *max) *max = *(p + 1);
if (*(p) < *min) *min = *p;
}
p += 2;
}
};
static bool Collision(Point *mPoint, const int count, const float angle5, float center_x, float center_y, float px, float py)
{
int count_point =count;
Point cmpoint[10];
memcpy(cmpoint, mPoint, count_point * sizeof(Point));
for (int i = 0; i < count_point; i++)
{
float xx1 = cmpoint[i].x, yy1 = cmpoint[i].y;
if (angle5>-4.71 || angle5 < -7.85) yy1 = -yy1;
cmpoint[i].x = cos(angle5)*xx1 - sin(angle5)*yy1 + center_x;
cmpoint[i].y = cos(angle5)*yy1 + sin(angle5)*xx1 + center_y;
}
/*
HGE *hge = hgeCreate(HGE_VERSION);
hge->Gfx_BeginScene();
for (int i = 0; i < count_point; i++)
{
if (i != count_point - 1)
hge->Gfx_RenderLine(cmpoint[i].x, cmpoint[i].y, cmpoint[i + 1].x, cmpoint[i + 1].y, ARGB(255, 255, 0, 0));
else
hge->Gfx_RenderLine(cmpoint[i].x, cmpoint[i].y, cmpoint[0].x, cmpoint[0].y,ARGB(255, 255, 0, 0));
}
hge->Gfx_EndScene();
*/
for (int i = 0; i < count_point; i++)
{
if (i != count_point - 1)
{
float k = 0;
if (cmpoint[i].x - cmpoint[i + 1].x != 0) k = (cmpoint[i].y - cmpoint[i + 1].y) / (cmpoint[i].x - cmpoint[i + 1].x);
else k = 10000000;
int bcs[10], maxs, mins;
float dx = py - px*k;
for (int j = 0; j < count_point; j++)
bcs[j] = cmpoint[j].y - cmpoint[j].x*k;
getRange(bcs, count_point, &maxs, &mins);
if (dx>maxs || dx < mins) return false;
}
else
{
float k = 0;
if (cmpoint[i].x - cmpoint[0].x != 0) k = (cmpoint[i].y - cmpoint[0].y) / (cmpoint[i].x - cmpoint[0].x);
else k = 10000000;
int bcs[10], maxs, mins;
float dx = py - px*k;
for (int j = 0; j < count_point; j++)
bcs[j] = cmpoint[j].y - cmpoint[j].x*k;
getRange(bcs, count_point, &maxs, &mins);
if (maxs > dx && dx > mins) return true;
else return false;
}
}
}
static bool CollisionBW(BWpic bools,float Targetx, float Targety, double angle, float myselfx, float myselfy,float size)
{
if (bools.bools != nullptr)
{
double angle1 = -angle;
//HGE *hge = hgeCreate(HGE_VERSION);
//HWND hwnd=hge->System_GetState(HGE_HWND);
//HDC dc = GetDC(hwnd);
//for (int i = 0; i < bools.width;i++)
//for (int j = 0; j < bools.height;j++)
//if (bools.bools[i][j])SetPixel(dc, i, j, RGB(0, 0, 0));
//else
// SetPixel(dc, i, j, RGB(255, 255, 255));
int fx, fy;
int x = (Targetx - myselfx);// +bools.width / 2;
int y = (Targety - myselfy);// +bools.height / 2;
fx = x*cos(angle1) - y*sin(angle1);
fy = y*cos(angle1) + x*sin(angle1);
fx /= size;
fy /= size;
fx += (bools.width / 2);
fy += (bools.height / 2);
//SetPixel(dc, fx, fy, RGB(50, 50, 50));
if (fx<0 || fy<0 || fx>bools.width-1 || fy>bools.height-1)
return false;
else
return bools.bools[fx][fy];
}
else
return false;
}
static bool ballcrash(float center_x, float center_y, int r, float px, float py)
{
int d1 = px - center_x;
int d2 = py - center_y;
if (r*r < d1*d1 + d2*d2)return false;
else return true;
}
/*
DWORD WINAPI ThreadProc(LPVOID)
{
HANDLE hEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, EVENT_NAME);
::WaitForSingleObject(hEvent, INFINITE);
::CloseHandle(hEvent);
return 0L;
}
*/
static void AddUntil(int &stage, int &charge, int max,bool &finish)
{
if (charge < max)
{
charge++;
}
else
{
charge = 0;
finish = true;
}
}
static void random(int a[], int n)
{
int index, tmp, i;
srand(time(NULL));
for (i = 0; i <n; i++)
{
index = rand() % (n - i) + i;
if (index != i)
{
tmp = a[i];
a[i] = a[index];
a[index] = tmp;
}
}
}