90 lines
1.8 KiB
C++
90 lines
1.8 KiB
C++
#include "bullet.h"
|
|
|
|
#include <azur/azur.h>
|
|
#include <azur/gint/render.h>
|
|
|
|
#include <cstdint>
|
|
#include <stdlib.h>
|
|
|
|
#include <num/num.h>
|
|
|
|
|
|
extern bopti_image_t img_bullet_normal;
|
|
extern bopti_image_t img_bullet_blue;
|
|
extern bopti_image_t img_bullet_laser;
|
|
extern bopti_image_t img_bullet_enemy_blue;
|
|
|
|
|
|
|
|
Bullet::Bullet( uint16_t lx, uint16_t ly, int16_t dx, int16_t dy, uint8_t id )
|
|
{
|
|
x = libnum::num( lx );
|
|
y = libnum::num( ly );
|
|
|
|
sx = libnum::num( dx );
|
|
sy = libnum::num( dy );
|
|
|
|
ID=id;
|
|
|
|
if (ID==BULLET_NORMAL)
|
|
{
|
|
strength = 5;
|
|
}
|
|
else if (ID==BULLET_BLUE)
|
|
{
|
|
strength = 2;
|
|
}
|
|
else if (ID==BULLET_LASER)
|
|
{
|
|
strength = 1;
|
|
}
|
|
else if (ID==BULLET_ENEMY_BLUE)
|
|
{
|
|
strength = 2;
|
|
}
|
|
toberemoved = false;
|
|
}
|
|
|
|
Bullet::~Bullet()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
void Bullet::Update( float dt )
|
|
{
|
|
libnum::num a = libnum::num( dt / 12000.0f );
|
|
x += sx * a;
|
|
y += sy * a;
|
|
|
|
if (x<-10 || x>azrp_width+10 || y<-10 || y>azrp_height+10) toberemoved=true;
|
|
}
|
|
|
|
void Bullet::Render( )
|
|
{
|
|
int16_t px = (int) x;
|
|
int16_t py = (int) y;
|
|
|
|
if (ID==BULLET_NORMAL)
|
|
{
|
|
azrp_image_p8( px-img_bullet_normal.width/2, py-img_bullet_normal.height/2, &img_bullet_normal, DIMAGE_NONE );
|
|
return;
|
|
}
|
|
else if (ID==BULLET_BLUE)
|
|
{
|
|
azrp_image_p8( px-img_bullet_blue.width/2, py-img_bullet_blue.height/2, &img_bullet_blue, DIMAGE_NONE );
|
|
return;
|
|
}
|
|
else if (ID==BULLET_LASER)
|
|
{
|
|
azrp_image_p8( px-img_bullet_laser.width/2, py-img_bullet_laser.height/2, &img_bullet_laser, DIMAGE_NONE );
|
|
return;
|
|
}
|
|
else if (ID==BULLET_ENEMY_BLUE)
|
|
{
|
|
azrp_image_p8( px-img_bullet_enemy_blue.width/2, py-img_bullet_enemy_blue.height/2, &img_bullet_enemy_blue, DIMAGE_NONE );
|
|
return;
|
|
}
|
|
}
|
|
|