286 lines
9.3 KiB
C++
286 lines
9.3 KiB
C++
#include "config.h"
|
|
|
|
#include "boss.h"
|
|
#include "bullet.h"
|
|
#include <cstdint>
|
|
#include <num/num.h>
|
|
#include <gint/rtc.h>
|
|
#include <sys/types.h>
|
|
#include "fast_trig.h"
|
|
|
|
#include <gint/gint.h>
|
|
#include "collections.h"
|
|
|
|
|
|
extern bopti_image_t img_Lifebar;
|
|
extern bopti_image_t img_Boss1;
|
|
|
|
extern font_t milifont_prop;
|
|
|
|
|
|
#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 <stdio.h>
|
|
|
|
void savedata( void )
|
|
{
|
|
FILE* exportfp = fopen("databosPtxt", "w" );
|
|
if(exportfp)
|
|
{
|
|
fprintf(exportfp, "Points : \n" );
|
|
|
|
for( int i=0; i<NB_PIECES_BOSS; i++ )
|
|
{
|
|
fprintf(exportfp, "Ext[ %d ] : X= %d - Y= %d \n", i, (int) XdataBossExternal[i], (int) YdataBossExternal[i] );
|
|
}
|
|
|
|
for( int i=0; i<NB_PIECES_BOSS; i++ )
|
|
{
|
|
fprintf(exportfp, "Int[ %d ] : X= %d - Y= %d \n", i, (int) XdataBossInternal[i], (int) YdataBossInternal[i] );
|
|
}
|
|
|
|
fprintf(exportfp, "Triangles : \n" );
|
|
|
|
for( int i=0; i<NB_PIECES_BOSS; i++ )
|
|
{
|
|
fprintf(exportfp, "Tri ext[ %d ] : P1= %d - P2= %d - P3= %d \n", i, Pieces[2*i].P1, Pieces[2*i].P2, Pieces[2*i].P3 );
|
|
}
|
|
|
|
for( int i=0; i<NB_PIECES_BOSS; i++ )
|
|
{
|
|
fprintf(exportfp, "Tri int[ %d ] : P1= %d - P2= %d - P3= %d \n", i, Pieces[2*i+1].P1, Pieces[2*i+1].P2, Pieces[2*i+1].P3 );
|
|
}
|
|
|
|
fclose( exportfp );
|
|
}
|
|
|
|
}
|
|
|
|
|
|
bool Is_Point_Inside_Triangle( int Px, int Py, int P1x, int P1y, int P2x, int P2y, int P3x, int P3y )
|
|
{
|
|
int as_x = Px - P1x;
|
|
int as_y = Py - P1y;
|
|
|
|
bool s_ab = (P2x - P1x) * as_y - (P2y - P1y) * as_x > 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; i<NB_PIECES_BOSS; i++ )
|
|
{
|
|
Pieces[i*2].P1 = i%NB_PIECES_BOSS; //exterior circle
|
|
Pieces[i*2].P2 = (i+1)%NB_PIECES_BOSS; //exterior circle
|
|
Pieces[i*2].P3 = (i+1)%NB_PIECES_BOSS; //interior circle
|
|
Pieces[i*2].life = 100;
|
|
Pieces[i*2].toberemoved = false;
|
|
Pieces[i*2].color = 0xbdf7; //light gray
|
|
|
|
Pieces[i*2+1].P1 = i%NB_PIECES_BOSS; //interior circle
|
|
Pieces[i*2+1].P2 = (i+1)%NB_PIECES_BOSS; //interior circle
|
|
Pieces[i*2+1].P3 = i%NB_PIECES_BOSS; //exterior circle
|
|
Pieces[i*2+1].life = 100;
|
|
Pieces[i*2+1].toberemoved = false;
|
|
Pieces[i*2+1].color = 0x528a; //darker gray
|
|
}
|
|
|
|
|
|
/* FOR DEBUGGING */
|
|
// gint_world_switch( GINT_CALL( savedata ) );
|
|
|
|
}
|
|
|
|
Boss::~Boss()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
void Boss::Update( float dt )
|
|
{
|
|
xmin = (int) x - width;
|
|
xmax = (int) x + width;
|
|
ymin = (int) y - height;
|
|
ymax = (int) y + height;
|
|
|
|
rotAngle += rotSpeed * dt / 25000.0f;
|
|
if (rotAngle>360.0f) rotAngle-=360.0f;
|
|
|
|
|
|
uint16_t angleint = (uint16_t) rotAngle;
|
|
uint16_t angledelta = (uint16_t) (360/NB_PIECES_BOSS);
|
|
|
|
for( int i=0; i<NB_PIECES_BOSS; i++ )
|
|
{
|
|
XdataBossInternal[ i ] = this->x + 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; i<NB_PIECES_BOSS; i++ )
|
|
{
|
|
XdataBossExternal[ i ] = this->x + 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; i<NB_PIECES_BOSS; i++ )
|
|
{
|
|
if (Pieces[i*2].toberemoved == false)
|
|
{
|
|
azrp_triangle( (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].color );
|
|
|
|
#if(DEBUG_MODE)
|
|
dfont( &milifont_prop );
|
|
int X = (int) ((XdataBossExternal[ Pieces[i*2].P1 ] + XdataBossExternal[ Pieces[i*2].P2 ] + XdataBossInternal[ Pieces[i*2].P3 ]) / 3);
|
|
int Y = (int) ((YdataBossExternal[ Pieces[i*2].P1 ] + YdataBossExternal[ Pieces[i*2].P2 ] + YdataBossInternal[ Pieces[i*2].P3 ]) / 3);
|
|
azrp_print( X, Y, C_WHITE, "%d", Pieces[i*2].life );
|
|
#endif
|
|
|
|
}
|
|
if (Pieces[i*2+1].toberemoved == false)
|
|
{
|
|
azrp_triangle( (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].color );
|
|
|
|
#if(DEBUG_MODE)
|
|
dfont( &milifont_prop );;
|
|
int X = (int) ((XdataBossInternal[ Pieces[i*2+1].P1 ] + XdataBossInternal[ Pieces[i*2+1].P2 ] + XdataBossExternal[ Pieces[i*2+1].P3 ]) / 3);
|
|
int Y = (int) ((YdataBossInternal[ Pieces[i*2+1].P1 ] + YdataBossInternal[ Pieces[i*2+1].P2 ] + YdataBossExternal[ Pieces[i*2+1].P3 ]) / 3);
|
|
azrp_print( X, Y, C_WHITE, "%d", Pieces[i*2+1].life );
|
|
#endif
|
|
}
|
|
}
|
|
|
|
azrp_image_p8_effect(xmin, ymin, &img_Boss1, DIMAGE_NONE);
|
|
|
|
if (life>life0*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) this->toberemoved = true;
|
|
projectile->toberemoved = true;
|
|
return true;
|
|
}
|
|
else return false;
|
|
}
|
|
|