当前位置:网站首页>QT based "synthetic watermelon" game
QT based "synthetic watermelon" game
2022-06-26 20:59:00 【biyezuopinvip】
Resource download address :https://download.csdn.net/download/sheziqiong/85788271
Resource download address :https://download.csdn.net/download/sheziqiong/85788271
Main process
Overall process
Realize the idea : By opening Mainscene Interface , Define fruits fruit, Implement various operations .

Algorithm or formula
The core algorithm : Two dimensional collision
principle : Because two balls collide , The velocities on the tangent are parallel to each other , There is no force and the connecting lines collide with each other ( As shown in the figure below ), There will be forces , So we just need to find the ball 1 And the ball 2 The velocity in the direction of the centreline of . Then, according to the law of conservation of momentum and the law of conservation of mechanical energy, we can find the ball after collision 1 And the ball 2 The direction of the connecting center line of . Finally, by adding their respective velocities on the tangent to each other, we can get their respective velocities after collision x Speed ,y Speed .

and v1t : It's the ball 1 The projection speed in the direction of the connecting center line and the tangent line
- and v2t : It's the ball 2 The projection speed in the direction of the connecting center line and the tangent line
The ball 1 The direction of the speed , be equal to v1n + v1t
The ball 2 The direction of the speed , be equal to v2n + v2t
distance = Math.sqrt(Math.pow((ball1.pointX - ball2.pointX),2) + Math.pow((ball1.pointY - ball2.pointY),2));
radius = ball1.r + ball2.r;
dx = ball1.pointX - ball2.pointX
dy = ball1.pointY - ball2.pointY
ex = dx / radius;
ey = dy / radius; // Get the unit vector of the centerline (ex,ey)
= ex * ball1.vx + ey * ball1.vy
= ex * ball2.vx + ey * ball2.vy

’ : The ball 1 The direction of velocity after the collision , be equal to v1n’ + v1t
’ : The ball 2 The direction of velocity after the collision , be equal to v2n’ + v2t
‘ and v2n’ :
Projection velocity of two small balls after collision
If the two balls are the same size , v1n’ and v2n’ The value is :
’ = v2n
’ = v1n
And according to the law of conservation of momentum and the law of conservation of mechanical energy :

and v2 : Speed before two balls hit .
and m2 : The mass of the two balls
' and v2' :
The speed of the two balls after they hit each other
double ux=-dy/distance,uy=dx/distance;// Tangential unit vector (ux,uy), Direction is (ex,ey) Counter clockwise rotation π/2
// The velocity projection of the ball in the direction of the line between the two balls is v=(vx,vy)·(ex,ey)
double v1=ex*balls[i].vx+ey*balls[i].vy;//i Normal velocity of
double v2=ex*balls[j].vx+ey*balls[j].vy;//j Normal velocity of
if (v2<v1) continue;// Two balls passed by , No collision
// The velocity projection of the ball in the tangent direction is v'=(vx,vy)·(ux,uy)
double v11=ux*balls[i].vx+uy*balls[i].vy;//i Tangential velocity of
double v22=ux*balls[j].vx+uy*balls[j].vy;//j Tangential velocity of
// According to the conservation of momentum and kinetic energy theorem, the velocity in the direction of the connecting line between the two balls after collision is calculated u1 and u2, among K Indicates the degree of kinetic energy loss
double m1=balls[i].mass,m2=balls[j].mass;
double u1=K*((m1-m2)*v1+2*m2*v2)/(m1+m2);//i Normal velocity after collision
double u2=K*((m2-m1)*v2+2*m1*v1)/(m1+m2);//j Normal velocity after collision
velocity vector (vx,vy)=(u1ex+v11ux,u1ey+v11uy)·(i,j)
balls[i].vx=1*(u1*ex+v11*ux);
balls[i].vy=1*(u1*ey+v11*uy);
balls[j].vx=1*(u2*ex+v22*ux);
balls[j].vy=1*(u2*ey+v22*uy);
Synthesis algorithm
combine(int i, int j)
{
Ball b;
initball(balls[i].type+1);
double vi=sqrt(balls[i].vx*balls[i].vx+balls[i].vy*balls[i].vy);
double vj=sqrt(balls[j].vx*balls[j].vx+balls[j].vy*balls[j].vy);
if (vi<vj)// The position of the composite is the ball with lower speed
{
=b._x=balls[i].x;
=b._y=balls[i].y;
}
else {
=b._x=balls[j].x;
=b._y=balls[j].y;
}
vx=(balls[i].vx+balls[j].vx)/2.0;
vy=(balls[i].vy+balls[j].vy)/2.0;
ay=1;
falling=1;
balls[i]=b; // Replace the new ball with balls[i]
collideWall(i);
balls[j]=balls[balls.size()-1];
balls.pop_back(); // from balls Delete in array balls[j]
gamescore+=2*balls[i].type;
str.sprintf("score:%d",gamescore);
q->setText(str);
}
Harvest
unit testing

