@@ -134,6 +134,9 @@ vec look_dir, lookx, looky;
134
134
float MOVE_SPEED = 0.6f ;
135
135
vec pp , mpp ; // position and inverted(-)position
136
136
uint attack = 0 ; // atacking
137
+ uint swipe = 0 ; // swipe animation
138
+ uint swipe_phase = 0 ;
139
+ float swipe_lt = 0.f ;
137
140
uint focus = 0 ; // focus mode
138
141
uint grounded = 0 ;// is on ground (not flying)
139
142
vec plook ; // 2D look direction (zero Z axis) (not normalised)
@@ -249,6 +252,46 @@ void updateTitle()
249
252
sprintf (tmp , "❤️ %u - 📈 %u - ⚔️ %u/8" , health , xp , weapon );
250
253
glfwSetWindowTitle (window , tmp );
251
254
}
255
+ void doAttack ()
256
+ {
257
+ for (uint i = 0 ; i < MAX_ENEMIES ; i ++ )
258
+ {
259
+ if (enemy_pos [i ].x != 0.f || enemy_pos [i ].y != 0.f || enemy_pos [i ].z != 0.f )
260
+ {
261
+ if (vDistSq (mpp , enemy_pos [i ]) < 0.014f )
262
+ {
263
+ vec n = (vec ){enemy_pos [i ].x , enemy_pos [i ].y , 0.f };
264
+ vSub (& n , n , (vec ){- pp .x , - pp .y , 0.f });
265
+ vNorm (& n );
266
+ vec tl = plook ;
267
+ vNorm (& tl );
268
+ const float angle = (tl .x * n .x ) + (tl .y * n .y );
269
+ //printf("%f\n", angle);
270
+ if (angle > 0.9f ) // looking at the enemy?
271
+ {
272
+ enemy_health [i ] -= 88 * (1 + wield ); // scale damage by wield weapon level
273
+ //printf("%u: %i\n", i, enemy_health[i]);
274
+ if (enemy_health [i ] <= 0 ) // uh-oh dead
275
+ {
276
+ xp += (1 + enemy_type [i ])* (1 + enemy_type [i ]);
277
+ if (xp > 113422 ){weapon = 8 , wield = weapon ;}
278
+ else if (xp > 49314 ){weapon = 7 , wield = weapon ;}
279
+ else if (xp > 21441 ){weapon = 6 , wield = weapon ;}
280
+ else if (xp > 9322 ){weapon = 5 , wield = weapon ;}
281
+ else if (xp > 4053 ){weapon = 4 , wield = weapon ;}
282
+ else if (xp > 1762 ){weapon = 3 , wield = weapon ;}
283
+ else if (xp > 766 ){weapon = 2 , wield = weapon ;}
284
+ else if (xp > 333 ){weapon = 1 , wield = weapon ;}
285
+
286
+ updateTitle ();
287
+ enemy_pos [i ] = (vec ){0.f , 0.f , 0.f };
288
+ }
289
+ break ; // one enemy per swipe
290
+ }
291
+ }
292
+ }
293
+ }
294
+ }
252
295
253
296
//*************************************
254
297
// render functions
@@ -377,6 +420,22 @@ if(health > 0)
377
420
}
378
421
}
379
422
423
+ // auto attack
424
+ if (attack == 1 )
425
+ {
426
+ if (t > swipe_lt )
427
+ {
428
+ if (swipe_phase == 0 )
429
+ {
430
+ doAttack ();
431
+ swipe = 1 ;
432
+ }
433
+ else if (swipe_phase == 1 ){swipe = 0 ;}
434
+ swipe_phase = 1 - swipe_phase ;
435
+ swipe_lt = t + 0.0625f ;
436
+ }
437
+ }
438
+
380
439
// spawn new box
381
440
{
382
441
static float lt = 0.f ;
@@ -482,7 +541,7 @@ if(health > 0)
482
541
esBindModel (2 );
483
542
mIdent (& model );
484
543
mSetPos (& model , (vec ){0.f , -0.3f , 0.f });
485
- if (attack == 1 && vDistSq (mpp , (vec ){0.f , -0.3f , 0.f }) < 0.012f )
544
+ if (swipe == 1 && vDistSq (mpp , (vec ){0.f , -0.3f , 0.f }) < 0.012f )
486
545
{
487
546
vec n = (vec ){0.f , -0.3f , 0.f };
488
547
vSub (& n , n , (vec ){- pp .x , - pp .y , 0.f });
@@ -574,7 +633,7 @@ if(health > 0)
574
633
mRotZ (& model , (((float )(i * m ))* 0.003649635f )* x2PI );
575
634
}
576
635
}
577
- float zscale = (1.f /((float )enemy_health_max [i ]))* ((float )enemy_health [i ]);
636
+ float zscale = (1.f /((float )enemy_health_max [i ]))* ((float )enemy_health [i ]); // could pre-compute the reciprocal but im past caring it's 2023
578
637
// if(zscale < 0.5f)
579
638
// {
580
639
// glEnable(GL_BLEND);
@@ -583,7 +642,7 @@ if(health > 0)
583
642
// }
584
643
// else
585
644
// {
586
- if (zscale < 1.f ){mScale (& model , 1.f , 1.f , zscale );} // could pre-compute the reciprocal but im past caring it's 2023
645
+ if (zscale < 1.f ){mScale (& model , 1.f , 1.f , zscale );}
587
646
// }
588
647
updateModelView ();
589
648
esRenderModel (m );
@@ -600,7 +659,7 @@ if(health > 0)
600
659
{
601
660
if (box_pos [i ].x != 0.f || box_pos [i ].y != 0.f || box_pos [i ].z != 0.f )
602
661
{
603
- if (attack == 1 )
662
+ if (swipe == 1 )
604
663
{
605
664
if (vDistSq (mpp , box_pos [i ]) < 0.014f )
606
665
{
@@ -624,7 +683,7 @@ if(health > 0)
624
683
{
625
684
if (itm_pos [i ].x != 0.f || itm_pos [i ].y != 0.f || itm_pos [i ].z != 0.f )
626
685
{
627
- const uint m = 16 + (i %14 ); // lol yes im that frugal
686
+ const uint m = 16 + (i %14 ); // lol yes im that frugal on memory today
628
687
if (health < 100 && vDistSq (mpp , itm_pos [i ]) < 0.003f )
629
688
{
630
689
if (m == 16 || m == 17 ){health += 1 ;}
@@ -747,7 +806,7 @@ if(health > 0)
747
806
mRotZ (& model , - xrot + PI );
748
807
else
749
808
mRotZ (& model , lr );
750
- if (attack == 1 ){mRotY (& model , -0.420f );}
809
+ if (swipe == 1 ){mRotY (& model , -0.420f );}
751
810
mTranslate (& model , 0.025f , 0.f , 0.05f );
752
811
updateModelView ();
753
812
esRenderModel (wid );
@@ -826,7 +885,7 @@ if(health > 0)
826
885
827
886
// rotate to camera direction with slight offset and set pos
828
887
mRotZ (& model , - (xrot - PI ));
829
- if (attack == 1 ){mRotY (& model , -0.6f ); mRotX (& model , -0.3f );}
888
+ if (swipe == 1 ){mRotY (& model , -0.6f ); mRotX (& model , -0.3f );}
830
889
mSetPos (& model , np );
831
890
832
891
// render it
@@ -840,7 +899,7 @@ if(health > 0)
840
899
841
900
///
842
901
843
- // render meshy
902
+ // render meshy intro
844
903
if (t < 5.f )
845
904
{
846
905
shadeFullbright1 (& position_id , & projection_id , & modelview_id , & color_id , & opacity_id );
@@ -1017,43 +1076,9 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
1017
1076
}
1018
1077
if (button == GLFW_MOUSE_BUTTON_LEFT )
1019
1078
{
1020
- for (uint i = 0 ; i < MAX_ENEMIES ; i ++ )
1021
- {
1022
- if (enemy_pos [i ].x != 0.f || enemy_pos [i ].y != 0.f || enemy_pos [i ].z != 0.f )
1023
- {
1024
- if (vDistSq (mpp , enemy_pos [i ]) < 0.014f )
1025
- {
1026
- vec n = (vec ){enemy_pos [i ].x , enemy_pos [i ].y , 0.f };
1027
- vSub (& n , n , (vec ){- pp .x , - pp .y , 0.f });
1028
- vNorm (& n );
1029
- vec tl = plook ;
1030
- vNorm (& tl );
1031
- const float angle = (tl .x * n .x ) + (tl .y * n .y );
1032
- //printf("%f\n", angle);
1033
- if (angle > 0.9f ) // looking at the enemy?
1034
- {
1035
- enemy_health [i ] -= 88 * (1 + wield ); // scale damage by wield weapon level
1036
- //printf("%u: %i\n", i, enemy_health[i]);
1037
- if (enemy_health [i ] <= 0 ) // uh-oh dead
1038
- {
1039
- xp += (1 + enemy_type [i ])* (1 + enemy_type [i ]);
1040
- if (xp > 113422 ){weapon = 8 , wield = weapon ;}
1041
- else if (xp > 49314 ){weapon = 7 , wield = weapon ;}
1042
- else if (xp > 21441 ){weapon = 6 , wield = weapon ;}
1043
- else if (xp > 9322 ){weapon = 5 , wield = weapon ;}
1044
- else if (xp > 4053 ){weapon = 4 , wield = weapon ;}
1045
- else if (xp > 1762 ){weapon = 3 , wield = weapon ;}
1046
- else if (xp > 766 ){weapon = 2 , wield = weapon ;}
1047
- else if (xp > 333 ){weapon = 1 , wield = weapon ;}
1048
-
1049
- updateTitle ();
1050
- enemy_pos [i ] = (vec ){0.f , 0.f , 0.f };
1051
- }
1052
- break ; // one enemy per swipe
1053
- }
1054
- }
1055
- }
1056
- }
1079
+ swipe = 1 ;
1080
+ swipe_phase = 0 ;
1081
+ swipe_lt = 0.f ;
1057
1082
attack = 1 ;
1058
1083
}
1059
1084
if (button == GLFW_MOUSE_BUTTON_RIGHT )
@@ -1070,6 +1095,9 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
1070
1095
{
1071
1096
if (button == GLFW_MOUSE_BUTTON_LEFT )
1072
1097
{
1098
+ swipe = 0 ;
1099
+ swipe_phase = 0 ;
1100
+ swipe_lt = 0.f ;
1073
1101
attack = 0 ;
1074
1102
}
1075
1103
else if (button == GLFW_MOUSE_BUTTON_RIGHT )
0 commit comments