diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2c4f84b --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# Build files +/build-fx +/build-cg +/*.g1a +/*.g3a + +# Python bytecode + __pycache__/ + +# Common IDE files +*.sublime-project +*.sublime-workspace +.vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index b841e35..855c84b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ set(SOURCES src/main.cpp src/utilities.cpp src/particles.cpp + src/starfield.cpp src/pixelshader.cpp # ... ) diff --git a/README.md b/README.md index d9a06bc..2d6ea02 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/assets-cg/Sprites/fill_circ_0.png b/assets-cg/Sprites/fill_circ_0.png deleted file mode 100644 index 277e658..0000000 Binary files a/assets-cg/Sprites/fill_circ_0.png and /dev/null differ diff --git a/assets-cg/Sprites/fill_circ_1.png b/assets-cg/Sprites/fill_circ_1.png deleted file mode 100644 index fbfc7ee..0000000 Binary files a/assets-cg/Sprites/fill_circ_1.png and /dev/null differ diff --git a/assets-cg/Sprites/fill_circ_2.png b/assets-cg/Sprites/fill_circ_2.png deleted file mode 100644 index 463aa22..0000000 Binary files a/assets-cg/Sprites/fill_circ_2.png and /dev/null differ diff --git a/assets-cg/Sprites/fill_circ_3.png b/assets-cg/Sprites/fill_circ_3.png deleted file mode 100644 index 077d653..0000000 Binary files a/assets-cg/Sprites/fill_circ_3.png and /dev/null differ diff --git a/assets-cg/Sprites/fill_circ_4.png b/assets-cg/Sprites/fill_circ_4.png deleted file mode 100644 index 7e2bdb0..0000000 Binary files a/assets-cg/Sprites/fill_circ_4.png and /dev/null differ diff --git a/assets-cg/Sprites/fill_circ_5.png b/assets-cg/Sprites/fill_circ_5.png deleted file mode 100644 index 8c3b05c..0000000 Binary files a/assets-cg/Sprites/fill_circ_5.png and /dev/null differ diff --git a/assets-cg/example.png b/assets-cg/example.png deleted file mode 100644 index 8826800..0000000 Binary files a/assets-cg/example.png and /dev/null differ diff --git a/src/MyAzurShaders.h b/src/MyAzurShaders.h new file mode 100644 index 0000000..0984d65 --- /dev/null +++ b/src/MyAzurShaders.h @@ -0,0 +1,4 @@ + + +void azrp_pixel(int x1, int y1, int color); + diff --git a/src/main.cpp b/src/main.cpp index 0fffed4..45bafab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,11 +22,12 @@ #include "utilities.h" #include "particles.h" +#include "starfield.h" #include #include -#include "pixelshader.h" +#include "MyAzurShaders.h" bool screenshot = false; @@ -41,13 +42,25 @@ bool exitToOS = false; #define NOBIAS (1-BIAS) std::vector MyParticles; +std::vector 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(); diff --git a/src/particles.cpp b/src/particles.cpp index e991abb..dd78a37 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -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, diff --git a/src/pixelshader.cpp b/src/pixelshader.cpp index b11b733..2f3292d 100644 --- a/src/pixelshader.cpp +++ b/src/pixelshader.cpp @@ -1,8 +1,10 @@ #include -#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; diff --git a/src/pixelshader.h b/src/pixelshader.h deleted file mode 100644 index 435b50c..0000000 --- a/src/pixelshader.h +++ /dev/null @@ -1,3 +0,0 @@ - - -void azrp_pixel(int x1, int y1, int color); \ No newline at end of file diff --git a/src/starfield.cpp b/src/starfield.cpp new file mode 100644 index 0000000..c29725e --- /dev/null +++ b/src/starfield.cpp @@ -0,0 +1,79 @@ +#include "starfield.h" + +#include +#include + +#include +#include + +#include + +#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 ); + } +} + diff --git a/src/starfield.h b/src/starfield.h new file mode 100644 index 0000000..3e5abae --- /dev/null +++ b/src/starfield.h @@ -0,0 +1,22 @@ +#ifndef STARS_H +#define STARS_H + +#include +#include + +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 \ No newline at end of file