#include "player.h" #include "bullet.h" #include "enemy.h" #include #include #include extern bopti_image_t img_mainship1; extern bopti_image_t img_Satellite_Lvl1; static int16_t cosTable[360], sinTable[360]; #define PI 3.141592 Player::Player( int16_t _x, int16_t _y, uint8_t _id ) { x = libnum::num(_x); y = libnum::num(_y); ID = _id; width = img_mainship1.width/2; height = img_mainship1.height/2; speed = 10; xmin = (int) x - width; xmax = (int) x + width; ymin = (int) y - height; ymax = (int) y + height; if (ID==0) life = 1000; lastshoot0 = rtc_ticks(); lastshoot1 = rtc_ticks(); lastshoot2 = rtc_ticks(); satellites = true; satLevel = 1; satNumber = 6; satAngle = 0; satRadius = 50; satSpeed = 2; for(int u=0; u<360; u++) { cosTable[u] = (int16_t) (satRadius*cos( u * PI / 180 )); sinTable[u] = (int16_t) (satRadius*sin( u * PI / 180 )); } } Player::~Player() { } void Player::Update( float dt ) { xmin = (int) x - width; xmax = (int) x + width; ymin = (int) y - height; ymax = (int) y + height; if(satellites) { satAngle += satSpeed * dt / 25000.0f; if (satAngle>360.0f) satAngle-=360.0f; } } void Player::Render( void ) { if (ID==0) azrp_image_p8_effect(xmin, ymin, &img_mainship1, DIMAGE_NONE); int w = img_Satellite_Lvl1.width/2; int h = img_Satellite_Lvl1.height/2; if(satellites) { int incangle = 360/satNumber; for(int u=0; ux >= xmin && projectile->x <= xmax && projectile->y >= ymin && projectile->y <= ymax ) { life -= projectile->strength; projectile->toberemoved = true; return true; } else return false; } bool Player::Test_Impact( Enemy *adverseship ) { if (adverseship->xmax >= xmin && adverseship->xmin <= xmax && adverseship->ymax >= ymin && adverseship->ymin <= ymax ) { life -= 50; adverseship->life -= 25; return true; } else return false; } void Player::Set_Speed( uint8_t _sp ) { speed = _sp; } bool Player::Shoot_OK( uint32_t tempshoot, uint8_t shootID ) { if (shootID==0) { if(tempshoot-lastshoot0>8) { lastshoot0=tempshoot; return true; } else return false; } else if (shootID==1) { if(tempshoot-lastshoot1>15) { lastshoot1=tempshoot; return true; } else return false; } else if (shootID==2) { if(tempshoot-lastshoot2>2) { lastshoot2=tempshoot; return true; } else return false; } else return false; } void Player::Go_Left( float dt ) { if( x > width/2+speed ) { libnum::num a = libnum::num( dt / 60000.0f ); x -= a * libnum::num( speed ); this->Update( 0.0f ); } } void Player::Go_Right( float dt ) { if(x < azrp_width-width/2-speed) { libnum::num a = libnum::num( dt / 60000.0f ); x += a * libnum::num( speed ); this->Update( 0.0f ); } } void Player::Go_Up( float dt ) { if(y > height/2+speed) { libnum::num a = libnum::num( dt / 60000.0f ); y -= a * libnum::num( speed ); this->Update( 0.0f ); } } void Player::Go_Down( float dt ) { if(y < azrp_height -height/2 -speed) { libnum::num a = libnum::num( dt / 60000.0f ); y += a * libnum::num( speed ); this->Update( 0.0f ); } }