11#include " RectangleTypeBullet.h"
22#include " ../../XCFrameInfo.h"
3+ #include " ../XCCollide/CollideInfo.h"
4+ #include " ../XCRender/ParticleHelper.h"
5+ #include " ../XCRender/RenderManager.h"
36#include < GL3/gl3w.h>
47#include < iostream>
5- RectangleTypeBullet::RectangleTypeBullet (std::string bulletImagePath, glm::vec4 dInfo, glm::vec3 sInfo ,glm::vec3 cSize ,glm::vec3 initCoord, float v, float a, float agl, float incA, int rbTime, bool ap)
8+ RectangleTypeBullet::RectangleTypeBullet (std::string bulletImagePath, glm::vec4 dInfo, glm::vec3 sInfo ,glm::vec3 cSize ,glm::vec3 initCoord,
9+ float v, float a, float agl, float incA, int rbTime, bool ap,
10+ int pDensity, float pFinishTime, float pVelocity, float pSize, glm::vec4 pColor)
611{
712 imagePath = bulletImagePath;
813
@@ -19,6 +24,12 @@ RectangleTypeBullet::RectangleTypeBullet(std::string bulletImagePath, glm::vec4
1924 increaseAngle = incA;
2025 reBoundTime = rbTime;
2126 aimToPlayer = ap;
27+ // release part
28+ particleDensity = pDensity;
29+ particleFinishTime = pFinishTime;
30+ particleVelocity = pVelocity;
31+ particleSize = pSize;
32+ particleColor = pColor;
2233
2334 // define current type
2435 setCurrentType (BulletType);
@@ -36,10 +47,9 @@ void RectangleTypeBullet::Render()
3647{
3748 if (isInit) {
3849 timer.Tick ();
39- NowPosition[0 ] += velocity * cos (angle / 180 .0f * 3 .1415926f ) * timer.getDeltaFrame ();
40- NowPosition[1 ] += velocity * sin (angle / 180 .0f * 3 .1415926f ) * timer.getDeltaFrame ();
41- angle += increaseAngle * timer.getDeltaFrame ();
42- velocity += acceleration * timer.getDeltaFrame ();
50+ auto pPlayerHelper1 = CollideInfo::getCollideHelper ();
51+ float * playerPos = (pPlayerHelper1 == nullptr ? nullptr : pPlayerHelper1->getPlayerPosition ());
52+ Bullet::solveBulletMovement (aimToPlayer, playerPos, velocity, angle, acceleration, increaseAngle, timer.getDeltaFrame ());
4353
4454 glEnable (GL_BLEND);
4555 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -63,11 +73,41 @@ void RectangleTypeBullet::Release()
6373 }
6474}
6575
66- bool RectangleTypeBullet::BulletCollideWithPoint (float x, float y, bool & haveGraze)
76+ bool RectangleTypeBullet::BulletCollideWithPoint (float x, float y, bool & haveGraze)
6777{
68- return false ;
78+ bool value = false ;
79+ if (isInit && timer.getAccumlateTime () >= 0 .2f ) {
80+ x -= NowPosition[0 ];
81+ y -= NowPosition[1 ];
82+
83+ float theta = glm::radians (angle);
84+ float NewX = x * cos (theta) + y * sin (theta);
85+ float NewY = -x * sin (theta) + y * cos (theta);
86+
87+ float distance = pow (NewX, 2 ) + pow (NewY, 2 );
88+
89+ if (!haveCheckGraze && distance <= CollideInfo::getGrazeDistance ()) {
90+ haveGraze = true ;
91+ haveCheckGraze = true ;
92+ }
93+ float parameterX = collideSize.x ;
94+ float parameterY = collideSize.y ;
95+ if (NewX >= -parameterX && NewX <= parameterX) {
96+ if (NewY >= -parameterY && NewY <= parameterY) {
97+ value = true ;
98+ }
99+ }
100+
101+ }
102+
103+ return value;
69104}
70105
71106void RectangleTypeBullet::setBulletTerminate ()
72107{
108+ ParticleHelper* particleGroup = new ParticleHelper;
109+ particleGroup->addNewParticle (particleDensity, particleSize, particleVelocity, particleFinishTime, particleColor,
110+ glm::vec3 (NowPosition[0 ], NowPosition[1 ], NowPosition[2 ]));
111+ RenderManager::getInstance ()->AddRenderObject (ParticleGroupUuid, particleGroup);
112+ isWorkFinish = true ;
73113}
0 commit comments