int main(void) { Cat cat("Garfield"); Dog dog("Odie"); /* cat.setName("Garfield"); dog.setName("Odie"); */ PetRenamer petRenamer("Jon"); cat.sleep(); petRenamer.rename(&cat,"Geraldine"); cat.eat(); cat.climb(); cat.play(); dog.sleep(); petRenamer.rename(&dog,"Pluto"); dog.eat(); dog.bark(); dog.bark(6); dog.play(); return 0; }
void GetFDoG(imatrix& image, ETF& e, double sigma, double sigma3, double tau) { int i, j; int image_x = image.getRow(); int image_y = image.getCol(); myvec GAU1, GAU2, GAU3; MakeGaussianVector(sigma, GAU1); MakeGaussianVector(sigma*1.6, GAU2); int half_w1, half_w2, half_l; half_w1 = GAU1.getMax()-1; half_w2 = GAU2.getMax()-1; MakeGaussianVector(sigma3, GAU3); half_l = GAU3.getMax()-1; mymatrix tmp(image_x, image_y); mymatrix dog(image_x, image_y); GetDirectionalDoG(image, e, dog, GAU1, GAU2, tau); GetFlowDoG(e, dog, tmp, GAU3); for (i = 0; i < image_x; i++) { for (j = 0; j < image_y; j++) { image[i][j] = round(tmp[i][j] * 255.); } } }
static void preview_update_preview (GimpPreview *preview, GimpDrawable *drawable) { gint x1, y1; gint width, height; gint bpp; guchar *buffer; GimpPixelRgn src_rgn; GimpPixelRgn preview_rgn; gint32 image_id, src_image_id; gint32 preview_id; GimpDrawable *preview_drawable; bpp = gimp_drawable_bpp (drawable->drawable_id); gimp_preview_get_position (preview, &x1, &y1); gimp_preview_get_size (preview, &width, &height); buffer = g_new (guchar, width * height * bpp); gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, width, height, FALSE, FALSE); gimp_pixel_rgn_get_rect (&src_rgn, buffer, x1, y1, width, height); /* set up gimp drawable for rendering preview into */ src_image_id = gimp_drawable_get_image (drawable->drawable_id); image_id = gimp_image_new (width, height, gimp_image_base_type (src_image_id)); preview_id = gimp_layer_new (image_id, "preview", width, height, gimp_drawable_type (drawable->drawable_id), 100, GIMP_NORMAL_MODE); preview_drawable = gimp_drawable_get (preview_id); gimp_image_add_layer (image_id, preview_id, 0); gimp_layer_set_offsets (preview_id, 0, 0); gimp_pixel_rgn_init (&preview_rgn, preview_drawable, 0, 0, width, height, TRUE, TRUE); gimp_pixel_rgn_set_rect (&preview_rgn, buffer, 0, 0, width, height); gimp_drawable_flush (preview_drawable); gimp_drawable_merge_shadow (preview_id, TRUE); gimp_drawable_update (preview_id, 0, 0, width, height); dog (image_id, preview_drawable, dogvals.inner, dogvals.outer, FALSE); gimp_pixel_rgn_get_rect (&preview_rgn, buffer, 0, 0, width, height); gimp_preview_draw_buffer (preview, buffer, width * bpp); gimp_image_delete (image_id); g_free (buffer); }
main() { printf("Hello World!\n"); int a, b, c; a = 5; b = 7; c = a + b; printf("%d + %d = %d\n", a, b, c); printf ( "Line1\nLine2\nLine3\n" ); dog(); tellmeloc(); return 0; }
// main関数 int main(void) { enum animal selected; do { switch (selected = select()) { case Dog : dog(); break; case Cat : cat(); break; case Monkey : monkey(); break; } } while (selected != Invalid); return (0); }
int main() { Dog dog("Tom"); Cat cat("Jerry"); std::cout << "\n已经诞生了" << Pet::getCount() << "只宠物!\n\n"; { Dog dog_2("Tom_2"); Cat cat_2("Jerry_2"); std::cout << "\n现在呢,已经诞生了" << Pet::getCount() << "只宠物!\n\n"; } std::cout << "\n现在还剩" << Pet::getCount() << "只宠物!\n\n"; return 0; }
int main(int argc, char *argv[]) { Animal* rover = dog("Rover"); Animal* sassy = cat("Sassy"); talk(rover); talk(sassy); Animal buddy; buddy.talk = bark; buddy.name[0] = 'B'; buddy.name[1] = '\0'; buddy.talk(&buddy); free(rover); free(sassy); return 0; }
texture_2d dog_filter(const texture_2d& src, int n, float sigma_e, float sigma_r, float tau, float phi) { texture_2d tmp(src.clone_format()); //texture_2d dst(src.clone_format()); for (int i = 0; i < n; ++i) { texture_2d img = (i == 0)? src : overlay(tmp, src); glsl_program dog("dog_fs.glsl"); dog.use(); dog.bind_sampler("img", img, GL_NEAREST); dog.set_uniform_1f("sigma_e", sigma_e); dog.set_uniform_1f("sigma_r", sigma_r); dog.set_uniform_1f("tau", tau); dog.set_uniform_1f("phi", phi); dog.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height()); dog.draw(&tmp); } return tmp; }
int main() { // These objects will be created then destroyed at program exit rm::WaitForKeypress(">>> Create some animals:"); rm::animals::Animal animal; rm::animals::Cat cat; rm::animals::Dog dog; rm::WaitForKeypress(">>> Make the animals speak:"); animal.speak(); cat.speak(); dog.speak(); // rm::waitForKeypress(">>> Create animals - this will cause Object Slicing:"); // OBJECT SLICING // To prevent Object Slicing the copy constructor, the copy assignment operator, // the move constructor and the move assignment operator have to be deleted // When the above mentioned constructors and the respective assignment operators // were deleted this will cause a compilation error. // std::vector<rm::animals::Animal> slicedAnimals; // for (int i = 0; 10 > i; i++) { // slicedAnimals.push_back(rm::animals::Dog()); // slicedAnimals.push_back(rm::animals::Cat()); // } // rm::waitForKeypress(">>> Make the animals speak - Object Slicing:"); //#ifdef CPP11 // for (rm::animals::Animal& animal: slicedAnimals) { // animal.speak(); // } //#else // for (std::vector<rm::animals::Animal>::iterator currentAnimal = slicedAnimals.begin(); // currentAnimal != slicedAnimals.end(); // ++currentAnimal) { // currentAnimal->speak(); // } //#endif // CPP11 // This won't compile if the copy constructor, the move constructor were deleted // std::vector<Animal> animals; // for (int i = 0; 10 > i; i++) { // Dog dog; // animals.push_back(dog); // Cat cat; // animals.push_back(cat); // } // To prevent Object Slicing: use pointers std::vector<std::unique_ptr<rm::animals::Animal>> animals; rm::WaitForKeypress(">>> Create animals - by using unique_ptr<>:"); for (int i = 0; 10 > i; i++) { std::unique_ptr<rm::animals::Dog> dog(new rm::animals::Dog); std::unique_ptr<rm::animals::Cat> cat(new rm::animals::Cat); animals.push_back(std::move(dog)); animals.push_back(std::move(cat)); } rm::WaitForKeypress(">>> Make the animals speak - No Object Slicing:"); #ifdef CPP11 for (std::unique_ptr<rm::animals::Animal>& animal: animals) { animal->speak(); } #else for (std::vector<rm::animals::Animal>::iterator currentAnimal = animals.begin(); currentAnimal != animals.end(); ++currentAnimal) { currentAnimal->speak(); } #endif // CPP11 // Cannot copy assign because the Animal's copy constructor is deleted // std::vector<std::unique_ptr<rm::animals::Animal>> animalsCopy; // animalsCopy = animals; // All animal objects will be deleted // If they are not deleted in this manner they'll be deleted when the program exits rm::WaitForKeypress(">>> Clear vector<> \"animals\" container:"); animals.clear(); rm::WaitForKeypress(">>> Exit the program"); return 0; }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; gint32 image_ID; GimpDrawable *drawable; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; run_mode = param[0].data.d_int32; INIT_I18N (); *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; /* Get the specified image and drawable */ image_ID = param[1].data.d_image; drawable = gimp_drawable_get (param[2].data.d_drawable); /* set the tile cache size so that the gaussian blur works well */ gimp_tile_cache_ntiles (2 * (MAX (drawable->width, drawable->height) / gimp_tile_width () + 1)); if (strcmp (name, PLUG_IN_PROC) == 0) { switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &dogvals); /* First acquire information with a dialog */ if (! dog_dialog (image_ID, drawable)) return; break; case GIMP_RUN_NONINTERACTIVE: /* Make sure all the arguments are there! */ if (nparams != 7) status = GIMP_PDB_CALLING_ERROR; if (status == GIMP_PDB_SUCCESS) { dogvals.inner = param[3].data.d_float; dogvals.outer = param[4].data.d_float; dogvals.normalize = param[5].data.d_int32; dogvals.invert = param[6].data.d_int32; } if (status == GIMP_PDB_SUCCESS && (dogvals.inner <= 0.0 && dogvals.outer <= 0.0)) status = GIMP_PDB_CALLING_ERROR; break; case GIMP_RUN_WITH_LAST_VALS: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &dogvals); break; default: break; } } else { status = GIMP_PDB_CALLING_ERROR; } if (status == GIMP_PDB_SUCCESS) { /* Make sure that the drawable is gray or RGB color */ if (gimp_drawable_is_rgb (drawable->drawable_id) || gimp_drawable_is_gray (drawable->drawable_id)) { gimp_progress_init (_("DoG Edge Detect")); /* run the Difference of Gaussians */ gimp_image_undo_group_start (image_ID); dog (image_ID, drawable, dogvals.inner, dogvals.outer, TRUE); gimp_image_undo_group_end (image_ID); gimp_progress_update (1.0); /* Store data */ if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PLUG_IN_PROC, &dogvals, sizeof (DoGValues)); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); } else { g_message (_("Cannot operate on indexed color images.")); status = GIMP_PDB_EXECUTION_ERROR; } gimp_drawable_detach (drawable); } values[0].data.d_status = status; }
void _main() { /****************************> Fix Stack <****************************/ //Load a good stack asm( "lis %r1, 0x1ab5 ;" "ori %r1, %r1, 0xd138 ;" ); /****************************> Get Handles <****************************/ //Get a handle to coreinit.rpl unsigned int coreinit_handle, vpad_handle, sysapp_handle, avm_handle; OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); OSDynLoad_Acquire("vpad.rpl", &vpad_handle); OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle); // CreeperMario: Get a handle to the audio/video manager - avm.rpl OSDynLoad_Acquire("avm.rpl", &avm_handle); // STUFF VPADData vpad_data; int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *err); OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead); // Sysapp stuff int(*SYSLaunchMenu)(); OSDynLoad_FindExport(sysapp_handle, 0, "SYSLaunchMenu", &SYSLaunchMenu); // please dont break stuff... int(*SYSLaunchTitle) (int bit1, int bit2); OSDynLoad_FindExport(sysapp_handle, 0, "SYSLaunchTitle", &SYSLaunchTitle); int(*_Exit)(); OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit); /****************************> External Prototypes <****************************/ //OSScreen functions void(*OSScreenInit)(); unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum); unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr); //OS Memory functions void*(*memset)(void * dest, uint32_t value, uint32_t bytes); void*(*OSAllocFromSystem)(uint32_t size, int align); void(*OSFreeToSystem)(void *ptr); //IM functions int(*IM_Open)(); int(*IM_Close)(int fd); int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b); // CreeperMario: TV Screen scaling functions bool(*AVMSetTVScale)(int width, int height); /****************************> Exports <****************************/ //OSScreen functions OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit); OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx); OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx); //OS Memory functions OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset); OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem); OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem); //IM functions OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open); OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close); OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState); // CreeperMario: TV Screen scaling functions OSDynLoad_FindExport(avm_handle, 0, "AVMSetTVScale", &AVMSetTVScale); /*** CreeperMario: Set the TV screen to the proper 'scale factor'. ***/ AVMSetTVScale(854, 480); /****************************> Initial Setup <****************************/ //Restart system to get lib access int fd = IM_Open(); void *mem = OSAllocFromSystem(0x100, 64); memset(mem, 0, 0x100); //set restart flag to force quit browser IM_SetDeviceState(fd, mem, 3, 0, 0); IM_Close(fd); OSFreeToSystem(mem); //wait a bit for browser end unsigned int t1 = 0x15000000; while(t1--) ; //Call the Screen initilzation function. OSScreenInit(); //Grab the buffer size for each screen (TV and gamepad) int buf0_size = OSScreenGetBufferSizeEx(0); int buf1_size = OSScreenGetBufferSizeEx(1); //Set the buffer area. OSScreenSetBufferEx(0, (void *)0xF4000000); OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size); //Clear both framebuffers. doclearstuff(); // Define struct for global variables! struct cGlobals caveGlobals; // Variables n stuff! caveGlobals.food = 0; caveGlobals.row = 1; caveGlobals.col = 1; caveGlobals.level = 1; caveGlobals.dogsteps = 0; caveGlobals.dogalive = 1; caveGlobals.mysteps = 0; caveGlobals.maxhealth = 10; caveGlobals.curhealth = 10; // Start at level 1 (obviously!) changelevel(&caveGlobals); // Draw Buffers and Initial Screen __os_snprintf(caveGlobals.mystat, 64, " "); doclearstuff(); drawstuff(&caveGlobals); flipBuffers(); int err; while(1) { VPADRead(0, &vpad_data, 1, &err); // Quit if (vpad_data.btn_trigger & BUTTON_HOME) { doclearstuff(); __os_snprintf(caveGlobals.endgame, 256, "Thanks for Playing!\nYour Final Level: %d \n\n\nBy: SonyUSA", caveGlobals.level); drawString(0, 0, caveGlobals.endgame); flipBuffers(); t1 = 0x50000000; while(t1--) ; //Maybe fix for exit crash? doclearstuff(); flipBuffers(); doclearstuff(); flipBuffers(); //Ape escape! SYSLaunchMenu(); _Exit(); } //Grab Stuff (A) if (vpad_data.btn_release & BUTTON_A) { //Checks for Food if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 8) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "Got it!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.food += 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 2; drawstuff(&caveGlobals); flipBuffers(); } //Check for Potions if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 11) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "*Gulp!*"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth += 5; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 2; //Make sure we don't go over health limit if (caveGlobals.curhealth > caveGlobals.maxhealth) { caveGlobals.curhealth = caveGlobals.maxhealth; } drawstuff(&caveGlobals); dog(&caveGlobals); flipBuffers(); } //Checks for Stairs if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 9) { caveGlobals.level += 1; doclearstuff(); changelevel(&caveGlobals); drawstuff(&caveGlobals); flipBuffers(); } } //Search for Hidden Traps and Doors if (vpad_data.btn_trigger & BUTTON_Y) { doclearstuff(); drawstuff(&caveGlobals); dog(&caveGlobals); //Ask the player which way to search __os_snprintf(caveGlobals.mystat, 64, "Search Which Way?"); drawString(22, 17, caveGlobals.mystat); flipBuffers(); //Lets use a while loop so players cant just hold down search while they are walking! Cheating gits! while(2) { VPADRead(0, &vpad_data, 1, &err); // Search Up if (vpad_data.btn_release & BUTTON_UP) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } // Search Down if (vpad_data.btn_release & BUTTON_DOWN) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } // Search Right if (vpad_data.btn_release & BUTTON_RIGHT) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } // Search Left if (vpad_data.btn_release & BUTTON_LEFT) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } } } //Open and Close Doors (X + Direction) if (vpad_data.btn_hold & BUTTON_X) { if (vpad_data.btn_trigger & BUTTON_DOWN) { if (isclosedoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 4; flipBuffers(); } } if (vpad_data.btn_trigger & BUTTON_UP) { if (isclosedoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 4; flipBuffers(); } } if (vpad_data.btn_trigger & BUTTON_LEFT) { if (isclosedoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 4; flipBuffers(); } } if (vpad_data.btn_trigger & BUTTON_RIGHT) { if (isclosedoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 4; flipBuffers(); } } } // Movement //Down if (vpad_data.btn_trigger & BUTTON_DOWN) { if (canmove(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.col += 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Up if (vpad_data.btn_trigger & BUTTON_UP) { if (canmove(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.col -= 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Left if (vpad_data.btn_trigger & BUTTON_LEFT) { if (canmove(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.row -= 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Right if (vpad_data.btn_trigger & BUTTON_RIGHT) { if (canmove(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.row += 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Feed the doggy if (vpad_data.btn_trigger & BUTTON_PLUS) { if (caveGlobals.dogalive == 1) { if (caveGlobals.food >= 1) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "*crunch* Woof!"); drawString(24, 17, caveGlobals.mystat); caveGlobals.food -= 1; caveGlobals.dogsteps -= 60; //Make sure we don't go negative in dog health if (caveGlobals.dogsteps <= 0) { caveGlobals.dogsteps = 0;} drawstuff(&caveGlobals); dog(&caveGlobals); flipBuffers(); } } } // Check if the player is dead if(caveGlobals.curhealth == 0) { doclearstuff(); __os_snprintf(caveGlobals.endgame, 256, "You're Dead!\nNow how will you get iosu? :/ \n\nThanks for Playing! \n\n\nBy: SonyUSA"); drawString(0, 0, caveGlobals.endgame); flipBuffers(); t1 = 0x80000000; while(t1--) ; SYSLaunchMenu(); _Exit(); } // Cheat and go to next level with Minus key if(vpad_data.btn_release & BUTTON_MINUS) { caveGlobals.level += 1; doclearstuff(); changelevel(&caveGlobals); drawstuff(&caveGlobals); flipBuffers(); } } }
TEST(VariadicTemplate, VariadicPrintf) { using Dog = smart_pointer::Dog; Dog dog("Henry"); vPrint("hello\n", std::string("world\n"), 'h', '\n', 10, '\n', 11.111, '\n', dog, '\n'); }
int main() { // setup window sf::Vector2i screenDimensions(576,272); sf::RenderWindow window(sf::VideoMode(screenDimensions.x, screenDimensions.y), "Rainsford"); window.setFramerateLimit(60); sf::Vector2f scaler(screenDimensions.x/72, screenDimensions.y/34); /*background setup There are 3 copies of each background layer (z-score), one is drawn in left and one is drawn right of the default background that is automatically drawn. After the any of the 3 copies moves its entire width left (position.x is negative width) it is assigned position.x = positive width. This "shuffles" the copies and gives an illusion of continuity. */ sf::RectangleShape titlescreen (sf::Vector2f(screenDimensions.x, screenDimensions.y)); sf::Texture title; if (!title.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Rainsford Titlescreen.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } titlescreen.setTexture(&title); // texture is a sf::Texture titlescreen.setTextureRect(sf::IntRect(0, 0, 576,272)); sf::RectangleShape titleback (sf::Vector2f(screenDimensions.x, screenDimensions.y)); sf::Texture titlebackTex; if (!titlebackTex.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Titleback.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } titleback.setTexture(&titlebackTex); // texture is a sf::Texture titleback.setTextureRect(sf::IntRect(0, 0, 576,272)); sf::RectangleShape moon (sf::Vector2f(screenDimensions.x, screenDimensions.y)); sf::Texture moonT; if (!moonT.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Moon.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } moon.setTexture(&moonT); // texture is a sf::Texture moon.setTextureRect(sf::IntRect(0, 0, 576,272)); //back1 sf::RectangleShape back1(sf::Vector2f(72,34)); sf::Texture textureBack1; if (!textureBack1.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background1.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back1.setTexture(&textureBack1); // texture is a sf::Texture back1.setTextureRect(sf::IntRect(0, 0, 72,34)); //back2 sf::RectangleShape back2(sf::Vector2f(128,32)); sf::Texture textureBack2; if (!textureBack2.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background2.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back2.setTexture(&textureBack2); // texture is a sf::Texture back2.setTextureRect(sf::IntRect(0, 0, 128,32)); sf::RectangleShape back2a(sf::Vector2f(128,32)); back2a.setTexture(&textureBack2); // texture is a sf::Texture back2a.setTextureRect(sf::IntRect(0, 0, 128,32)); back2a.setPosition(-128*8, 0); sf::RectangleShape back2b(sf::Vector2f(128,32)); back2b.setTexture(&textureBack2); // texture is a sf::Texture back2b.setTextureRect(sf::IntRect(0, 0, 128,32)); back2b.setPosition(128*8, 0); //back3 sf::RectangleShape back3(sf::Vector2f(128,32)); sf::Texture textureBack3; if (!textureBack3.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background3.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back3.setTexture(&textureBack3); // texture is a sf::Texture back3.setTextureRect(sf::IntRect(0, 0, 128,32)); sf::RectangleShape back3a(sf::Vector2f(128,32)); back3a.setTexture(&textureBack3); // texture is a sf::Texture back3a.setTextureRect(sf::IntRect(0, 0, 128,32)); back3a.setPosition(-128*8, 0); sf::RectangleShape back3b(sf::Vector2f(128,32)); back3b.setTexture(&textureBack3); // texture is a sf::Texture back3b.setTextureRect(sf::IntRect(0, 0, 128,32)); back3b.setPosition(128*8, 0); //back4 sf::RectangleShape back4(sf::Vector2f(112,32)); sf::Texture textureBack4; if (!textureBack4.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background4.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back4.setTexture(&textureBack4); // texture is a sf::Texture back4.setTextureRect(sf::IntRect(0, 0, 112,32)); sf::RectangleShape back4a(sf::Vector2f(112,32)); back4a.setTexture(&textureBack4); // texture is a sf::Texture back4a.setTextureRect(sf::IntRect(0, 0, 112,32)); back4a.setPosition(-112*8, 0); sf::RectangleShape back4b(sf::Vector2f(112,32)); back4b.setTexture(&textureBack4); // texture is a sf::Texture back4b.setTextureRect(sf::IntRect(0, 0, 112,32)); back4b.setPosition(112*8, 0); //back5 sf::RectangleShape back5(sf::Vector2f(96,32)); sf::Texture textureBack5; if (!textureBack5.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background5.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back5.setTexture(&textureBack5); // texture is a sf::Texture back5.setTextureRect(sf::IntRect(0, 0, 96,32)); sf::RectangleShape back5a(sf::Vector2f(96,32)); back5a.setTexture(&textureBack5); // texture is a sf::Texture back5a.setTextureRect(sf::IntRect(0, 0, 96,32)); back5a.setPosition(-96*8, 0); sf::RectangleShape back5b(sf::Vector2f(96,32)); back5b.setTexture(&textureBack5); // texture is a sf::Texture back5b.setTextureRect(sf::IntRect(0, 0, 96,32)); back5b.setPosition(96*8, 0); //back6 sf::RectangleShape back6(sf::Vector2f(72,32)); sf::Texture textureBack6; if (!textureBack6.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Background6.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } back6.setTexture(&textureBack6); // texture is a sf::Texture back6.setTextureRect(sf::IntRect(0, 0, 72,32)); sf::RectangleShape back6a(sf::Vector2f(72,32)); back6a.setTexture(&textureBack6); // texture is a sf::Texture back6a.setTextureRect(sf::IntRect(0, 0, 72,32)); back6a.setPosition(-72*8, 0); sf::RectangleShape back6b(sf::Vector2f(72,32)); back6b.setTexture(&textureBack6); // texture is a sf::Texture back6b.setTextureRect(sf::IntRect(0, 0, 72,32)); back6b.setPosition(72*8, 0); //moonlight sf::RectangleShape moonlight(sf::Vector2f(96,32)); sf::Texture textureMoon; if (!textureMoon.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Moonlight.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } moonlight.setTexture(&textureMoon); // texture is a sf::Texture moonlight.setTextureRect(sf::IntRect(0, 0, 96,32)); sf::RectangleShape moonlighta(sf::Vector2f(96,32)); moonlighta.setTexture(&textureBack6); // texture is a sf::Texture moonlighta.setTextureRect(sf::IntRect(0, 0, 96,32)); moonlighta.setPosition(-96*8, 0); sf::RectangleShape moonlightb(sf::Vector2f(96,32)); moonlightb.setTexture(&textureMoon); // texture is a sf::Texture moonlightb.setTextureRect(sf::IntRect(0, 0, 96,32)); moonlightb.setPosition(96*8, 0); //vines sf::RectangleShape vines(sf::Vector2f(96,32)); sf::Texture textureVines; if (!textureVines.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Vines.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } vines.setTexture(&textureVines); // texture is a sf::Texture vines.setTextureRect(sf::IntRect(0, 0, 96,32)); sf::RectangleShape vinesa(sf::Vector2f(96,32)); vinesa.setTexture(&textureVines); // texture is a sf::Texture vinesa.setTextureRect(sf::IntRect(0, 0, 96,32)); vinesa.setPosition(-96*8, 0); sf::RectangleShape vinesb(sf::Vector2f(96,32)); vinesb.setTexture(&textureVines); // texture is a sf::Texture vinesb.setTextureRect(sf::IntRect(0, 0, 96,32)); vinesb.setPosition(96*8, 0); //end of backgrounds *********************************************************** back1.scale(scaler); back2.scale(scaler); back3.scale(scaler); back4.scale(scaler); back5.scale(scaler); back6.scale(scaler); vines.scale(scaler); back2a.scale(scaler); back3a.scale(scaler); back4a.scale(scaler); back5a.scale(scaler); back6a.scale(scaler); vinesa.scale(scaler); back2b.scale(scaler); back3b.scale(scaler); back4b.scale(scaler); back5b.scale(scaler); back6b.scale(scaler); vinesb.scale(scaler); moonlight.scale(scaler); moonlighta.scale(scaler); moonlightb.scale(scaler); //flickering stormlamp spritesheet sf::Texture stormLamp; if (!stormLamp.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/RainsfordStormLamp_Spritesheet.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } Animation flicker; flicker.setSpriteSheet(stormLamp); flicker.addFrame(sf::IntRect (0, 0, 160, 90)); flicker.addFrame(sf::IntRect (0, 90, 160, 90)); flicker.addFrame(sf::IntRect (0, 180, 160, 90)); flicker.addFrame(sf::IntRect (0, 90, 160, 90)); AnimatedSprite flickerSprite(sf::seconds(.3), true, false); flickerSprite.scale(scaler); flickerSprite.setPosition(((-160/scaler.x)*18), -120*scaler.y/4); //IVAN STUFF // load texture (spritesheet) sf::Texture textureIvan; if (!textureIvan.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Ivan.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } // set up the animations for all four directions (set spritesheet and push frames) Animation ivan_standingRight; ivan_standingRight.setSpriteSheet(textureIvan); ivan_standingRight.addFrame(sf::IntRect(0, 0, 8, 8)); ivan_standingRight.addFrame(sf::IntRect(8, 0, 8, 8)); ivan_standingRight.addFrame(sf::IntRect(16, 0, 8, 8)); ivan_standingRight.addFrame(sf::IntRect( 24, 0, 8, 8)); ivan_standingRight.addFrame(sf::IntRect(32, 0, 8, 8)); ivan_standingRight.addFrame(sf::IntRect( 40, 0, 8, 8)); Animation ivan_standingLeft; ivan_standingLeft.setSpriteSheet(textureIvan); ivan_standingLeft.addFrame(sf::IntRect(0, 8, 8, 8)); ivan_standingLeft.addFrame(sf::IntRect(8, 8, 8, 8)); ivan_standingLeft.addFrame(sf::IntRect(16, 8, 8, 8)); ivan_standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8)); ivan_standingLeft.addFrame(sf::IntRect(32, 8, 8, 8)); ivan_standingLeft.addFrame(sf::IntRect(40, 8, 8, 8)); Animation ivan_walkingRight; ivan_walkingRight.setSpriteSheet(textureIvan); ivan_walkingRight.addFrame(sf::IntRect(0, 16, 8, 8)); ivan_walkingRight.addFrame(sf::IntRect(8, 16, 8, 8)); ivan_walkingRight.addFrame(sf::IntRect(16, 16, 8, 8)); ivan_walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8)); ivan_walkingRight.addFrame(sf::IntRect(32, 16, 8, 8)); ivan_walkingRight.addFrame(sf::IntRect( 40, 16, 8, 8)); Animation ivan_walkingLeft; ivan_walkingLeft.setSpriteSheet(textureIvan); ivan_walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8)); ivan_walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8)); ivan_walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8)); ivan_walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8)); ivan_walkingLeft.addFrame(sf::IntRect(32, 24, 8, 8)); ivan_walkingLeft.addFrame(sf::IntRect( 40, 24, 8, 8)); Animation* currentIvanAnimation = &ivan_standingRight; AnimatedSprite ivan(sf::seconds(.07), true, false); ivan.setPosition(sf::Vector2f(screenDimensions.x / 2 - 264, 192)); ivan.scale(scaler); // DOG load texture (spritesheet) sf::Texture textureDog; if (!textureDog.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Dog.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } //dog spritesheet animation setup Animation dog_standingRight; dog_standingRight.setSpriteSheet(textureDog); dog_standingRight.addFrame(sf::IntRect(0, 0, 8, 8)); dog_standingRight.addFrame(sf::IntRect(8, 0, 8, 8)); dog_standingRight.addFrame(sf::IntRect(16, 0, 8, 8)); dog_standingRight.addFrame(sf::IntRect( 24, 0, 8, 8)); Animation dog_standingLeft; dog_standingLeft.setSpriteSheet(textureDog); dog_standingLeft.addFrame(sf::IntRect(0, 8, 8, 8)); dog_standingLeft.addFrame(sf::IntRect(8, 8, 8, 8)); dog_standingLeft.addFrame(sf::IntRect(16, 8, 8, 8)); dog_standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8)); Animation dog_walkingRight; dog_walkingRight.setSpriteSheet(textureDog); dog_walkingRight.addFrame(sf::IntRect(0, 16, 8, 8)); dog_walkingRight.addFrame(sf::IntRect(8, 16, 8, 8)); dog_walkingRight.addFrame(sf::IntRect(16, 16, 8, 8)); dog_walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8)); Animation dog_walkingLeft; dog_walkingLeft.setSpriteSheet(textureDog); dog_walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8)); dog_walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8)); dog_walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8)); dog_walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8)); Animation dog_walkingRightHostile; dog_walkingRightHostile.setSpriteSheet(textureDog); dog_walkingRightHostile.addFrame(sf::IntRect(0, 32, 8, 8)); dog_walkingRightHostile.addFrame(sf::IntRect(8, 32, 8, 8)); dog_walkingRightHostile.addFrame(sf::IntRect(16, 32, 8, 8)); dog_walkingRightHostile.addFrame(sf::IntRect( 24, 32, 8, 8)); Animation dog_walkingLeftHostile; dog_walkingLeftHostile.setSpriteSheet(textureDog); dog_walkingLeftHostile.addFrame(sf::IntRect(0, 40, 8, 8)); dog_walkingLeftHostile.addFrame(sf::IntRect(8, 40, 8, 8)); dog_walkingLeftHostile.addFrame(sf::IntRect(16, 40, 8, 8)); dog_walkingLeftHostile.addFrame(sf::IntRect( 24, 40, 8, 8)); Animation* currentDogAnimation = &dog_standingRight; AnimatedSprite dog(sf::seconds(.07), true, false); dog.setPosition(sf::Vector2f(screenDimensions.x / 2 - 200, 192)); dog.scale(scaler); // load texture (spritesheet) sf::Texture texture; if (!texture.loadFromFile("/Users/Bloopton/Desktop/Programs/TestAnimation/TestAnimation/Spritesheet_Rainsford.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; return 1; } // set up the animations for all directions (set spritesheet and push frames) Animation standingRight; standingRight.setSpriteSheet(texture); standingRight.addFrame(sf::IntRect(0, 0, 8, 8)); standingRight.addFrame(sf::IntRect(8, 0, 8, 8)); standingRight.addFrame(sf::IntRect(16, 0, 8, 8)); standingRight.addFrame(sf::IntRect( 24, 0, 8, 8)); // standingRight.addFrame(sf::IntRect(32, 0, 8, 8)); // standingRight.addFrame(sf::IntRect( 40, 0, 8, 8)); Animation standingLeft; standingLeft.setSpriteSheet(texture); standingLeft.addFrame(sf::IntRect(0, 8, 8, 8)); standingLeft.addFrame(sf::IntRect(8, 8, 8, 8)); standingLeft.addFrame(sf::IntRect(16, 8, 8, 8)); standingLeft.addFrame(sf::IntRect( 24, 8, 8, 8)); // standingLeft.addFrame(sf::IntRect(32, 8, 8, 8)); // standingLeft.addFrame(sf::IntRect(40, 8, 8, 8)); Animation walkingRight; walkingRight.setSpriteSheet(texture); walkingRight.addFrame(sf::IntRect(0, 16, 8, 8)); walkingRight.addFrame(sf::IntRect(8, 16, 8, 8)); walkingRight.addFrame(sf::IntRect(16, 16, 8, 8)); walkingRight.addFrame(sf::IntRect( 24, 16, 8, 8)); //walkingRight.addFrame(sf::IntRect(32, 16, 8, 8)); //walkingRight.addFrame(sf::IntRect( 40, 16, 8, 8)); Animation walkingLeft; walkingLeft.setSpriteSheet(texture); walkingLeft.addFrame(sf::IntRect(0, 24, 8, 8)); walkingLeft.addFrame(sf::IntRect(8, 24, 8, 8)); walkingLeft.addFrame(sf::IntRect(16, 24, 8, 8)); walkingLeft.addFrame(sf::IntRect( 24, 24, 8, 8)); //walkingLeft.addFrame(sf::IntRect(32, 24, 8, 8)); //walkingLeft.addFrame(sf::IntRect( 40, 24, 8, 8)); Animation jumpingRight; jumpingRight.setSpriteSheet(texture); jumpingRight.addFrame(sf::IntRect(0, 32, 8, 8)); jumpingRight.addFrame(sf::IntRect(8, 32, 8, 8)); jumpingRight.addFrame(sf::IntRect(16, 32, 8, 8)); jumpingRight.addFrame(sf::IntRect( 24, 32, 8, 8)); //jumpingRight.addFrame(sf::IntRect(32, 32, 8, 8)); //jumpingRight.addFrame(sf::IntRect( 40, 32, 8, 8)); Animation jumpingLeft; jumpingLeft.setSpriteSheet(texture); jumpingLeft.addFrame(sf::IntRect(0, 40, 8, 8)); jumpingLeft.addFrame(sf::IntRect(8, 40, 8, 8)); jumpingLeft.addFrame(sf::IntRect(16, 40, 8, 8)); jumpingLeft.addFrame(sf::IntRect( 24, 40, 8, 8)); //jumpingLeft.addFrame(sf::IntRect(32, 40, 8, 8)); //jumpingLeft.addFrame(sf::IntRect( 40, 40, 8, 8)); Animation crawlingRight; crawlingRight.setSpriteSheet(texture); crawlingRight.addFrame(sf::IntRect(0, 64, 8, 8)); crawlingRight.addFrame(sf::IntRect(8, 64, 8, 8)); crawlingRight.addFrame(sf::IntRect(16, 64, 8, 8)); crawlingRight.addFrame(sf::IntRect( 24, 64, 8, 8)); //jumpingRight.addFrame(sf::IntRect(32, 32, 8, 8)); //jumpingRight.addFrame(sf::IntRect( 40, 32, 8, 8)); Animation crawlingLeft; crawlingLeft.setSpriteSheet(texture); crawlingLeft.addFrame(sf::IntRect(0, 72, 8, 8)); crawlingLeft.addFrame(sf::IntRect(8, 72, 8, 8)); crawlingLeft.addFrame(sf::IntRect(16, 72, 8, 8)); crawlingLeft.addFrame(sf::IntRect( 24, 72, 8, 8)); //jumpingLeft.addFrame(sf::IntRect(32, 40, 8, 8)); //jumpingLeft.addFrame(sf::IntRect( 40, 40, 8, 8)); Animation disguise1; disguise1.setSpriteSheet(texture); disguise1.addFrame(sf::IntRect(0, 48, 8, 8)); Animation disguise2; disguise2.setSpriteSheet(texture); disguise2.addFrame(sf::IntRect(8, 48, 8, 8)); Animation disguise3; disguise3.setSpriteSheet(texture); disguise3.addFrame(sf::IntRect(16, 48, 8, 8)); Animation disguise4; disguise4.setSpriteSheet(texture); disguise4.addFrame(sf::IntRect(24, 48, 8, 8)); Animation crouchedRight; crouchedRight.setSpriteSheet(texture); crouchedRight.addFrame(sf::IntRect(0, 56, 8, 8)); Animation crouchedLeft; crouchedLeft.setSpriteSheet(texture); crouchedLeft.addFrame(sf::IntRect(8, 56, 8, 8)); Animation* currentAnimation = &standingRight; float rainsfordAnimationSpeed = .07; // set up AnimatedSprite AnimatedSprite animatedSprite(sf::seconds(rainsfordAnimationSpeed), true, false); animatedSprite.setPosition(sf::Vector2f(screenDimensions.x / 2 - 64, 192)); animatedSprite.scale(scaler); sf::Clock frameClock; float speed = 650.f; bool noKeyWasPressed = true; enum direction { left, right}; direction currentDir = right; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) window.close(); } sf::Time frameTime = frameClock.restart(); // if a key was pressed set the correct animation and move correctly sf::Vector2f movement(0.f, 0.f); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { if(currentDir == left) { currentAnimation = &jumpingLeft; noKeyWasPressed = false; } if(currentDir == right) { currentAnimation = &jumpingRight; noKeyWasPressed = false; } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { currentAnimation = &crawlingLeft; currentDogAnimation = &dog_walkingLeft; //DOG ANIMATION currentIvanAnimation = &ivan_walkingLeft; //Ivan ANIMATION movement.x += .2*speed; noKeyWasPressed = false; currentDir = left; } else { currentAnimation = &walkingLeft; currentDogAnimation = &dog_walkingLeftHostile; //DOG ANIMATION currentIvanAnimation = &ivan_walkingLeft; //Ivan ANIMATION movement.x += speed; noKeyWasPressed = false; currentDir = left; } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { currentAnimation = &crawlingRight; currentDogAnimation = &dog_walkingRight; //DOG ANIMATION currentIvanAnimation = &ivan_walkingRight; //Ivan ANIMATION movement.x -= .2*speed; noKeyWasPressed = false; currentDir = right; } else { currentAnimation = &walkingRight; currentDogAnimation = &dog_walkingRightHostile; //DOG ANIMATION currentIvanAnimation = &ivan_walkingRight; //Ivan ANIMATION movement.x -= speed; noKeyWasPressed = false; currentDir = right; } } } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { if(currentDir == left) { currentAnimation = &crouchedLeft; noKeyWasPressed = false; } if(currentDir == right) { currentAnimation = &crouchedRight; noKeyWasPressed = false; } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) { currentAnimation = &disguise1; noKeyWasPressed = false; movement.x = 0; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::R)) { currentAnimation = &disguise2; noKeyWasPressed = false; movement.x = 0; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::T)) { currentAnimation = &disguise3; noKeyWasPressed = false; movement.x = 0; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Y)) { currentAnimation = &disguise4; noKeyWasPressed = false; movement.x = 0; } // if no key was pressed if (noKeyWasPressed) { sf::Time slowerFrameTime = sf::seconds(.3); animatedSprite.setFrameTime(slowerFrameTime); dog.setFrameTime(slowerFrameTime); //DOG WUZ HERE ivan.setFrameTime(slowerFrameTime); //IVAn if (currentDir == left) { currentAnimation = &standingLeft; currentDogAnimation = &dog_standingLeft;// DAWG HERE TOO DOG currentIvanAnimation = &ivan_standingLeft;// IVAN } if (currentDir == right) { currentAnimation = &standingRight; currentDogAnimation = &dog_standingRight; // DAWG HERE TOO 2 DOG currentIvanAnimation = &ivan_standingRight;// IVAN } } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { animatedSprite.setFrameTime(sf::seconds(.15)); dog.setFrameTime(sf::seconds(.15));//DOOOOOOOGGGGEEE DOG ivan.setFrameTime(sf::seconds(.15));//IVAN } else { animatedSprite.setFrameTime(sf::seconds(.07)); dog.setFrameTime(sf::seconds(.07));//DOOOOOOOGGGGEEEDOOOOOOOGGGGEEEDOOOOOOOGGGGEEE DOG ivan.setFrameTime(sf::seconds(.07));//IVAN } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { //EDGE EFFECT HERE if (back2.getPosition().x <= back2.getSize().x*-8) { back2.setPosition(back2.getSize().x*8, 0); } if (back2a.getPosition().x <= back2a.getSize().x*-8) { back2a.setPosition(back2a.getSize().x*8, 0); } if (back2b.getPosition().x <= back2b.getSize().x*-8) { back2b.setPosition(back2b.getSize().x*8, 0); } if (back3.getPosition().x <= back3.getSize().x*-8) { back3.setPosition(back3.getSize().x*8, 0); } if (back3a.getPosition().x <= back3a.getSize().x*-8) { back3a.setPosition(back3a.getSize().x*8, 0); } if (back3b.getPosition().x <= back3b.getSize().x*-8) { back3b.setPosition(back3b.getSize().x*8, 0); } if (back4.getPosition().x <= back4.getSize().x*-8) { back4.setPosition(back4.getSize().x*8, 0); } if (back4a.getPosition().x <= back4a.getSize().x*-8) { back4a.setPosition(back4a.getSize().x*8, 0); } if (back4b.getPosition().x <= back4b.getSize().x*-8) { back4b.setPosition(back4b.getSize().x*8, 0); } if (back5.getPosition().x <= back5.getSize().x*-8) { back5.setPosition(back5.getSize().x*8, 0); } if (back5a.getPosition().x <= back5a.getSize().x*-8) { back5a.setPosition(back5a.getSize().x*8, 0); } if (back5b.getPosition().x <= back5b.getSize().x*-8) { back5b.setPosition(back5b.getSize().x*8, 0); } if (back6.getPosition().x <= back6.getSize().x*-8) { back6.setPosition(back6.getSize().x*8, 0); } if (back6a.getPosition().x <= back6a.getSize().x*-8) { back6a.setPosition(back6a.getSize().x*8, 0); } if (back6b.getPosition().x <= back6b.getSize().x*-8) { back6b.setPosition(back6b.getSize().x*8, 0); } //vines if (vines.getPosition().x <= vines.getSize().x*-8) { vines.setPosition(vines.getSize().x*8, 0); } if (vinesa.getPosition().x <= vinesa.getSize().x*-8) { vinesa.setPosition(vinesa.getSize().x*8, 0); } if (vinesb.getPosition().x <= vinesb.getSize().x*-8) { vinesb.setPosition(vinesb.getSize().x*8, 0); } //moonlight if (moonlight.getPosition().x <= moonlight.getSize().x*-8) { moonlight.setPosition(moonlight.getSize().x*8, 0); } if (moonlighta.getPosition().x <= moonlighta.getSize().x*-8) { moonlighta.setPosition(moonlighta.getSize().x*8, 0); } if (moonlightb.getPosition().x <= moonlightb.getSize().x*-8) { moonlightb.setPosition(moonlightb.getSize().x*8, 0); } } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { //positive /* if (back2.getPosition().x >= back2.getSize().x*8) { back2.setPosition(back2.getSize().x*-8, 0); } if (back2a.getPosition().x >= back2a.getSize().x*8) { back2a.setPosition(back2a.getSize().x*-8, 0); } if (back2b.getPosition().x >= back2b.getSize().x*8) { back2b.setPosition(back2b.getSize().x*-8, 0); } if (back3.getPosition().x >= back3.getSize().x*8) { back3.setPosition(back3.getSize().x*-8, 0); } if (back3a.getPosition().x >= back3a.getSize().x*8) { back3a.setPosition(back3a.getSize().x*-8, 0); } if (back3b.getPosition().x >= back3b.getSize().x*8) { back3b.setPosition(back3b.getSize().x*-8, 0); } */ if (back4.getPosition().x >= back4.getSize().x*8) { back4.setPosition(back4.getSize().x*-8, 0); } if (back4a.getPosition().x >= back4a.getSize().x*8) { back4a.setPosition(back4a.getSize().x*-8, 0); } if (back4b.getPosition().x >= back4b.getSize().x*8) { back4b.setPosition(back4b.getSize().x*-8, 0); } if (back5.getPosition().x >= back5.getSize().x*8) { back5.setPosition(back5.getSize().x*-8, 0); } if (back5a.getPosition().x >= back5a.getSize().x*8) { back5a.setPosition(back5a.getSize().x*-8, 0); } if (back5b.getPosition().x >= back5b.getSize().x*8) { back5b.setPosition(back5b.getSize().x*-8, 0); } if (back6.getPosition().x >= back6.getSize().x*8) { back6.setPosition(back6.getSize().x*-8, 0); } if (back6a.getPosition().x >= back6a.getSize().x*8) { back6a.setPosition(back6a.getSize().x*-8, 0); } if (back6b.getPosition().x >= back6b.getSize().x*8) { back6b.setPosition(back6b.getSize().x*-8, 0); } //vines if (vines.getPosition().x >= vines.getSize().x*8) { vines.setPosition(vines.getSize().x*-8, 0); } if (vinesa.getPosition().x >= vinesa.getSize().x*8) { vinesa.setPosition(vinesa.getSize().x*-8, 0); } if (vinesb.getPosition().x >= vinesb.getSize().x*8) { vinesb.setPosition(vinesb.getSize().x*-8, 0); } //moonlight if (moonlight.getPosition().x >= moonlight.getSize().x*8) { moonlight.setPosition(moonlight.getSize().x*-8, 0); } if (moonlighta.getPosition().x >= moonlighta.getSize().x*8) { moonlighta.setPosition(moonlighta.getSize().x*-8, 0); } if (moonlightb.getPosition().x >= moonlightb.getSize().x*8) { moonlightb.setPosition(moonlightb.getSize().x*-8, 0); } } float timeMov = 1; timeMov = frameTime.asSeconds(); ivan.play(*currentIvanAnimation); dog.play(*currentDogAnimation);//dog animation here animatedSprite.play(*currentAnimation); flickerSprite.play(flicker); animatedSprite.move(0,0); back2.move(-16 * timeMov, 0); back3.move(-32 * timeMov, 0); back4.move(.3*movement.x * timeMov, 0); moonlight.move(.45*movement.x * timeMov, 0); back5.move(.55*movement.x * timeMov, 0); vines.move(.65*movement.x * timeMov, 0); back6.move(.8*movement.x * timeMov, 0); back2a.move(-16 * timeMov, 0); back3a.move(-32 * timeMov, 0); back4a.move(.3*movement.x * timeMov, 0); moonlighta.move(.45*movement.x * timeMov, 0); back5a.move(.55*movement.x * timeMov, 0); vinesa.move(.65*movement.x * timeMov, 0); back6a.move(.8*movement.x * timeMov, 0); back2b.move(-16 * timeMov, 0); back3b.move(-32 * timeMov, 0); back4b.move(.3*movement.x * timeMov, 0); moonlightb.move(.45*movement.x * timeMov, 0); back5b.move(.55*movement.x * timeMov, 0); vinesb.move(.65*movement.x * timeMov, 0); back6b.move(.8*movement.x * timeMov, 0); noKeyWasPressed = true; // update AnimatedSprite dog.update(frameTime);//dog ivan.update(frameTime);//ivan animatedSprite.update(frameTime); flickerSprite.update(sf::seconds(.03f)); // draw window.clear(); window.draw(titleback); window.draw(moon); //window.draw(back1); window.draw(back2); window.draw(back2a); window.draw(back2b); window.draw(back3); window.draw(back3a); window.draw(back3b); /*window.draw(back4); window.draw(back4a); window.draw(back4b); window.draw(back5); window.draw(back5a); window.draw(back5b); window.draw(back6); window.draw(back6a); window.draw(back6b); window.draw(animatedSprite); window.draw(dog);//dog window.draw(ivan);//ivan */ window.draw(titlescreen); int flickerCounter = 0; if (sf::Keyboard::isKeyPressed(sf::Keyboard::F)) { if(flickerCounter==0) flickerCounter++; else flickerCounter--; } if(flickerCounter!=0) window.draw(flickerSprite); window.display(); } return 0; }
//***************************************************************************************** void CBCGPSliderCtrl::OnDraw(CDC* pDCIn) { CBCGPMemDC memDC (*pDCIn, this); CDC* pDC = &memDC.GetDC (); if (!CBCGPVisualManager::GetInstance ()->OnFillParentBarBackground (this, pDC)) { globalData.DrawParentBackground (this, pDC, NULL); } DWORD dwStyle = GetStyle (); BOOL bVert = (dwStyle & TBS_VERT); BOOL bLeftTop = (dwStyle & TBS_BOTH) || (dwStyle & TBS_LEFT); BOOL bRightBottom = (dwStyle & TBS_BOTH) || ((dwStyle & TBS_LEFT) == 0); BOOL bIsFocused = GetSafeHwnd () == ::GetFocus (); CRect rectChannel; GetChannelRect (rectChannel); if (bVert) { CRect rect = rectChannel; rectChannel.left = rect.top; rectChannel.right = rect.bottom; rectChannel.top = rect.left; rectChannel.bottom = rect.right; } CBCGPDrawOnGlass dog(m_bOnGlass); CBCGPVisualManager::GetInstance ()->OnDrawSliderChannel (pDC, this, bVert, rectChannel, m_bOnGlass); CRect rectThumb; GetThumbRect (rectThumb); int nTicSize = max(3, (bVert ? rectThumb.Height() : rectThumb.Width()) / 3); int nTicOffset = 2; int nNumTics = GetNumTics(); for (int i = 0; i < nNumTics; i++) { int nTicPos = GetTicPos(i); if (nTicPos < 0) { if (i == nNumTics - 2) { if (bVert) { nTicPos = rectChannel.top + rectThumb.Height() / 2; } else { nTicPos = rectChannel.left + rectThumb.Width() / 2; } } else if (i == nNumTics - 1) { if (bVert) { nTicPos = rectChannel.bottom - rectThumb.Height() / 2 - 1; } else { nTicPos = rectChannel.right - rectThumb.Width() / 2 - 1; } } } if (nTicPos >= 0) { CRect rectTic1(0, 0, 0, 0); CRect rectTic2(0, 0, 0, 0); if (bVert) { if (bLeftTop) { rectTic1 = CRect(rectThumb.left - nTicOffset - nTicSize, nTicPos, rectThumb.left - nTicOffset, nTicPos + 1); } if (bRightBottom) { rectTic2 = CRect(rectThumb.right + nTicOffset, nTicPos, rectThumb.right + nTicOffset + nTicSize, nTicPos + 1); } } else { if (bLeftTop) { rectTic1 = CRect(nTicPos, rectThumb.top - nTicOffset - nTicSize, nTicPos + 1, rectThumb.top - nTicOffset); } if (bRightBottom) { rectTic2 = CRect(nTicPos, rectThumb.bottom + nTicOffset, nTicPos + 1, rectThumb.bottom + nTicOffset + nTicSize); } } if (!rectTic1.IsRectEmpty()) { CBCGPVisualManager::GetInstance ()->OnDrawSliderTic(pDC, this, rectTic1, bVert, TRUE, m_bOnGlass); } if (!rectTic2.IsRectEmpty()) { CBCGPVisualManager::GetInstance ()->OnDrawSliderTic(pDC, this, rectTic2, bVert, FALSE, m_bOnGlass); } } } CBCGPVisualManager::GetInstance ()->OnDrawSliderThumb ( pDC, this, rectThumb, m_bIsThumbHighligted || bIsFocused, m_bIsThumPressed, !IsWindowEnabled (), bVert, bLeftTop, bRightBottom, m_bOnGlass); if (bIsFocused && m_bDrawFocus) { CRect rectFocus; GetClientRect (rectFocus); if (m_bOnGlass) { CBCGPDrawManager dm (*pDC); dm.DrawFocusRect(rectFocus); } else { pDC->DrawFocusRect (rectFocus); } } }