-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuaji_emoji.cpp
153 lines (121 loc) · 3.54 KB
/
huaji_emoji.cpp
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
#include "huaji_emoji.h"
#include "windows.h"
#include "QMouseEvent"
extern QPoint GLOBAL_Point;
extern int GLOBAL_Frame_Rate;
Huaji_emoji::Huaji_emoji(QWidget *parent)
{
//父窗体
father = parent;
//设置起点
pos_x=father->width()/2;
pos_y=father->height()/2;
new_Seed=rand()%5;
new_Seed=new_Seed/3+new_Seed/4+1;
Flag_diry=1;
Flag_dirx=1;
Flag_Create_new=0;
Flag_Delete=0;
Max_Size=100;
}
int Huaji_emoji::my_Rand(int Seed)
{
static int x=2;
int temp1=Seed*x*x+x;
x++;
int temp2=Seed*x*x+x;
if(temp2>4000)
x=0;
return temp2-temp1;
}
int Huaji_emoji::my_Rand_y(int Seed)
{
static int x=10;
int temp1=Seed*x*x+x;
x++;
int temp2=Seed*x*x+x;
if(temp2>40000)
x=0;
return temp2-temp1;
}
void Huaji_emoji::set_start_pos(int pos_x_init,int pos_y_init)
{
pos_x=pos_x_init;
pos_y=pos_y_init;
}
void Huaji_emoji::set_seed(int seed)
{
new_Seed=seed;
}
void Huaji_emoji::update()
{
QPoint p;//定义一个POINT变量,用于存储鼠标的坐标
// POINT p1;
// GetCursorPos(&p1);//获取鼠标位置
// p.setX(p1.x);
// p.setY(p1.y);
p=GLOBAL_Point;
int Half_Size=Max_Size/2;
//static int Flag_in=0;
if((pos_x+Half_Size-p.x())*(pos_x+Half_Size-p.x())+(pos_y+Half_Size-p.y())*(pos_y+Half_Size-p.y())<=((Half_Size+50)*(Half_Size+50)))
{
// if(Flag_in==0&&(pos_x+Half_Size-p.x())*(pos_x+Half_Size-p.x())+(pos_y+Half_Size-p.y())*(pos_y+Half_Size-p.y())>=((Half_Size+2*new_Seed)*(Half_Size+2*new_Seed)))
// {
Flag_dirx=-Flag_dirx;
Flag_diry=-Flag_diry;
// }
// Flag_in=1;
if(abs(pos_x+Half_Size-p.x())<Half_Size+10)
{
new_Seed=new_Seed<4?(new_Seed+1):new_Seed;
}
if(abs(pos_y+Half_Size-p.y())<Half_Size+10)
{
new_Seed=new_Seed<4?(new_Seed+1):new_Seed;
}
pos_x+=Flag_dirx*new_Seed*6;
pos_y+=Flag_diry*new_Seed*6;
if((pos_x+Half_Size-p.x())*(pos_x+Half_Size-p.x())+(pos_y+Half_Size-p.y())*(pos_y+Half_Size-p.y())<(Half_Size*Half_Size/2))
{
if(Delete_count<=0)
{
Flag_Delete=1;
}
else
{
Delete_count--;
}
}
// int temp_x= pos_x+Flag_dirx*(new_Seed*144/(float)GLOBAL_Frame_Rate+(my_Rand(1)%(new_Seed+1)/3));
// int temp_y= pos_y+Flag_diry*(new_Seed*144/(float)GLOBAL_Frame_Rate+(my_Rand_y(2)%(new_Seed+1)/3));
// if((temp_x+Half_Size-p.x())*(temp_x+Half_Size-p.x())+(temp_y+Half_Size-p.y())*(temp_y+Half_Size-p.y())<=((Half_Size+50)*(Half_Size+50)))//如果还没跑出圈 则改变方向以便下一次方向正确
// {
// Flag_dirx=-Flag_dirx;
// Flag_diry=-Flag_diry;
// }
}
// else
// {
// Flag_in=0;
// }
pos_x+=Flag_dirx*(new_Seed*144/(float)GLOBAL_Frame_Rate+(my_Rand(1)%(new_Seed+1)/3));
pos_y+=Flag_diry*(new_Seed*144/(float)GLOBAL_Frame_Rate+(my_Rand_y(2)%(new_Seed+1)/3));
Flag_Create_new=0;//重置新创建允许标志位
if(pos_y<0||pos_y>father->height()-Max_Size-40)
{
Flag_diry=-Flag_diry;
}
if(pos_x<0||pos_x>father->width()-Max_Size)
{
Flag_dirx=-Flag_dirx;
Flag_Create_new=1;
}
if(pos_y>father->height()-Max_Size-40)
pos_y=father->height()-Max_Size-40-1;
if(pos_y<0)
pos_y=1;
if(pos_x>father->width()-Max_Size)
pos_x=father->width()-Max_Size-1;
if(pos_x<0)
pos_x=1;
}