( Start interface )

( Game pause )

( The game is in progress )
Resource download address :https://download.csdn.net/download/sheziqiong/85788271
Resource download address :https://download.csdn.net/download/sheziqiong/85788271
边栏推荐
- Super VRT
- Detailed explanation of shutter textfield
- 分布式ID生成系统
- GameFi 活跃用户、交易量、融资额、新项目持续性下滑,Axie、StepN 能摆脱死亡螺旋吗?链游路在何方?
- Three basic backup methods of mongodb
- Leetcode question brushing: String 06 (implement strstr())
- Developer survey: rust/postgresql is the most popular, and PHP salary is low
- Comment installer la base de données MySQL 8.0 sous Windows? (tutoriel graphique)
- Dynamic parameter association using postman
- 好物推薦:移動端開發安全工具
猜你喜欢

leetcode刷题:字符串02( 反转字符串II)

与 MySQL 建立连接

慕课8、服务容错-Sentinel
![[serialization] how to master the core technology of opengauss database? Secret 5: master database security (6)](/img/a8/622cddae2ac8c383979ed51d36bca9.jpg)
[serialization] how to master the core technology of opengauss database? Secret 5: master database security (6)
![[Shandong University] information sharing for the first and second examinations of postgraduate entrance examination](/img/f9/68b5b5ce21f4f851439fa061b477c9.jpg)
[Shandong University] information sharing for the first and second examinations of postgraduate entrance examination

郭明錤:苹果 AR / MR 头显是其有史以来设计最复杂的产品,将于 2023 年 1 月发布

Super VRT

GEE:计算image区域内像素最大最小值

Development of NFT for digital collection platform

Leetcode question brushing: String 05 (Sword finger offer 58 - ii. left rotation string)
随机推荐
Separate save file for debug symbols after strip
Mr. Sun's version of JDBC (21:34:25, June 12, 2022)
论数据库的传统与未来之争之溯源溯本----AWS系列专栏
Feitian +cipu body brings more imagination to the metauniverse
The relationship between the development of cloud computing technology and chip processor
[most detailed] latest and complete redis interview (42 tracks)
第2章 构建自定义语料库
Three basic backup methods of mongodb
西瓜书重温(七): 贝叶斯分类器(手推+代码demo)
Good thing recommendation: mobile terminal development security tool
飞天+CIPU体为元宇宙带来更大想象空间
Leetcode question brushing: String 05 (Sword finger offer 58 - ii. left rotation string)
Détails de l'annotation des ressources sentinelles
Redis + Guava 本地缓存 API 组合,性能炸裂!
Arduino uno + DS1302 uses 31 byte static RAM to store data and print through serial port
Is there any risk in opening a mobile stock registration account? Is it safe?
Establish a connection with MySQL
记录一次Redis大Key的排查
【protobuf 】protobuf 升级后带来的一些坑
0 basic C language (2)