Shmup/src/bullet.cpp

81 lines
1.5 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;
Bullet::Bullet( uint16_t lx, uint16_t ly, uint8_t id )
{
x = libnum::num( lx );
y = libnum::num( ly );
ID=id;
if (ID==0)
{
sx = libnum::num( 6 );
sy = 0;
strength = 5;
}
else if (ID==1)
{
sx = libnum::num( 3 );
sy = 0;
strength = 2;
}
else if (ID==2)
{
sx = libnum::num( 3 );
sy = 0;
strength = 1;
}
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( )
{
uint16_t px = (int) x;
uint16_t py = (int) y;
if (ID==0)
{
azrp_image_p8( px-img_bullet_normal.width/2, py-img_bullet_normal.height/2, &img_bullet_normal, DIMAGE_NONE );
return;
}
else if (ID==1)
{
azrp_image_p8( px-img_bullet_blue.width/2, py-img_bullet_blue.height/2, &img_bullet_blue, DIMAGE_NONE );
return;
}
else if (ID==2)
{
azrp_image_p8( px-img_bullet_laser.width/2, py-img_bullet_laser.height/2, &img_bullet_laser, DIMAGE_NONE );
return;
}
}