2023-01-22 13:39:43 +01:00
|
|
|
#include "enemy.h"
|
2023-01-21 14:04:58 +01:00
|
|
|
#include "bullet.h"
|
|
|
|
#include <num/num.h>
|
|
|
|
|
|
|
|
|
|
|
|
extern bopti_image_t img_mainship2;
|
2023-01-22 13:39:43 +01:00
|
|
|
extern bopti_image_t img_Enemy_Blue_Lvl1;
|
2023-01-23 22:03:09 +01:00
|
|
|
extern bopti_image_t img_Enemy_Red_Lvl1;
|
2023-01-21 14:04:58 +01:00
|
|
|
|
2023-01-22 13:39:43 +01:00
|
|
|
Enemy::Enemy( int16_t _x, int16_t _y, uint8_t _id )
|
2023-01-21 14:04:58 +01:00
|
|
|
{
|
|
|
|
x = libnum::num( _x );
|
|
|
|
y = libnum::num( _y );
|
|
|
|
|
2023-01-23 18:27:57 +01:00
|
|
|
dirx = 1;
|
|
|
|
diry = -6;
|
2023-01-21 14:04:58 +01:00
|
|
|
|
|
|
|
ID = _id;
|
|
|
|
|
|
|
|
if (ID==0)
|
|
|
|
{
|
|
|
|
width = img_mainship2.width/2;
|
|
|
|
height = img_mainship2.height/2;
|
|
|
|
speed = 1;
|
|
|
|
}
|
2023-01-21 22:45:10 +01:00
|
|
|
else if (ID==1)
|
|
|
|
{
|
2023-01-22 13:39:43 +01:00
|
|
|
width = img_Enemy_Blue_Lvl1.width/2;
|
|
|
|
height = img_Enemy_Blue_Lvl1.height/2;
|
2023-01-21 22:45:10 +01:00
|
|
|
speed = 2;
|
|
|
|
}
|
2023-01-23 22:03:09 +01:00
|
|
|
else if (ID==2)
|
|
|
|
{
|
|
|
|
width = img_Enemy_Red_Lvl1.width/2;
|
|
|
|
height = img_Enemy_Red_Lvl1.height/2;
|
|
|
|
speed = 2;
|
|
|
|
}
|
2023-01-21 22:45:10 +01:00
|
|
|
|
2023-01-21 14:04:58 +01:00
|
|
|
xmin = (int) x - width;
|
|
|
|
xmax = (int) x + width;
|
|
|
|
ymin = (int) y - height;
|
|
|
|
ymax = (int) y + height;
|
|
|
|
|
|
|
|
toberemoved = false;
|
|
|
|
|
2023-01-21 22:45:10 +01:00
|
|
|
if (ID==0) life = 400;
|
|
|
|
else if (ID==1) life = 200;
|
2023-01-23 22:03:09 +01:00
|
|
|
else if (ID==2) life = 100;
|
2023-01-21 14:04:58 +01:00
|
|
|
}
|
|
|
|
|
2023-01-22 13:39:43 +01:00
|
|
|
Enemy::~Enemy()
|
2023-01-21 14:04:58 +01:00
|
|
|
{
|
2023-01-23 22:03:09 +01:00
|
|
|
if (hasTrajectory)
|
|
|
|
delete(pathToFollow);
|
2023-01-21 14:04:58 +01:00
|
|
|
}
|
|
|
|
|
2023-01-22 13:39:43 +01:00
|
|
|
void Enemy::Update( float dt )
|
2023-01-21 14:04:58 +01:00
|
|
|
{
|
2023-01-23 22:03:09 +01:00
|
|
|
if (!hasTrajectory)
|
|
|
|
{
|
|
|
|
libnum::num a = libnum::num( dt / 60000.0f );
|
|
|
|
x += a * libnum::num( dirx * speed );
|
|
|
|
y += a * libnum::num( diry * speed );
|
2023-01-21 14:04:58 +01:00
|
|
|
|
2023-01-23 22:03:09 +01:00
|
|
|
if (x<width || x>azrp_width-width) dirx=-1*dirx;
|
|
|
|
if (y<height || y>azrp_height-height) diry=-1*diry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int tempX, tempY;
|
|
|
|
pathToFollow->CalculatePosition( dt, speed, true, &tempX, &tempY );
|
|
|
|
x = libnum::num( tempX );
|
|
|
|
y = libnum::num( tempY );
|
|
|
|
}
|
2023-01-21 14:04:58 +01:00
|
|
|
|
|
|
|
xmin = (int) x - width;
|
|
|
|
xmax = (int) x + width;
|
|
|
|
ymin = (int) y - height;
|
|
|
|
ymax = (int) y + height;
|
|
|
|
|
|
|
|
if (life<=0) toberemoved=true;
|
|
|
|
}
|
|
|
|
|
2023-01-22 13:39:43 +01:00
|
|
|
void Enemy::Render( void )
|
2023-01-21 14:04:58 +01:00
|
|
|
{
|
2023-01-23 22:03:09 +01:00
|
|
|
if (ID==0) azrp_image_p8_effect(xmin, ymin, &img_mainship2, DIMAGE_NONE);
|
2023-01-22 13:39:43 +01:00
|
|
|
if (ID==1) azrp_image_p8_effect(xmin, ymin, &img_Enemy_Blue_Lvl1, DIMAGE_NONE);
|
2023-01-23 22:03:09 +01:00
|
|
|
if (ID==2) azrp_image_p8_effect(xmin, ymin, &img_Enemy_Red_Lvl1, DIMAGE_NONE);
|
2023-01-21 14:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-22 13:39:43 +01:00
|
|
|
bool Enemy::Test_Impact( Bullet *projectile )
|
2023-01-21 14:04:58 +01:00
|
|
|
{
|
|
|
|
if (projectile->x >= xmin && projectile->x <= xmax && projectile->y >= ymin && projectile->y <= ymax )
|
|
|
|
{
|
|
|
|
life -= projectile->strength;
|
|
|
|
projectile->toberemoved = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
2023-01-22 13:39:43 +01:00
|
|
|
void Enemy::Set_Speed_Vector( uint8_t _sp, uint8_t _xd, uint8_t _yd)
|
2023-01-21 14:04:58 +01:00
|
|
|
{
|
|
|
|
speed = _sp;
|
|
|
|
dirx = _xd;
|
|
|
|
diry = _yd;
|
|
|
|
}
|