StarField in the background
|
@ -0,0 +1,13 @@
|
|||
# Build files
|
||||
/build-fx
|
||||
/build-cg
|
||||
/*.g1a
|
||||
/*.g3a
|
||||
|
||||
# Python bytecode
|
||||
__pycache__/
|
||||
|
||||
# Common IDE files
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
.vscode
|
|
@ -15,6 +15,7 @@ set(SOURCES
|
|||
src/main.cpp
|
||||
src/utilities.cpp
|
||||
src/particles.cpp
|
||||
src/starfield.cpp
|
||||
src/pixelshader.cpp
|
||||
# ...
|
||||
)
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# A very simple Space Shooter - SHMUP - Shoot Them All
|
||||
|
||||
First attempt to use Lephe's Azur.
|
||||
|
||||
Yet it only consists in a Particle Engine able to reproduce some kind of explosions and a starfield moving in the background of the screen.
|
||||
The particle engine is based on fixed-point maths for update and on Azur shaders for rendering.
|
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 3.7 KiB |
|
@ -0,0 +1,4 @@
|
|||
|
||||
|
||||
void azrp_pixel(int x1, int y1, int color);
|
||||
|
37
src/main.cpp
|
@ -22,11 +22,12 @@
|
|||
|
||||
#include "utilities.h"
|
||||
#include "particles.h"
|
||||
#include "starfield.h"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "pixelshader.h"
|
||||
#include "MyAzurShaders.h"
|
||||
|
||||
|
||||
bool screenshot = false;
|
||||
|
@ -41,13 +42,25 @@ bool exitToOS = false;
|
|||
#define NOBIAS (1-BIAS)
|
||||
|
||||
std::vector<Particle*> MyParticles;
|
||||
std::vector<Star*> MyStars;
|
||||
uint8_t texttodraw=1;
|
||||
|
||||
|
||||
|
||||
void Create_Starfield( void )
|
||||
{
|
||||
srand(rtc_ticks());
|
||||
|
||||
for(int i=0; i<100; i++)
|
||||
{
|
||||
Star *s = new Star( );
|
||||
MyStars.push_back( s );
|
||||
}
|
||||
}
|
||||
|
||||
void Create_Explosion( void )
|
||||
{
|
||||
if(MyParticles.size()>=150) return;
|
||||
if(MyParticles.size()>=300) return;
|
||||
|
||||
srand(rtc_ticks());
|
||||
|
||||
|
@ -76,6 +89,9 @@ static void update( float dt )
|
|||
MyParticles.erase( MyParticles.begin() + i );
|
||||
}
|
||||
}
|
||||
|
||||
for(auto&s : MyStars)
|
||||
s->Update( dt );
|
||||
}
|
||||
|
||||
|
||||
|
@ -118,7 +134,9 @@ int main(void)
|
|||
azrp_shader_image_p8_configure();
|
||||
azrp_shader_image_p4_configure();
|
||||
|
||||
//extern bopti_image_t img_plane;
|
||||
|
||||
Create_Starfield();
|
||||
|
||||
|
||||
usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL };
|
||||
usb_open(interfaces, GINT_CALL_NULL);
|
||||
|
@ -155,12 +173,6 @@ int main(void)
|
|||
// all the stuff to be rendered should be put here
|
||||
azrp_clear( C_BLACK );
|
||||
|
||||
azrp_pixel( 158, 11, 0xFFFF );
|
||||
azrp_pixel( 157, 12, 0xFFFF );
|
||||
azrp_pixel( 158, 12, 0xFFFF );
|
||||
azrp_pixel( 159, 12, 0xFFFF );
|
||||
azrp_pixel( 158, 13, 0xFFFF );
|
||||
|
||||
#if(BIAS)
|
||||
if (texttodraw>=1) Azur_draw_text(1,01, " FPS = %.0f", (float) (1000000.0f / elapsedTime) );
|
||||
if (texttodraw>=1) Azur_draw_text(1,11, "Parts = %d", MyParticles.size() );
|
||||
|
@ -182,6 +194,9 @@ int main(void)
|
|||
for(auto& p : MyParticles)
|
||||
p->Render();
|
||||
|
||||
for(auto& s : MyStars)
|
||||
s->Render();
|
||||
|
||||
azrp_update();
|
||||
}
|
||||
|
||||
|
@ -215,8 +230,12 @@ int main(void)
|
|||
while (exitToOS==false);
|
||||
|
||||
|
||||
for(auto& p : MyParticles) delete(p);
|
||||
MyParticles.clear();
|
||||
|
||||
for(auto& s : MyStars) delete(s);
|
||||
MyStars.clear();
|
||||
|
||||
|
||||
prof_quit();
|
||||
usb_close();
|
||||
|
|
|
@ -17,8 +17,8 @@ Particle::Particle( uint16_t lx, uint16_t ly )
|
|||
x = libnum::num( lx );
|
||||
y = libnum::num( ly );
|
||||
|
||||
sx = ( (libnum::num( rand() % 11 )) - libnum::num( 5.0f ) ) / libnum::num( 4.0f );
|
||||
sy = ( (libnum::num( rand() % 11 )) - libnum::num( 5.0f ) ) / libnum::num( 4.0f );
|
||||
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 ) );
|
||||
|
@ -39,7 +39,7 @@ void Particle::Update( float dt )
|
|||
libnum::num a = libnum::num( dt / 12000.0f );
|
||||
x += sx * a;
|
||||
y += sy * a;
|
||||
age += libnum::num( dt / 10000.0f );
|
||||
age += libnum::num( dt / 12000.0f );
|
||||
sx *= libnum::num( 0.90 );
|
||||
sy *= libnum::num( 0.90 );
|
||||
|
||||
|
@ -57,11 +57,11 @@ void Particle::Render( )
|
|||
|
||||
int color;
|
||||
|
||||
if ( age > libnum::num( 30 ) ) color = 0x526A; // Dark Purple Gray-ish
|
||||
else if ( age > libnum::num( 25 ) ) color = 0x71D6; // Red Brown -ish
|
||||
else if ( age > libnum::num( 20 ) ) color = 0xF80D; // Dark Red
|
||||
else if ( age > libnum::num( 15 ) ) color = 0xFB80; // Red
|
||||
else if ( age > libnum::num( 10 ) ) color = 0xFFE0; // Yellow
|
||||
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,
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#include <azur/gint/render.h>
|
||||
#include "pixelshader.h"
|
||||
#include "MyAzurShaders.h"
|
||||
|
||||
|
||||
uint8_t AZRP_SHADER_PIXEL = -1;
|
||||
|
||||
|
||||
__attribute__((constructor))
|
||||
static void register_shader(void)
|
||||
{
|
||||
|
@ -10,13 +12,15 @@ static void register_shader(void)
|
|||
AZRP_SHADER_PIXEL = azrp_register_shader(azrp_shader_pixel);
|
||||
}
|
||||
|
||||
|
||||
void azrp_shader_pixel_configure(void)
|
||||
{
|
||||
azrp_set_uniforms(AZRP_SHADER_PIXEL, (void *)azrp_width);
|
||||
}
|
||||
|
||||
|
||||
struct command {
|
||||
uint16_t shader_id;
|
||||
uint8_t shader_id;
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
uint16_t color;
|
||||
|
@ -27,15 +31,11 @@ void azrp_pixel(int x1, int y1, int color)
|
|||
{
|
||||
prof_enter(azrp_perf_cmdgen);
|
||||
|
||||
/* Find a rectangle containing the triangle */
|
||||
|
||||
if(x1 >= azrp_width || x1 < 0 || y1 >= azrp_height || y1 < 0) {
|
||||
prof_leave(azrp_perf_cmdgen);
|
||||
return;
|
||||
}
|
||||
|
||||
/* TODO: Have a proper way to do optimized-division by azrp_frag_height
|
||||
TODO: Also account for first-fragment offset */
|
||||
int frag_first = y1 >> 4;
|
||||
int frag_count = 1;
|
||||
int first_offset = y1 & 15;
|
||||
|
@ -50,6 +50,7 @@ void azrp_pixel(int x1, int y1, int color)
|
|||
prof_leave(azrp_perf_cmdgen);
|
||||
}
|
||||
|
||||
|
||||
void azrp_shader_pixel( void *uniforms, void *command, void *fragment )
|
||||
{
|
||||
struct command *cmd = (struct command *) command;
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
|
||||
|
||||
void azrp_pixel(int x1, int y1, int color);
|
|
@ -0,0 +1,79 @@
|
|||
#include "starfield.h"
|
||||
|
||||
#include <azur/azur.h>
|
||||
#include <azur/gint/render.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <num/num.h>
|
||||
|
||||
#include "MyAzurShaders.h"
|
||||
|
||||
|
||||
|
||||
Star::Star( void )
|
||||
{
|
||||
x = rand() % 396;
|
||||
y = libnum::num( rand() % 224 );
|
||||
|
||||
size = 1 + ( rand() % 4 );
|
||||
|
||||
sy = libnum::num( size );
|
||||
|
||||
color = 0xFFFF;
|
||||
}
|
||||
|
||||
Star::~Star()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Star::Update( float dt )
|
||||
{
|
||||
libnum::num a = libnum::num( dt / 12000.0f );
|
||||
y += sy * a;
|
||||
|
||||
if (y > 224)
|
||||
{
|
||||
x = rand() % 396;
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Star::Render( )
|
||||
{
|
||||
if (size==1)
|
||||
{
|
||||
azrp_pixel( x, (int) y, color );
|
||||
}
|
||||
else if (size==2)
|
||||
{
|
||||
azrp_pixel( x-1, (int) y-1, color );
|
||||
azrp_pixel( x-1, (int) y, color );
|
||||
azrp_pixel( x, (int) y-1, color );
|
||||
azrp_pixel( x, (int) y, color );
|
||||
}
|
||||
else if (size==3)
|
||||
{
|
||||
azrp_pixel( x, (int) y-1, color );
|
||||
azrp_pixel( x-1, (int) y, color );
|
||||
azrp_pixel( x, (int) y, color );
|
||||
azrp_pixel( x+1, (int) y, color );
|
||||
azrp_pixel( x, (int) y+1, color );
|
||||
}
|
||||
else if (size==4)
|
||||
{
|
||||
azrp_pixel( x-1, (int) y-1, color );
|
||||
azrp_pixel( x-1, (int) y, color );
|
||||
azrp_pixel( x-1, (int) y+1, color );
|
||||
azrp_pixel( x, (int) y-1, color );
|
||||
azrp_pixel( x, (int) y, color );
|
||||
azrp_pixel( x, (int) y+1, color );
|
||||
azrp_pixel( x+1, (int) y-1, color );
|
||||
azrp_pixel( x+1, (int) y, color );
|
||||
azrp_pixel( x+1, (int) y+1, color );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef STARS_H
|
||||
#define STARS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <num/num.h>
|
||||
|
||||
class Star
|
||||
{
|
||||
public:
|
||||
Star();
|
||||
~Star();
|
||||
void Update( float dt );
|
||||
void Render();
|
||||
|
||||
uint16_t x;
|
||||
libnum::num y;
|
||||
libnum::num sy;
|
||||
uint8_t size;
|
||||
uint16_t color;
|
||||
};
|
||||
|
||||
#endif //STARS_H
|