#include "boss.h" #include "bullet.h" #include #include #include #include #include "fast_trig.h" #include #include "collections.h" extern bopti_image_t img_Lifebar; extern bopti_image_t img_Boss1; #define NB_PIECES_BOSS 12 libnum::num XdataBossInternal[NB_PIECES_BOSS]; libnum::num YdataBossInternal[NB_PIECES_BOSS]; libnum::num XdataBossExternal[NB_PIECES_BOSS]; libnum::num YdataBossExternal[NB_PIECES_BOSS]; BossPart Pieces[NB_PIECES_BOSS*2]; #include void savedata( void ) { FILE* exportfp = fopen("databosPtxt", "w" ); if(exportfp) { fprintf(exportfp, "Points : \n" ); for( int i=0; i 0; if ((P3x - P1x) * as_y - (P3y - P1y) * as_x > 0 == s_ab) return false; if ((P3x - P2x) * (Py - P2y) - (P3y - P2y)*(Px - P2x) > 0 != s_ab) return false; return true; } Boss::Boss( int16_t _x, int16_t _y, uint8_t _id ) { x = libnum::num(_x); y = libnum::num(_y); ID = _id; speed = 10; toberemoved = false; width = img_Boss1.width/2; height = img_Boss1.height/2; xmin = (int) x - width; xmax = (int) x + width; ymin = (int) y - height; ymax = (int) y + height; if (ID==0) { life = 1000; life0 = 1000; } lastshoot0 = rtc_ticks(); lastshoot1 = rtc_ticks(); lastshoot2 = rtc_ticks(); radiusInt = libnum::num( 75 ); radiusExt = libnum::num( 100 ); rotAngle = 0.0f; rotSpeed = 2; this->Update(0.0f); for( int i=0; i360.0f) rotAngle-=360.0f; uint16_t angleint = (uint16_t) rotAngle; uint16_t angledelta = (uint16_t) (360/NB_PIECES_BOSS); for( int i=0; ix + this->radiusInt * FastCosInt( angleint ); YdataBossInternal[ i ] = this->y + this->radiusInt * FastSinInt( angleint ); angleint += angledelta; if (angleint>=360) angleint -= 360; } // Pour le cercle Exterieur on se décale d'un demi-incrément d'angle pour le sommet du triangle angleint = (uint16_t) rotAngle + angledelta/2; if (angleint>=360) angleint -= 360; for( int i=0; ix + this->radiusExt * FastCosInt( angleint ); YdataBossExternal[ i ] = this->y + this->radiusExt * FastSinInt( angleint ); angleint += angledelta; if (angleint>=360) angleint -= 360; } } void Boss::Render( void ) { if (ID==0 && toberemoved==false) { for( int i=0; ilife0*2/3) azrp_subimage_p8_effect((int) x - img_Lifebar.width/2, ymin - 9, &img_Lifebar, 0, 7, (img_Lifebar.width*life)/life0, 5, DIMAGE_NONE ); else if (life>life0/3) azrp_subimage_p8_effect((int) x - img_Lifebar.width/2, ymin - 9, &img_Lifebar, 0, 12, (img_Lifebar.width*life)/life0, 5, DIMAGE_NONE ); else azrp_subimage_p8_effect((int) x - img_Lifebar.width/2, ymin - 9, &img_Lifebar, 0, 17, (img_Lifebar.width*life)/life0, 5, DIMAGE_NONE ); }; } bool Boss::Test_Impact( Bullet *projectile ) { for( int i=0; i< NB_PIECES_BOSS; i++ ) { if (Pieces[i*2].toberemoved == false) { if (Is_Point_Inside_Triangle( (int) projectile->x, (int) projectile->y, (int) XdataBossExternal[ Pieces[i*2].P1 ], (int) YdataBossExternal[ Pieces[i*2].P1 ], (int) XdataBossExternal[ Pieces[i*2].P2 ], (int) YdataBossExternal[ Pieces[i*2].P2 ], (int) XdataBossInternal[ Pieces[i*2].P3 ], (int) YdataBossInternal[ Pieces[i*2].P3 ] )) { Pieces[i*2].life -= projectile->strength; if (Pieces[i*2].life<=0) { Pieces[i*2].toberemoved = true; Create_Explosion( (int) projectile->x, (int) projectile->y ); } projectile->toberemoved = true; return true; } } if (Pieces[i*2+1].toberemoved == false) { if (Is_Point_Inside_Triangle( (int) projectile->x, (int) projectile->y, (int) XdataBossInternal[ Pieces[i*2+1].P1 ], (int) YdataBossInternal[ Pieces[i*2+1].P1 ], (int) XdataBossInternal[ Pieces[i*2+1].P2 ], (int) YdataBossInternal[ Pieces[i*2+1].P2 ], (int) XdataBossExternal[ Pieces[i*2+1].P3 ], (int) YdataBossExternal[ Pieces[i*2+1].P3 ] )) { Pieces[i*2+1].life -= projectile->strength; if (Pieces[i*2+1].life<=0) { Pieces[i*2+1].toberemoved = true; Create_Explosion( (int) projectile->x, (int) projectile->y ); } projectile->toberemoved = true; return true; } } } if (projectile->x >= xmin && projectile->x <= xmax && projectile->y >= ymin && projectile->y <= ymax ) { life -= projectile->strength; if (life<0) toberemoved = true; projectile->toberemoved = true; return true; } else return false; }