#include "ennemy.h" #include "bullet.h" #include extern bopti_image_t img_mainship2; extern bopti_image_t img_Ennemy_Blue_Lvl1; Ennemy::Ennemy( int16_t _x, int16_t _y, uint8_t _id ) { x = libnum::num( _x ); y = libnum::num( _y ); dirx = -6; diry = 1; ID = _id; if (ID==0) { width = img_mainship2.width/2; height = img_mainship2.height/2; speed = 1; } else if (ID==1) { width = img_Ennemy_Blue_Lvl1.width/2; height = img_Ennemy_Blue_Lvl1.height/2; speed = 2; } xmin = (int) x - width; xmax = (int) x + width; ymin = (int) y - height; ymax = (int) y + height; toberemoved = false; if (ID==0) life = 400; else if (ID==1) life = 200; } Ennemy::~Ennemy() { } void Ennemy::Update( float dt ) { libnum::num a = libnum::num( dt / 60000.0f ); x += a * libnum::num( dirx * speed ); y += a * libnum::num( diry * speed ); if (xazrp_width-width) dirx=-1*dirx; if (yazrp_height-height) diry=-1*diry; xmin = (int) x - width; xmax = (int) x + width; ymin = (int) y - height; ymax = (int) y + height; if (life<=0) toberemoved=true; } void Ennemy::Render( void ) { if (ID==0) azrp_image_p8_effect(xmin, ymin, &img_mainship2, IMAGE_VFLIP); if (ID==1) azrp_image_p8_effect(xmin, ymin, &img_Ennemy_Blue_Lvl1, DIMAGE_NONE); } bool Ennemy::Test_Impact( Bullet *projectile ) { if (projectile->x >= xmin && projectile->x <= xmax && projectile->y >= ymin && projectile->y <= ymax ) { life -= projectile->strength; projectile->toberemoved = true; return true; } else return false; } void Ennemy::Set_Speed_Vector( uint8_t _sp, uint8_t _xd, uint8_t _yd) { speed = _sp; dirx = _xd; diry = _yd; }