1+ #include " NormalStrike.h"
2+ #include " ../../XCFrameInfo.h"
3+ #include " ../XCRender/RenderManager.h"
4+ #include " ../XCRender/ParticleHelper.h"
5+ #include < GL3/gl3w.h>
6+ XCWavFile NormalStrike::strikeEffect;
7+ bool NormalStrike::isResInit = false ;
8+
9+ NormalStrike::NormalStrike (float x, float y, float z)
10+ {
11+ NowPosition[0 ] = x;
12+ NowPosition[1 ] = y;
13+ NowPosition[2 ] = z;
14+
15+ setCurrentType (AttackType);
16+ }
17+
18+ void NormalStrike::Init ()
19+ {
20+ if (!isInit) {
21+ if (!isResInit) {
22+ strikeEffect = AudioHelper::loadWavFromFile (" assets/SE/se_plst00.wav" );
23+ isResInit = true ;
24+ }
25+
26+ std::thread effectThread (&NormalStrike::threadStrikeHitWork, this );
27+ effectThread.detach ();
28+
29+ renderHelper = new XCImageHelper (" assets/Item/attack.png" , true );
30+
31+ scaleSize[1 ] = 0 .075f ;
32+ scaleSize[0 ] = scaleSize[1 ] / (1 .0f * renderHelper->getImageWidth () / renderHelper->getImageHeight ());
33+ scaleSize[2 ] = 0 .075f ;
34+
35+ isInit = true ;
36+ }
37+ }
38+
39+ void NormalStrike::Render ()
40+ {
41+ if (isInit) {
42+ timer.Tick ();
43+ NowPosition[1 ] += velocity * timer.getDeltaFrame ();
44+ if (isFinish && texIndex < 4 ) {
45+ texIndex += 1 .0f ;
46+ }
47+ glEnable (GL_BLEND);
48+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
49+ renderHelper->Render (glm::vec3 (NowPosition[0 ], NowPosition[1 ], NowPosition[2 ]),
50+ glm::vec4 (1 .0f ), glm::radians (90 .0f ), glm::vec3 (0 , 0 , 1 ), glm::vec3 (scaleSize[0 ], scaleSize[1 ], scaleSize[2 ]),
51+ IRenderHelper::GetSpecificTexWithRate (XCFrameInfo::FrameRight, XCFrameInfo::FrameTop, 4 , 1 , (int )texIndex, 1 ));
52+ glDisable (GL_BLEND);
53+
54+ if (!haveEffectPlay) {
55+ AudioHelper::playFromBuffer (strikeEffect.wavBuffer );
56+ haveEffectPlay = true ;
57+ }
58+
59+ if (NowPosition[1 ]>1 .0f + 0 .025f ) {
60+ isWorkFinish = true ;
61+ }
62+
63+ if (isFinish && timer.getAccumlateTime () - finishTime > 0.06 ) {
64+ isWorkFinish = true ;
65+ }
66+ }
67+ }
68+
69+ void NormalStrike::Release ()
70+ {
71+ if (isInit) {
72+ renderHelper->Release ();
73+ delete renderHelper;
74+
75+ isInit = false ;
76+ }
77+ }
78+
79+ void NormalStrike::checkCollisonWithEnemy (EnemyObject * pEnemy)
80+ {
81+ if (!pEnemy->getIsTerminate () && !isFinish) {
82+ glm::vec3 enemyPosition = pEnemy->getNowPosition ();
83+ float halfWidth = scaleSize[1 ];
84+ float halfHeight = scaleSize[0 ];
85+ float lastY = NowPosition[1 ] - velocity * timer.getDeltaFrame ();
86+ if (enemyPosition[0 ] <= NowPosition[0 ] + halfWidth && enemyPosition[0 ] >= NowPosition[0 ] - halfWidth){
87+ if (enemyPosition[1 ] <= NowPosition[1 ] + halfHeight && enemyPosition[1 ] >= lastY - halfHeight) {
88+ ParticleHelper* particleGroup = new ParticleHelper;
89+ particleGroup->addNewParticle (6 , 20 .0f , 0 .6f , 0 .4f , glm::vec4 (1 .0f ), enemyPosition);
90+ RenderManager::getInstance ()->AddRenderObject (ParticleGroupUuid, particleGroup);
91+
92+ pEnemy->hurtEnemy (0 .2f );
93+ velocity /= 3 .0f ;
94+ finishTime = timer.getAccumlateTime ();
95+ isFinish = true ;
96+ }
97+ }
98+ }
99+ }
100+
101+ void NormalStrike::threadStrikeHitWork ()
102+ {
103+ AudioHelper::playFromBuffer (strikeEffect.wavBuffer );
104+ }
0 commit comments