Shmup/src/particles.cpp

73 lines
1.6 KiB
C++

#include "particles.h"
#include <azur/azur.h>
#include <azur/gint/render.h>
#include <cstdint>
#include <stdlib.h>
#include <num/num.h>
extern bopti_image_t img_fill_circ;
Particle::Particle( uint16_t lx, uint16_t ly )
{
x = libnum::num( lx );
y = libnum::num( ly );
sx = (libnum::num( rand() % 11 - 5 )) / 4 ;
sy = (libnum::num( rand() % 11 - 5 )) / 4;
age = libnum::num( rand() % 3 );
maxage = libnum::num( 20 + ( rand() % 20 ) );
size = libnum::num( 3 + ( rand() % 5 ) );
toberemoved = false;
}
Particle::~Particle()
{
}
void Particle::Update( float dt )
{
libnum::num a = libnum::num( dt / 12000.0f );
x += sx * a;
y += sy * a;
age += libnum::num( dt / 12000.0f );
sx *= libnum::num( 0.90 );
sy *= libnum::num( 0.90 );
if( age > maxage ) size *= libnum::num( 0.85 );
if( size < libnum::num( 1.0f ) ) toberemoved = true;
}
void Particle::Render( )
{
uint8_t dximg = (int) ( size - libnum::num( 1 ) ) * 15;
uint8_t sz = (int) size;
uint16_t px = (int) x;
uint16_t py = (int) y;
int color;
if ( age > 30 ) color = 0x526A; // Dark Purple Gray-ish
else if ( age > 25 ) color = 0x71D6; // Red Brown -ish
else if ( age > 20 ) color = 0xF80D; // Dark Red
else if ( age > 15 ) color = 0xFB80; // Red
else if ( age > 10 ) color = 0xFFE0; // Yellow
else color = 0xFFFF; // White
azrp_subimage_p8_dye( px-7, py-7,
&img_fill_circ,
dximg+7-sz, 7-sz, sz*2, sz*2,
IMAGE_DYE, color );
}