Shmup/src/bullet.cpp

71 lines
1.0 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;
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 = 0;
sy = libnum::num( -6 );
strength = 5;
}
else if (ID==1)
{
sx = 0;
sy = libnum::num( -3 );
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 (y<-10) toberemoved=true;
}
void Bullet::Render( )
{
uint16_t px = (int) x;
uint16_t py = (int) y;
if (ID==0)
{
azrp_image_p8( px-4, py-11, &img_bullet_normal, DIMAGE_NONE );
return;
}
else if (ID==1)
{
azrp_image_p8( px-4, py-11, &img_bullet_blue, DIMAGE_NONE );
return;
}
}