#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "utilities.h" #include "particles.h" #include #include #include "MyAzurShaders.h" bool screenshot = false; bool record = false; bool textoutput = false; bool exitToOS = false; #define SCALE_PIXEL 1 #define X_RESOL (DWIDTH / SCALE_PIXEL) #define Y_RESOL (DHEIGHT / SCALE_PIXEL) #define BIAS 1 #define NOBIAS (1-BIAS) std::vector MyParticles; Starfield *MyStarField; uint8_t texttodraw=1; extern bopti_image_t img_mainship1, img_mainship2; uint8_t movement = -1; uint16_t playerX = 0; uint16_t playerY = 0; uint16_t bossX = 0; uint16_t bossY = 0; static void hook_prefrag(int id, void *fragment, int size) { if(!screenshot && !record) return; /* Screenshot takes precedence */ char const *type = screenshot ? "image" : "video"; int pipe = usb_ff_bulk_output(); if(id == 0) { usb_fxlink_header_t h; usb_fxlink_image_t sh; int size = azrp_width * azrp_height * 2; usb_fxlink_fill_header(&h, "fxlink", type, size + sizeof sh); sh.width = htole32(azrp_width); sh.height = htole32(azrp_height); sh.pixel_format = htole32(USB_FXLINK_IMAGE_RGB565); usb_write_sync(pipe, &h, sizeof h, 4, false); usb_write_sync(pipe, &sh, sizeof sh, 4, false); } usb_write_sync(pipe, fragment, size, 4, false); if(id == azrp_frag_count - 1) { usb_commit_sync(pipe); screenshot = false; } } /*void Create_Starfield( void ) { MyStarField = new Starfield(); }*/ void Create_Explosion( void ) { if(MyParticles.size()>=1) return; srand(rtc_ticks()); uint16_t xexplosion = rand() % X_RESOL; uint16_t yexplosion = rand() % Y_RESOL; for(int i=0; i<50; i++) { Particle *p = new Particle( xexplosion, yexplosion ); MyParticles.push_back( p ); } } static void update( float dt ) { // all update stuff depending on time will be done here for(unsigned int i=0; iUpdate( dt ); // Check if the property toberemoved has been set to "true" for particle deletion if (MyParticles[i]->toberemoved == true) { delete( MyParticles[i] ); MyParticles.erase( MyParticles.begin() + i ); } } //MyStarField->Update( dt ); } static void get_inputs( void ) { uint8_t speed = 4; key_event_t ev; while((ev = pollevent()).type != KEYEV_NONE) { } movement = 0; if(keydown(KEY_SHIFT)) {Create_Explosion();} if(keydown(KEY_EXIT)) {exitToOS = true; }; if(keydown(KEY_7)) {screenshot = true;}; if(keydown(KEY_8)) {record = true; }; if(keydown(KEY_9)) {record = false; }; if(keydown(KEY_DEL)) {textoutput = true;}; if(keydown(KEY_F1)) {texttodraw=0;} if(keydown(KEY_F2)) {texttodraw=1;} if(keydown(KEY_F3)) {texttodraw=2;} if(keydown(KEY_F4)) {texttodraw=3;} if(keydown(KEY_LEFT)) { if(playerX>speed) playerX-=speed; } if(keydown(KEY_RIGHT)) { if(playerXspeed) playerY-=speed; } if(keydown(KEY_DOWN)) { if(playerY=1) Azur_draw_text(1,01, " FPS = %.0f", (float) (1000000.0f / elapsedTime) ); if (texttodraw>=1) Azur_draw_text(1,11, "Parts = %d", MyParticles.size() ); if (texttodraw>=2) Azur_draw_text(1,31, "Update = %.0f mc secs", (float) time_update ); if (texttodraw>=2) Azur_draw_text(1,41, "Render = %.0f mc secs", (float) time_render ); if (texttodraw>=2) Azur_draw_text(1,51, ">Total = %.3f ml secs", (float) elapsedTime / 1000.0f ); if (texttodraw>=2) Azur_draw_text(1,61, ">Total = %.0f seconds", (float) elapsedTime ); if (texttodraw>=3) Azur_draw_text(1,81, "Mem Used : %d", _uram_stats->used_memory + extram_stats->used_memory); if (texttodraw>=3) Azur_draw_text(1,91, "Mem Free : %d", _uram_stats->free_memory + extram_stats->free_memory); if (texttodraw>=3) Azur_draw_text(1,101, "Mem Peak Used : %d", _uram_stats->peak_used_memory + extram_stats->peak_used_memory ); if (texttodraw>=3) Azur_draw_text(1,121, "Size of Particles : %d bytes", sizeof(Particle) ); #endif for(auto& p : MyParticles) p->Render(); azrp_starfield(); azrp_image_p8_effect(bossX, bossY, &img_mainship2, IMAGE_VFLIP); azrp_image_p8(playerX, playerY, &img_mainship1, DIMAGE_NONE); azrp_update(); } prof_leave(perf_render); time_render = prof_time(perf_render); #if(NOBIAS) dclear(C_BLACK); dprint(1,01, C_WHITE, "Update = %.0f mc secs", (float) time_update ); dprint(1,11, C_WHITE, "Render = %.0f mc secs", (float) time_render ); dprint(1,21, C_WHITE, ">Total = %.3f ml secs", (float) elapsedTime / 1000.0f ); dprint(1,31, C_WHITE, ">Total = %.0f", (float) elapsedTime ); dprint(1,41, C_WHITE, " FPS = %.0f", (float) (1000000.0f / elapsedTime) ); dprint(1,51, C_WHITE, "Parts = %d", MyParticles.size() ); dupdate(); #endif elapsedTime = ((float) (time_update+time_render)); if (textoutput && usb_is_open()) { azrp_starfield_USBDEBUG( SHOW_PIXELS ); azrp_starfield_USBDEBUG( SHOW_STARS ); textoutput = false; } } while (exitToOS==false); for(auto& p : MyParticles) delete(p); MyParticles.clear(); azrp_starfield_close( ); prof_quit(); usb_close(); FreeMoreRAM( ); return 1; }