enable non-looping trajectories with dully kill of enemies when reaching end
This commit is contained in:
parent
137cf2f6a9
commit
ba57b0aa4a
2
TODO.txt
2
TODO.txt
|
@ -5,7 +5,7 @@
|
|||
- [DONE] better keyboard management engine for keypressed() and keyreleased() events
|
||||
- Mettre une système d'ajustement de FPS mini avec switch des niveaux d'overclock à la volée de manière dynamique
|
||||
- [DONE] Mettre en place un système de collision en "pixel perfect" pour mode jeu "Asteroids Alert !!!"
|
||||
- refactoriser les classes des entités "mobiles"
|
||||
- [DONE] refactoriser les classes des entités "mobiles"
|
||||
o class Entity (position, box, ID, trajectory)
|
||||
~~> class Enemy : public Entity (+shoot, +life)
|
||||
~~> class Boss : public Enemy (+multiple shoots, +multiple life)
|
||||
|
|
Binary file not shown.
|
@ -54,7 +54,8 @@ void Bonus::Update( float dt )
|
|||
}
|
||||
else
|
||||
{
|
||||
pathToFollow->CalculatePosition( &accumulatedTime, dt, speed, true, &x, &y );
|
||||
if (pathToFollow->CalculatePosition( &accumulatedTime, dt, speed, loopTrajectory, &x, &y ) == -1)
|
||||
toberemoved=true;
|
||||
}
|
||||
|
||||
xmin = (int) x - width;
|
||||
|
|
|
@ -24,11 +24,7 @@ class Bonus : public Entity
|
|||
|
||||
private:
|
||||
int8_t dirx, diry;
|
||||
libnum::num currentframe;
|
||||
|
||||
libnum::num currentframe;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -158,7 +158,8 @@ void Boss::Update( float dt )
|
|||
{
|
||||
if (hasTrajectory)
|
||||
{
|
||||
pathToFollow->CalculatePosition( &accumulatedTime, dt, speed, true, &x, &y );
|
||||
if (pathToFollow->CalculatePosition( &accumulatedTime, dt, speed, loopTrajectory, &x, &y ) == -1)
|
||||
toberemoved=true;
|
||||
}
|
||||
|
||||
xmin = (int) x - width;
|
||||
|
|
|
@ -38,7 +38,7 @@ class Boss : public Enemy
|
|||
|
||||
virtual void Update( float dt ) override;
|
||||
virtual void Render( void ) override;
|
||||
virtual bool Test_Impact( Bullet *projectile ) override;
|
||||
bool Test_Impact( Bullet *projectile ) override;
|
||||
|
||||
uint32_t lastshoot = 0;
|
||||
uint8_t rotSpeed;
|
||||
|
|
|
@ -67,8 +67,6 @@ void Create_Enemies( void )
|
|||
MyEnemies.push_back( e4 );
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Vector2D *A = new Vector2D( 348, 112 );
|
||||
Vector2D *B = new Vector2D( 371, 199 );
|
||||
Vector2D *C = new Vector2D( 198, 149 );
|
||||
|
@ -77,7 +75,6 @@ void Create_Enemies( void )
|
|||
Vector2D *F = new Vector2D( 198, 75 );
|
||||
Vector2D *G = new Vector2D( 371, 25 );
|
||||
|
||||
|
||||
Trajectory *MyPath= new Trajectory();
|
||||
MyPath->AddPoint( A );
|
||||
MyPath->AddPoint( B );
|
||||
|
@ -88,6 +85,7 @@ void Create_Enemies( void )
|
|||
MyPath->AddPoint( G );
|
||||
MyTrajectories.push_back( MyPath );
|
||||
|
||||
|
||||
Enemy* e5 = new Enemy( 348, 112, 2);
|
||||
e5->hasTrajectory = true;
|
||||
e5->pathToFollow = MyPath;
|
||||
|
@ -110,9 +108,79 @@ void Create_Enemies( void )
|
|||
MyEnemies.push_back( e5 );
|
||||
MyEnemies.push_back( e6 );
|
||||
MyEnemies.push_back( e7 );
|
||||
|
||||
|
||||
Vector2D *A1 = new Vector2D( 450, 0 );
|
||||
Vector2D *B1 = new Vector2D( 400, 0 );
|
||||
Vector2D *C1 = new Vector2D( 350, 25 );
|
||||
Vector2D *D1 = new Vector2D( 300, 25 );
|
||||
Vector2D *E1 = new Vector2D( 250, 100 );
|
||||
Vector2D *F1 = new Vector2D( 100, 100 );
|
||||
Vector2D *G1 = new Vector2D( 50, 25 );
|
||||
Vector2D *H1 = new Vector2D( 0, 25 );
|
||||
Vector2D *I1 = new Vector2D( -100, 0 );
|
||||
|
||||
|
||||
Trajectory *MyPath1= new Trajectory();
|
||||
MyPath1->AddPoint( A1 );
|
||||
MyPath1->AddPoint( B1 );
|
||||
MyPath1->AddPoint( C1 );
|
||||
MyPath1->AddPoint( D1 );
|
||||
MyPath1->AddPoint( E1 );
|
||||
MyPath1->AddPoint( F1 );
|
||||
MyPath1->AddPoint( G1 );
|
||||
MyPath1->AddPoint( H1 );
|
||||
MyPath1->AddPoint( I1 );
|
||||
MyTrajectories.push_back( MyPath1 );
|
||||
|
||||
|
||||
Enemy* e8 = new Enemy( 450, 0, 1);
|
||||
e8->hasTrajectory = true;
|
||||
e8->pathToFollow = MyPath1;
|
||||
MyPath1->AddRegistry();
|
||||
e8->Set_Accumulated_Time(1.0f);
|
||||
|
||||
Enemy* e9 = new Enemy( 450, 0, 1);
|
||||
e9->hasTrajectory = true;
|
||||
e9->pathToFollow = MyPath1;
|
||||
MyPath1->AddRegistry();
|
||||
e9->Set_Accumulated_Time(0.75f);
|
||||
e9->Set_Loop_Trajectory(false);
|
||||
|
||||
Enemy* e10 = new Enemy( 450, 0, 1);
|
||||
e10->hasTrajectory = true;
|
||||
e10->pathToFollow = MyPath1;
|
||||
MyPath1->AddRegistry();
|
||||
e10->Set_Accumulated_Time(0.50f);
|
||||
|
||||
Enemy* e11 = new Enemy( 450, 0, 1);
|
||||
e11->hasTrajectory = true;
|
||||
e11->pathToFollow = MyPath1;
|
||||
MyPath1->AddRegistry();
|
||||
e11->Set_Accumulated_Time(0.25f);
|
||||
e11->Set_Loop_Trajectory(false);
|
||||
|
||||
Enemy* e12 = new Enemy( 450, 0, 1);
|
||||
e12->hasTrajectory = true;
|
||||
e12->pathToFollow = MyPath1;
|
||||
MyPath1->AddRegistry();
|
||||
e12->Set_Accumulated_Time(0.0f);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
MyEnemies.push_back( e8 );
|
||||
MyEnemies.push_back( e9 );
|
||||
MyEnemies.push_back( e10 );
|
||||
MyEnemies.push_back( e11 );
|
||||
MyEnemies.push_back( e12 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Create_Explosion( uint16_t xexplosion, uint16_t yexplosion )
|
||||
{
|
||||
srand(rtc_ticks());
|
||||
|
|
|
@ -68,7 +68,8 @@ void Enemy::Update( float dt )
|
|||
}
|
||||
else
|
||||
{
|
||||
pathToFollow->CalculatePosition( &accumulatedTime, dt, speed, true, &x, &y );
|
||||
if (pathToFollow->CalculatePosition( &accumulatedTime, dt, speed, loopTrajectory, &x, &y ) == -1)
|
||||
toberemoved=true;
|
||||
}
|
||||
|
||||
xmin = (int) x - width;
|
||||
|
|
|
@ -22,7 +22,7 @@ class Enemy : public Entity
|
|||
virtual void Update( float dt ) override;
|
||||
virtual void Render( void ) override;
|
||||
|
||||
virtual bool Test_Impact( Bullet *projectile ) override;
|
||||
virtual bool Test_Impact( Bullet *projectile );
|
||||
void Set_Speed_Vector( uint8_t _sp, uint8_t _xd, uint8_t _yd);
|
||||
|
||||
virtual void Set_Accumulated_Time( float value );
|
||||
|
|
|
@ -9,6 +9,7 @@ Entity::Entity( int16_t _x, int16_t _y, uint8_t _id )
|
|||
toberemoved = false;
|
||||
hasTrajectory = false;
|
||||
accumulatedTime = 0.0f;
|
||||
loopTrajectory = true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,7 +29,7 @@ void Entity::Render( void )
|
|||
|
||||
}
|
||||
|
||||
bool Entity::Test_Impact( Bullet *projectile )
|
||||
void Entity::Set_Loop_Trajectory( bool value )
|
||||
{
|
||||
|
||||
loopTrajectory = value;
|
||||
}
|
|
@ -18,7 +18,7 @@ class Entity
|
|||
|
||||
virtual void Update( float dt );
|
||||
virtual void Render( void );
|
||||
virtual bool Test_Impact( Bullet *projectile );
|
||||
void Set_Loop_Trajectory( bool value );
|
||||
|
||||
|
||||
libnum::num x, y; // center position of the boss
|
||||
|
@ -30,6 +30,7 @@ class Entity
|
|||
bool toberemoved;
|
||||
|
||||
bool hasTrajectory = false;
|
||||
bool loopTrajectory;
|
||||
Trajectory *pathToFollow;
|
||||
float accumulatedTime;
|
||||
int16_t life0;
|
||||
|
|
|
@ -34,11 +34,19 @@ void Trajectory::DeleteRegistry( void )
|
|||
registration--;
|
||||
}
|
||||
|
||||
void Trajectory::CalculatePosition( float *accumulatedTime, float time, uint16_t speed, bool looped, libnum::num *xreturn, libnum::num *yreturn )
|
||||
int8_t Trajectory::CalculatePosition( float *accumulatedTime, float time, uint16_t speed, bool looped, libnum::num *xreturn, libnum::num *yreturn )
|
||||
{
|
||||
*accumulatedTime += speed * time / 2000000.0f;
|
||||
if (*accumulatedTime>ControlPoints.size()) *accumulatedTime-=ControlPoints.size();
|
||||
if (*accumulatedTime<0) *accumulatedTime+=ControlPoints.size();
|
||||
|
||||
if( !looped && (*accumulatedTime>ControlPoints.size()))
|
||||
return -1;
|
||||
|
||||
if (*accumulatedTime>ControlPoints.size())
|
||||
*accumulatedTime -= ControlPoints.size();
|
||||
|
||||
if (*accumulatedTime<0)
|
||||
*accumulatedTime += ControlPoints.size();
|
||||
|
||||
|
||||
libnum::num t = libnum::num( *accumulatedTime - (int) *accumulatedTime );
|
||||
|
||||
|
@ -72,4 +80,6 @@ void Trajectory::CalculatePosition( float *accumulatedTime, float time, uint16_t
|
|||
|
||||
*xreturn = tx;
|
||||
*yreturn = ty;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class Trajectory
|
|||
void AddPoint( Vector2D *p );
|
||||
void AddRegistry( void );
|
||||
void DeleteRegistry( void );
|
||||
void CalculatePosition( float *accumulatedTime, float time, uint16_t speed, bool looped, libnum::num *xreturn, libnum::num *yreturn );
|
||||
int8_t CalculatePosition( float *accumulatedTime, float time, uint16_t speed, bool looped, libnum::num *xreturn, libnum::num *yreturn );
|
||||
|
||||
std::vector<Vector2D*> ControlPoints;
|
||||
bool isLoop;
|
||||
|
|
|
@ -62,17 +62,8 @@ bool Pixel_Perfect_Collision( SpriteLocator image1, SpriteLocator image2 )
|
|||
if ( IMAGE_IS_P4(image1.image->format) || IMAGE_IS_P4(image2.image->format) )
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
|
||||
int astartx, aendx;
|
||||
int astarty, aendy;
|
||||
int adeltax, adeltay;
|
||||
|
||||
int bstartx, bendx;
|
||||
int bstarty, bendy;
|
||||
int bdeltax, bdeltay;
|
||||
|
||||
int rows, columns;
|
||||
|
||||
if (image1.x <= image2.x)
|
||||
|
@ -191,13 +182,15 @@ bool Pixel_Perfect_Collision( SpriteLocator image1, SpriteLocator image2 )
|
|||
d1 = data_u16_1[ adeltax + i ] == transp1 ? 0 : 1;
|
||||
else if (im1_P8)
|
||||
d1 = data_u8_1[ adeltax + i ] == transp1 ? 0 : 1;
|
||||
|
||||
else d1 = 0;
|
||||
|
||||
/* d2 is set to 1 if pixel of image2 is not transparent and to 0 if transparent */
|
||||
/* need to be format dependant here so quite time consumming test at each loop :( )*/
|
||||
if (im2_P16)
|
||||
d2 = data_u16_2[ bdeltax + i ] == transp2 ? 0 : 1;
|
||||
else if (im2_P8)
|
||||
d2 = data_u8_2[ bdeltax + i ] == transp2 ? 0 : 1;
|
||||
else d2 = 0;
|
||||
|
||||
/* if d1 + d2 = 2 means that both coincident pixels are not transparent and then we have collision*/
|
||||
if (d1 + d2 == 2) return true;
|
||||
|
|
Loading…
Reference in New Issue