int main() { sf::RenderWindow window(sf::VideoMode(300, 200), "Thor Animation"); window.setVerticalSyncEnabled(true); window.setKeyRepeatEnabled(false); sf::Font font; if (!font.loadFromFile("Media/sansation.ttf")) return 1; // Instruction text sf::Text instructions( "W: Play walk animation (loop)\n" "A: Play attack animation\n" "S: Stop current animation\n" "Esc: Quit", font, 14u); sf::Text animationText("", font, 14u); animationText.setPosition(100.f, 150.f); // Load image that contains animation steps sf::Image image; if (!image.loadFromFile("Media/animation.png")) return 1; image.createMaskFromColor(sf::Color::White); // Create texture based on sf::Image sf::Texture texture; if (!texture.loadFromImage(image)) return 1; // Create sprite which is animated sf::Sprite sprite(texture); sprite.setPosition(100.f, 100.f); // Define walk animation thor::FrameAnimation walk; addFrames(walk, 0, 0, 7); // Frames 0..7 Right leg moves forward addFrames(walk, 0, 6, 0); // Frames 6..0 Right leg moves backward // Define attack animation thor::FrameAnimation attack; addFrames(attack, 1, 0, 3); // Frames 0..3 Lift gun addFrames(attack, 1, 4, 4, 5.f); // Frame 4 Aim (5 times normal frame duration) for (int i = 0; i < 3; ++i) addFrames(attack, 1, 5, 7); // Frame 5..7 Fire (repeat 3 times) addFrames(attack, 1, 4, 4, 5.f); // Frame 4 Wait addFrames(attack, 1, 3, 0); // Frame 3..1 Lower gun // Define static frame for stand animation thor::FrameAnimation stand; addFrames(stand, 0, 0, 0); // Register animations with their corresponding durations thor::Animator<sf::Sprite, std::string> animator; animator.addAnimation("walk", walk, sf::seconds(1.f)); animator.addAnimation("stand", stand, sf::seconds(1.f)); animator.addAnimation("attack", attack, sf::seconds(1.f)); // Create clock to measure frame time sf::Clock frameClock; // Main loop for (;;) { // Handle events sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::KeyPressed) { switch (event.key.code) { case sf::Keyboard::W: animator.playAnimation("walk", true); break; case sf::Keyboard::A: animator.playAnimation("attack"); break; case sf::Keyboard::S: animator.stopAnimation(); break; case sf::Keyboard::Escape: return 0; } } else if (event.type == sf::Event::Closed) { return 0; } } // If no other animation is playing, play stand animation if (!animator.isPlayingAnimation()) animator.playAnimation("stand"); // Output playing animation (general case; at the moment an animation is always playing) if (animator.isPlayingAnimation()) animationText.setString("Animation: " + animator.getPlayingAnimation()); else animationText.setString(""); // Update animator and apply current animation state to the sprite animator.update(frameClock.restart()); animator.animate(sprite); // Draw everything window.clear(sf::Color(50, 50, 50)); window.draw(instructions); window.draw(animationText); window.draw(sprite); window.display(); } }
//////////////////////////////////////////////////////////// /// Entry point of application /// /// \return Application exit code /// //////////////////////////////////////////////////////////// int main() { // Create the main window sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader"); window.EnableVerticalSync(true); // Create the effects std::vector<Effect*> effects; effects.push_back(new Pixelate); effects.push_back(new WaveBlur); effects.push_back(new StormBlink); effects.push_back(new Edge); std::size_t current = 0; // Initialize them for (std::size_t i = 0; i < effects.size(); ++i) effects[i]->Load(); // Create the messages background sf::Texture textBackgroundTexture; if (!textBackgroundTexture.LoadFromFile("resources/text-background.png")) return EXIT_FAILURE; sf::Sprite textBackground(textBackgroundTexture); textBackground.SetPosition(0, 520); textBackground.SetColor(sf::Color(255, 255, 255, 200)); // Load the messages font sf::Font font; if (!font.LoadFromFile("resources/sansation.ttf")) return EXIT_FAILURE; // Create the description text sf::Text description("Current effect: " + effects[current]->GetName(), font, 20); description.SetPosition(10, 530); description.SetColor(sf::Color(80, 80, 80)); // Create the instructions text sf::Text instructions("Press left and right arrows to change the current shader", font, 20); instructions.SetPosition(280, 555); instructions.SetColor(sf::Color(80, 80, 80)); // Start the game loop sf::Clock clock; while (window.IsOpen()) { // Process events sf::Event event; while (window.PollEvent(event)) { // Close window: exit if (event.Type == sf::Event::Closed) window.Close(); if (event.Type == sf::Event::KeyPressed) { switch (event.Key.Code) { // Escape key: exit case sf::Keyboard::Escape: window.Close(); break; // Left arrow key: previous shader case sf::Keyboard::Left: if (current == 0) current = effects.size() - 1; else current--; description.SetString("Current effect: " + effects[current]->GetName()); break; // Right arrow key: next shader case sf::Keyboard::Right: if (current == effects.size() - 1) current = 0; else current++; description.SetString("Current effect: " + effects[current]->GetName()); break; default: break; } } } // Update the current example float x = static_cast<float>(sf::Mouse::GetPosition(window).x) / window.GetWidth(); float y = static_cast<float>(sf::Mouse::GetPosition(window).y) / window.GetHeight(); effects[current]->Update(clock.GetElapsedTime() / 1000.f, x, y); // Clear the window window.Clear(sf::Color(255, 128, 0)); // Draw the current example window.Draw(*effects[current]); // Draw the text window.Draw(textBackground); window.Draw(instructions); window.Draw(description); // Finally, display the rendered frame on screen window.Display(); } // delete the effects for (std::size_t i = 0; i < effects.size(); ++i) delete effects[i]; return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { UCHAR seed[256]; UCHAR line[MAX_LINE+1]; UCHAR plain_text[MAX_TEXT+1]; UCHAR cipher_text[MAX_TEXT+1]; UCHAR comment[MAX_LINE+1]; UCHAR xored_text[MAX_TEXT+1]; int i, num; ULONG sweep, done = 0, iter; rc4_key key; FILE *fp; char** args = argv; int acount = argc; double time_taken; USHORT plain_text_len, cipher_text_len, text_len; USHORT cmd_line_project_id, file_check_sum = 0; USHORT completed_check_sum = 0; USHORT comment_len = 0; USHORT segments, start_segment; UCHAR* tag; UCHAR* value; int done_plain_text = 0; int done_cipher_text = 0; #if !defined(_MSDOS) && !defined(__OS2__) struct timeval tv_start,tv_end; #endif double keys_sec, run_time, start_time; int first = 1; #ifdef __OS2__ APIRET rc; #endif big_endian = ((char*)&test_endian)[0]; prog = argv[0]; #ifdef __OS2__ /* set priority class to IDLETIME */ rc = DosSetPriority(PRTYS_PROCESS, PRTYC_IDLETIME, 0, 0); if (rc != 0) { fprintf(stderr, "%s: unable to set priority, rc = %ld\n", prog, rc); exit(1); } #endif /* __OS2__ */ if (argc < 2) { usage(); exit(1); } if (args[1][0]=='-') { switch(args[1][1]) { case 'q': verbose = 0; break; case '\0': /* stdin = '-' */ acount++; args--; /* doesn't count as a flag */ break; default: fprintf(stderr,"invalid flag %s\n",args[1]); usage(); exit(1); } args++; acount--; } if (acount < 5) { usage(); exit(1); } if (!strcmp(args[1],"-")) { fp = stdin; } else { fp = fopen(args[1],"rb"); if (!fp) { fprintf(stderr,"error cannot open config file %s\n",args[1]); exit(2); } } num = sscanf(args[2],"%hx",&cmd_line_project_id); if (num < 1) { fprintf(stderr,"error: project-id should be a hexadecimal number\n\n"); usage(); exit(1); } if (strlen(args[3]) > 4) { fprintf(stderr,"error: start-key should be a 4 digit hexadecimal number\n\n"); usage(); exit(1); } i = byte_pack(seed, (UCHAR*) args[3], 2); if (i != 2) { fprintf(stderr,"error: start-key should be a 4 digit hexadecimal number\n\n"); usage(); exit(1); } seed[2] = seed[3] = seed[4] = 0; start_segment = (USHORT)seed[0]*256 + (USHORT)seed[1]; num = sscanf(args[4],"%hu",&segments); if (num < 1) { fprintf(stderr,"error: segments should be a decimal number\n\n"); usage(); exit(1); } sweep = (ULONG)segments << 8; while (!feof(fp)) { line[0] = '\0'; fgets(line, MAX_LINE, fp); strip_crlf(line); strip_comments(line); file_check_sum = checksum(file_check_sum, line); parse_line(line,&tag,&value); if (!tag || !*tag) { continue; } if (!strcasecmp(tag,"PLAIN-TEXT")) { if (done_plain_text) { fprintf(stderr, "config file error: should only have one PLAIN-TEXT field\n"); exit(2); } if (strlen(value) & 0x1 != 0) { fprintf(stderr, "config file error: PLAIN-TEXT field must be an even number of hex digits\n"); exit(2); } plain_text_len = byte_pack(plain_text, value, MAX_TEXT); if (plain_text_len == 0) { fprintf(stderr, "config file error: PLAIN-TEXT field must be hex digits\n"); exit(2); } done_plain_text = 1; } else if (!strcasecmp(tag,"CIPHER-TEXT")) { if (done_cipher_text) { fprintf(stderr, "config file error: should only have one CIPHER-TEXT field\n"); exit(2); } if (strlen(value) & 0x1 != 0) { fprintf(stderr, "config file error: CIPHER-TEXT field must be an even number of hex digits\n"); exit(2); } cipher_text_len = byte_pack(cipher_text, value, MAX_TEXT); if (cipher_text_len == 0) { fprintf(stderr, "config file error: CIPHER-TEXT field must be hex digits\n"); exit(2); } done_cipher_text = 1; } else if (!strcasecmp(tag,"COMMENT")) { char *rest = strtok(0, "\n"); /* ie to the end of string as there */ if (comment_len != 0) /* won't be a \n due to strip_crlf */ { fprintf(stderr, "config file error: should only have one COMMENT field\n"); exit(2); } strncpy(comment, value, MAX_LINE); if (rest) { comment_len = strlen(comment); strncat(comment," ", MAX_LINE - comment_len); comment_len++; strncat(comment, rest, MAX_LINE - comment_len); comment[MAX_LINE] = '\0'; } comment_len = strlen(comment); } else { fprintf(stderr,"config file error: unknown tag: %s\n",tag); exit(2); } } if (!done_plain_text) { fprintf(stderr,"config file error: no PLAIN-TEXT field\n"); exit(2); } if (!done_cipher_text) { fprintf(stderr,"config file error: no CIPHER-TEXT field\n"); exit(2); } if (plain_text_len != cipher_text_len) { fprintf(stderr,"config file warning: PLAIN-TEXT and CIPHER-TEXT are not the same length\n"); } text_len = plain_text_len < cipher_text_len ? plain_text_len : cipher_text_len; if (cmd_line_project_id != file_check_sum) { fprintf(stderr,"error: you have the wrong config file for project %04x (%04x)\n", cmd_line_project_id, file_check_sum); exit(1); } completed_check_sum = (( (ULONG)file_check_sum + (ULONG)start_segment + (ULONG)segments ) & 0xFFFFL); if (verbose) { fprintf(stderr,"PROJECT-ID\t%04x\n",file_check_sum); if (comment_len) fprintf(stderr,"COMMENT \t%s\n",comment); fprintf(stderr,"START-KEY\t%s\n",print_hex(seed,KEY_SIZE)); fprintf(stderr,"SEGMENTS\t%u (16M keys/segment)\n",segments); fprintf(stderr,"PLAIN-TEXT\t%s\n",print_hex(plain_text,text_len)); fprintf(stderr,"CIPHER-TEXT\t%s\n",print_hex(cipher_text,text_len)); fprintf(stderr,"TEXT-SIZE\t%d\n",text_len); fprintf(stderr,"256k keys per '.' printed, 1 segment per line, a segment = 16M keys\n"); fprintf(stderr,"LINES-TO-DO\t%d\n",segments); } /* pre-compute plain_text XOR cipher_text */ for (i=0; i<text_len; i++) { xored_text[i] = plain_text[i] ^ cipher_text[i]; } for (done=0; done<sweep; done++) { if (verbose) { if (first) { #if defined(_MSDOS) || defined(__OS2__) start_time = (double) clock()/CLOCKS_PER_SEC; #else gettimeofday(&tv_start,0); #endif } } for (iter=0; iter < 65536; iter++) { prepare_key(seed,KEY_SIZE,&key); if (rc4_eq(xored_text, text_len, &key)) { if (verbose) { fprintf(stderr,"\nFOUND-IT\t%s\n", print_hex(seed,KEY_SIZE)); instructions(); } printf("%04x %04x %04x %u %s\n",file_check_sum,completed_check_sum, start_segment,segments,print_hex(seed,KEY_SIZE)); exit(0); } inc_key(seed); } if (verbose) { if (first) { #if defined(_MSDOS) || defined(__OS2__) time_taken = ((double) clock()/CLOCKS_PER_SEC) - start_time; #else gettimeofday(&tv_end,0); time_taken = (double)(tv_end.tv_sec - tv_start.tv_sec); time_taken += ((double)(tv_end.tv_usec - tv_start.tv_usec)/1000000.0); #endif keys_sec = 65536.0 / time_taken; fprintf(stderr,"KEYS-PER-SEC\t%0.1lf keys/sec\n",keys_sec); fprintf(stderr,"EXPECTED-RUNNING-TIME\t"); run_time = sweep * time_taken; if (run_time < 60) { fprintf(stderr,"%0.1lf secs\n",run_time); } else if (run_time < 3600) { fprintf(stderr,"%0.1lf mins\n",run_time / 60); } else { fprintf(stderr,"%0.1lf hours\n",run_time / 3600); if (run_time > 180000) { fprintf(stderr,"in days: %0.1lf days\n",run_time / 86400); } } first = 0; } if ((done & 255L) == 0) { if (done > 0) fprintf(stderr,"]\n"); fprintf(stderr,"%sxxxxxx:[",print_hex(seed,2)); } if ((done & 3L) == 0) { fputc('.',stderr); } #ifdef __OS2__ fflush(stderr); /* needed to prevent buffering of stderr */ #endif } } if (verbose) { fprintf(stderr,"]\n"); instructions(); } printf("%04x %04x %04x %u no\n",file_check_sum,completed_check_sum, start_segment,segments); return 0; }
int main() { Packets::SimPack* spack = new Packets::SimPack(); float str = 2.5; float brk = 4.5; float gas = 0.5; int forward = 0; int reverse = 0; int parking = 1; int tmp; ml.lock(); spack->setDigital(GEARSELECT1, ON); spack->setDigital(ACTIVATIONCLC,ON); ml.unlock(); std::thread worker(simSend, spack); worker.detach(); initscr(); (void)noecho(); curs_set(0); addstr( instructions()); refresh(); getch(); clear(); addstr( gui(str,gas,brk,forward,reverse)); addstr( txt(str,gas,brk,forward,reverse,parking)); refresh(); while(1){ tmp = getch(); if(tmp == 104){ clear(); addstr( instructions()); refresh(); getch(); clear(); }else if(tmp == 113){ clear(); endwin(); exit(0); }else{ ml.lock(); update(tmp,str,brk,gas,forward,reverse,parking,*spack); ml.unlock(); clear(); addstr( gui(str,gas,brk,forward,reverse)); addstr( txt(str,gas,brk,forward,reverse,parking)); refresh(); } } clear(); endwin(); return 0; }
int main() { // Initial setup signal(SIGINT, shutDown); openPath(); instructions(); srand(time(NULL)); game_state currGame; memset(&currGame, 0, sizeof(game_state)); // Sets up piezobuzzer for sound using designated PWM pin pwm = fopen("/sys/devices/bone_capemgr.9/slots", "w"); fseek(pwm, 0, SEEK_END); fprintf(pwm, "am33xx_pwm"); fprintf(pwm, "bone_pwm_P9_14"); fflush(pwm); // Sets the pointers to the appropriate duty and period files dirDuty = fopen("/sys/devices/ocp.3/pwm_test_P9_14.15/duty", "w"); dirT = fopen("/sys/devices/ocp.3/pwm_test_P9_14.15/period", "w"); // Main game loop while (!currGame.quit) { char *playScreen = " Press button to start! "; write(fd_lcd, playScreen, SCREEN_SIZE * 3); pressAnyButton(); // usleep necessary here to prevent signal overlap once game begins usleep(500000); // Initializes the playing screen char symbolScreen[SCREEN_SIZE + 1]; int i; for (i = 0; i < SCREEN_SIZE; i++) { symbolScreen[i] = ' '; } symbolScreen[SCREEN_SIZE] = '\0'; session_state currSession; memset(&currSession, 0, sizeof(session_state)); currSession.misses = -1; // Current game session loop while (currSession.misses < WRONG_GUESSES) { // When software counter resets, update to the next screen frame if (currSession.counter == 0) { // Respond to player's input if (currSession.correctInput && symbolScreen[0] != ' ') { currSession.currScore++; } else if (!currSession.correctInput) { currSession.misses++; } currSession.inputted = 0; currSession.correctInput = 0; if (nextScreenFrame(&currSession, symbolScreen) == -1) { shutDown(); return EXIT_FAILURE; } } // Delay inbetween input update usleep(DELAY_TIME); // Reads the current status of the button inputs read(fd_but, currGame.inputs, NUM_BUTTONS * sizeof(int)); currSession.pressed = 5; for (i = 0; i < NUM_BUTTONS; i++) { if (currGame.inputs[i] == 1) { currSession.pressed = i; } } // Play sound on buzzer which corresponds to the input // This is done less often to improve smoothness of gameplay if (currSession.counter % 15 == 0) { if (currSession.pressed == 0) { buzzer(noteA); } else if (currSession.pressed == 1) { buzzer(noteB); } else if (currSession.pressed == 2) { buzzer(noteC); } else if (currSession.pressed == 3) { buzzer(noteD); } else if (currSession.pressed == 4) { buzzer(noteE); } else { buzzer(0); } } updateSession(&currSession, symbolScreen[0]); } printGameOver(currSession.currScore, &(currGame.highScore)); pressAnyButton(); usleep(500000); // Prompts user to choose to play again currGame.quit = wantToQuit(); usleep(500000); } shutDown(); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { bool playing; int ch; if(pledge("stdio rpath tty proc exec", NULL) == -1) err(1, "pledge"); while ((ch = getopt(argc, argv, "emqr")) != -1) switch (ch) { case 'e': explain = TRUE; break; case 'm': muggins = TRUE; break; case 'q': quiet = TRUE; break; case 'r': rflag = TRUE; break; case '?': default: (void) fprintf(stderr, "usage: cribbage [-emqr]\n"); exit(1); } initscr(); (void)signal(SIGINT, rintsig); cbreak(); noecho(); Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0); Tablewin = subwin(stdscr, TABLE_Y, TABLE_X, 0, PLAY_X); Compwin = subwin(stdscr, COMP_Y, COMP_X, 0, TABLE_X + PLAY_X); Msgwin = subwin(stdscr, MSG_Y, MSG_X, Y_MSG_START, SCORE_X + 1); leaveok(Playwin, TRUE); leaveok(Tablewin, TRUE); leaveok(Compwin, TRUE); clearok(stdscr, FALSE); if (!quiet) { msg("Do you need instructions for cribbage? "); if (getuchar() == 'Y') { endwin(); clear(); mvcur(0, COLS - 1, LINES - 1, 0); fflush(stdout); instructions(); cbreak(); noecho(); clear(); refresh(); msg("For cribbage rules, use \"man cribbage\""); } } if (pledge("stdio tty", NULL) == -1) err(1, "pledge"); playing = TRUE; do { wclrtobot(Msgwin); msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? "); if (glimit == SGAME) glimit = (getuchar() == 'L' ? LGAME : SGAME); else glimit = (getuchar() == 'S' ? SGAME : LGAME); game(); msg("Another game? "); playing = (getuchar() == 'Y'); } while (playing); bye(); exit(0); }
World::World(WindowFramework* windowFrameworkPtr) : UP(0,0,1), m_windowFrameworkPtr(windowFrameworkPtr) { // preconditions if(m_windowFrameworkPtr == NULL) { nout << "ERROR: parameter windowFrameworkPtr cannot be NULL." << endl; return; } // This code puts the standard title and instruction text on screen COnscreenText title("title", COnscreenText::TS_plain); title.set_text("Panda3D: Tutorial - Collision Detection"); title.set_fg(Colorf(1,1,1,1)); title.set_pos(LVecBase2f(0.7,-0.95)); title.set_scale(0.07); title.reparent_to(m_windowFrameworkPtr->get_aspect_2d()); m_titleNp = title.generate(); COnscreenText instructions("instructions"); instructions.set_text("Mouse pointer tilts the board"); instructions.set_pos(LVecBase2f(-1.3, 0.95)); instructions.set_fg(Colorf(1,1,1,1)); instructions.set_align(TextNode::A_left); instructions.set_scale(0.05); instructions.reparent_to(m_windowFrameworkPtr->get_aspect_2d()); m_instructionsNp = instructions.generate(); // Escape quits m_windowFrameworkPtr->enable_keyboard(); m_windowFrameworkPtr->get_panda_framework()->define_key("escape", "sysExit", sys_exit, NULL); // Disable mouse-based camera control // Note: irrelevant in C++ // Place the camera NodePath cameraNp = m_windowFrameworkPtr->get_camera_group(); cameraNp.set_pos_hpr(0, 0, 25, 0, -90, 0); // Load the maze and place it in the scene NodePath modelsNp = m_windowFrameworkPtr->get_panda_framework()->get_models(); m_mazeNp = m_windowFrameworkPtr->load_model(modelsNp, "../models/maze"); NodePath renderNp = m_windowFrameworkPtr->get_render(); m_mazeNp.reparent_to(renderNp); // Most times, you want collisions to be tested against invisible geometry // rather than every polygon. This is because testing against every polygon // in the scene is usually too slow. You can have simplified or approximate // geometry for the solids and still get good results. // // Sometimes you'll want to create and position your own collision solids in // code, but it's often easier to have them built automatically. This can be // done by adding special tags into an egg file. Check maze.egg and ball.egg // and look for lines starting with <Collide>. The part is brackets tells // Panda exactly what to do. Polyset means to use the polygons in that group // as solids, while Sphere tells panda to make a collision sphere around them // Keep means to keep the polygons in the group as visable geometry (good // for the ball, not for the triggers), and descend means to make sure that // the settings are applied to any subgroups. // // Once we have the collision tags in the models, we can get to them using // NodePath's find command // Find the collision node named wall_collide m_wallsNp = m_mazeNp.find("**/wall_collide"); // Collision objects are sorted using BitMasks. BitMasks are ordinary numbers // with extra methods for working with them as binary bits. Every collision // solid has both a from mask and an into mask. Before Panda tests two // objects, it checks to make sure that the from and into collision masks // have at least one bit in common. That way things that shouldn't interact // won't. Normal model nodes have collision masks as well. By default they // are set to bit 20. If you want to collide against actual visable polygons, // set a from collide mask to include bit 20 // // For this example, we will make everything we want the ball to collide with // include bit 0 m_wallsNp.node()->set_into_collide_mask(BitMask32::bit(0)); // CollisionNodes are usually invisible but can be shown. Uncomment the next // line to see the collision walls // m_wallsNp.show(); // We will now find the triggers for the holes and set their masks to 0 as // well. We also set their names to make them easier to identify during // collisions m_loseTriggers.reserve(NB_HOLES); for(int i = 0; i < NB_HOLES; ++i) { ostringstream filename; filename << "**/hole_collide" << i; NodePath triggerNp = m_mazeNp.find(filename.str()); triggerNp.node()->set_into_collide_mask(BitMask32::bit(0)); triggerNp.node()->set_name("loseTrigger"); m_loseTriggers.push_back(triggerNp); // Uncomment this line to see the triggers // triggerNp.show(); } // Ground_collide is a single polygon on the same plane as the ground in the // maze. We will use a ray to collide with it so that we will know exactly // what height to put the ball at every frame. Since this is not something // that we want the ball itself to collide with, it has a different // bitmask. m_mazeGroundNp = m_mazeNp.find("**/ground_collide"); m_mazeGroundNp.node()->set_into_collide_mask(BitMask32::bit(1)); // Load the ball and attach it to the scene // It is on a root dummy node so that we can rotate the ball itself without // rotating the ray that will be attached to it m_ballRootNp = renderNp.attach_new_node("ballRoot"); m_ballNp = m_windowFrameworkPtr->load_model(modelsNp, "../models/ball"); m_ballNp.reparent_to(m_ballRootNp); // Find the collision sphere for the ball which was created in the egg file // Notice that it has a from collision mask of bit 0, and an into collision // mask of no bits. This means that the ball can only cause collisions, not // be collided into m_ballSphereNp = m_ballNp.find("**/ball"); static_cast<CollisionNode*>(m_ballSphereNp.node())->set_from_collide_mask(BitMask32::bit(0)); m_ballSphereNp.node()->set_into_collide_mask(BitMask32::all_off()); // No we create a ray to start above the ball and cast down. This is to // Determine the height the ball should be at and the angle the floor is // tilting. We could have used the sphere around the ball itself, but it // would not be as reliable // Create the ray m_ballGroundRayPtr = new CollisionRay(); if(m_ballGroundRayPtr != NULL) { // Set its origin m_ballGroundRayPtr->set_origin(0,0,10); // And its direction m_ballGroundRayPtr->set_direction(0,0,-1); // Collision solids go in CollisionNode // Create and name the node m_ballGroundColPtr = new CollisionNode("groundRay"); if(m_ballGroundColPtr != NULL) { // Add the ray m_ballGroundColPtr->add_solid(m_ballGroundRayPtr); // Set its bitmasks m_ballGroundColPtr->set_from_collide_mask(BitMask32::bit(1)); m_ballGroundColPtr->set_into_collide_mask(BitMask32::all_off()); // Attach the node to the ballRoot so that the ray is relative to the ball // (it will always be 10 feet over the ball and point down) m_ballGroundColNp = m_ballRootNp.attach_new_node(m_ballGroundColPtr); // Uncomment this line to see the ray // m_ballGroundColNp.show(); } } // Finally, we create a CollisionTraverser. CollisionTraversers are what // do the job of calculating collisions // Note: no need to in this implementation // Collision traversers tell collision handlers about collisions, and then // the handler decides what to do with the information. We are using a // CollisionHandlerQueue, which simply creates a list of all of the // collisions in a given pass. There are more sophisticated handlers like // one that sends events and another that tries to keep collided objects // apart, but the results are often better with a simple queue m_cHandlerPtr = new CollisionHandlerQueue(); if(m_cHandlerPtr != NULL) { // Now we add the collision nodes that can create a collision to the // traverser. The traverser will compare these to all others nodes in the // scene. There is a limit of 32 CollisionNodes per traverser // We add the collider, and the handler to use as a pair m_cTrav.add_collider(m_ballSphereNp, m_cHandlerPtr); m_cTrav.add_collider(m_ballGroundColNp, m_cHandlerPtr); } // Collision traversers have a built in tool to help visualize collisions. // Uncomment the next line to see it. // m_cTrav.show_collisions(renderNp); // This section deals with lighting for the ball. Only the ball was lit // because the maze has static lighting pregenerated by the modeler PT(AmbientLight) ambientLightPtr = new AmbientLight("ambientLight"); if(ambientLightPtr != NULL) { ambientLightPtr->set_color(Colorf(0.55, 0.55, 0.55, 1)); m_ballRootNp.set_light(renderNp.attach_new_node(ambientLightPtr)); } PT(DirectionalLight) directionalLightPtr = new DirectionalLight("directionalLight"); if(directionalLightPtr != NULL) { directionalLightPtr->set_direction(LVecBase3f(0, 0, -1)); directionalLightPtr->set_color(Colorf(0.375, 0.375, 0.375, 1)); directionalLightPtr->set_specular_color(Colorf(1, 1, 1, 1)); m_ballRootNp.set_light(renderNp.attach_new_node(directionalLightPtr)); } // This section deals with adding a specular highlight to the ball to make // it look shiny PT(Material) materialPtr = new Material(); if(materialPtr != NULL) { materialPtr->set_specular(Colorf(1,1,1,1)); materialPtr->set_shininess(96); m_ballNp.set_material(materialPtr, 1); } // Finally, we call start for more initialization start(); }
void menu() { clrscr(); setgraph(); setbkcolor(1); for(int i=0;i<635;i+=20) { setcolor(2); setfillstyle(1,2); circle(12+i,10,10); floodfill(12+i,10,2); } for(i=0;i<635;i+=20) { setcolor(2); setfillstyle(1,2); circle(12+i,468,10); floodfill(12+i,468,2); } settextstyle(8,0,3); for(i=420;i>30;i-=3) { setcolor(random(15)); outtextxy(230,i,"SeLeCtIoN MeNu"); delay(40); setcolor(1); outtextxy(230,i,"SeLeCtIoN MeNu"); } setcolor(14); outtextxy(230,30,"SeLeCtIoN MeNu"); line(220,60,440,60); for(i=0;i<200;i+=3) { setcolor(i); settextstyle(7,0,2); outtextxy(i,110," 1. NEW GAME"); outtextxy(i,160," 2. INSTRUCTIONS"); outtextxy(i,210," 3. EXIT"); delay(40); setcolor(1); outtextxy(i,110," 1. NEW GAME"); outtextxy(i,160," 2. INSTRUCTIONS"); outtextxy(i,210," 3. EXIT"); } int v; for(int h=0;;) { for(int i=0;i<635;i+=20) { setcolor(2); setfillstyle(1,2); circle(12+i,10,10); floodfill(12+i,10,2); } for(i=0;i<635;i+=20) { setcolor(2); setfillstyle(1,2); circle(12+i,468,10); floodfill(12+i,468,2); } i=200; setcolor(15); ellipse(310,180,0,360,140,100); setfillstyle(1,4); floodfill(310,180,15); setcolor(15); settextstyle(7,0,2); outtextxy(i,110," 1. NEW GAME"); outtextxy(i,160," 2. INSTRUCTIONS"); outtextxy(i,210," 3. EXIT"); setcolor(14); setfillstyle(1,14); circle(180,350,10); floodfill(180,350,14); setcolor(10); setfillstyle(1,10); circle(130,200,20); floodfill(130,200,10); setcolor(6); setfillstyle(1,6); circle(600,300,15); floodfill(600,300,6); setcolor(13); setfillstyle(1,13); circle(30,330,15); floodfill(30,330,13); setcolor(12); setfillstyle(1,12); circle(460,350,15); floodfill(460,350,12); setcolor(13); setfillstyle(1,13); circle(480,220,20); floodfill(480,220,13); setcolor(12); setfillstyle(1,12); circle(50,80,10); floodfill(50,80,12); setcolor(14); setfillstyle(1,14); circle(590,80,10); floodfill(590,80,14); if(h==300) v=1; else if(h==0) v=0; if(v==1) h-=10; else if(v==0) h+=10; setcolor(15); settextstyle(8,0,2); outtextxy(h,400,"Enter Your Choice (1,2 or 3)"); delay(150); setcolor(1); settextstyle(8,0,2); outtextxy(h,400,"Enter Your Choice (1,2 or 3)"); if(kbhit()) { char c=getch(); if(c=='1') { setcolor(4); rectangle(205,320,440,420); setcolor(14); rectangle(206,321,439,419); setcolor(15); settextstyle(2,0,6); outtextxy(210,340," 1. USER vs COMPUTER"); outtextxy(210,370," 2.PLAYER 1 vs PLAYER 2"); p= getch(); closegraph(); game(); } else if(c=='2') instructions(); else exit(0); } settextstyle(8,0,3); setcolor(14); outtextxy(230,30,"SeLeCtIoN MeNu"); line(220,60,440,60); } }
int main(int argc, char **argv[]) { char *input = argv[1]; int length; if (argc != ARGS) { return instructions(); } input = argv[1]; length = strlen(input); printf("input is %s with length %d.\n",input,length); printf("i[0] = %c,\n",input[0]); int test = 0; int sum = 0; int i = 0; char temp = 0; // div test 2- test whether last digit is divisible by two test = input[11] % 2; if (test == 0) printf("fails div test 1. not prime.\n"); // div test 3 - test whether sum of digits is divisible by three for (i = 0; i < length; i++) { temp = input[i]; temp = atoi(&temp); sum = sum + temp; printf("current digit %d and current sum %d\n",temp,sum); } test = sum % 3; if (test == 0) printf("the sum %d is divisible by three.\n",sum); else printf("the sum %d is not divisible by three.\n",sum); // div test 4 - test whether the last two digits are divisible by 4 // div test 5 - test whether last digit is 0 or 5 // div test 6 - even and sum of digits divisible by 2 or 3 // satisfied by tests for 2 and 3 // div test 7 - just divide by 7 // or take two left most digits, multiple left by 3 and add to the second // then replace these two with the result etc etc. // div test 8 - test whether last three digits are divisible by 8 // div test 9 - test whether the sum of digits is divisible by 9 // satisfied by test for 3 // div test 10 - last digit is 0 // satisfied by test for 5 // div test 11 - test whether difference between sum of odd digits // and sum of even digits is divisible by 11 }
void dogde() { int i,j,ran; char ch,menu; loading(); cleardevice(); setbkcolor(YELLOW); setcolor(BLUE); h: outtextxy(100,100,"Press I to read instructions."); outtextxy(100,200,"Press S to start the game."); outtextxy(100,300,"Press E to exit."); menu=getchar(); clrscr(); toupper(menu); switch(menu) { case 'S' : break; case 's' : break; case 'I' : instructions(); goto h; case 'i' : instructions(); goto h; case 'E' : exit(0); case 'e' : exit(0); default : goto h; } setviewport(0,170,639,310,1); start: setbkcolor(YELLOW); randomize(); ran=random(2); if(ran==0) { for(i=0;i<639;i++) { draw_man(); setcolor(RED); rectangle(635-i,120,639-i,140); setcolor(BLACK); rectangle(637-i,120,641-i,140); man.top_y=90; man.top_x=55; man.bottom_x=55; man.bottom_y=140; obstacle.x=635-i; obstacle.y=120; if(kbhit()) { ch=getch(); if(ch=='y'||ch=='Y') { i=jump(i,ran); draw_man(); if(man.bottom_x>obstacle.x) { score++; goto start; } else if(man.bottom_y >=obstacle.y && man.bottom_x==obstacle.x) { gameover(); } } else if(ch=='h'||ch=='H') { i=bend(i,ran); draw_man(); if(man.bottom_x>obstacle.x) { score++; goto start; } else if(man.bottom_y >=obstacle.y && man.bottom_x==obstacle.x) { gameover(); } } } delay(10); } } else if(ran==1) { for(i=0;i<639;i++) { draw_man(); setcolor(RED); rectangle(635-i,20,639-i,80); setcolor(BLACK); rectangle(637-i,20,641-i,80); obstacle.x=635-i; obstacle.y=60; if(kbhit()) { ch=getch(); if(ch=='y'||ch=='Y') { i=jump(i,ran); draw_man(); if(man.bottom_x>obstacle.x) { score++; goto start; } else if(man.top_y<=obstacle.y && man.bottom_x==obstacle.x) { gameover(); } } else if(ch=='h'||ch=='H') { i=bend(i,ran); draw_man(); if(man.bottom_x>obstacle.x) { score++; goto start; } else if(man.bottom_y >=obstacle.y && man.bottom_x==obstacle.x) { gameover(); } } } delay(10); } } gameover(); closegraph(); }
void main() { //MAIN SCREEN setgraph(); setbkcolor(15); setcolor(RED); settextstyle(4,0,8); outtextxy(20,20,"NBA Live 2011"); settextstyle(3,0,4); outtextxy(300,420,"c MacroSoft Inc.2011"); circle(307,445,10); setfillstyle(1,BLUE); bar(200,350,400,370); for(int x=2;x<10;x++) { if(x%2==0) setfillstyle(1,GREEN); else setfillstyle(1,15); for(int i=205;i<395;i+=15) { bar(i,353,i+10,367); delay(50); } } settextstyle(4,0,3); outtextxy(123,380,"PRESS ANY KEY TO CONTINUE"); getch(); cleardevice(); settextstyle(3,0,4); outtextxy(300,420,"c Macrosoft Inc.2011"); circle(307,445,10); settextstyle(4,0,8); outtextxy(140,20,"Main Menu"); setcolor(BLUE); settextstyle(1,0,4); outtextxy(195,200," 1. Start Game"); outtextxy(195,230," 2. Instructions"); outtextxy(195,260," 3. Exit"); circle(80,380,45); setfillstyle(1,6); floodfill(50,385,1); line(80,335,80,425); arc(30,380,300,63,30); arc(130,380,117,240,30); circle(560,380,45); setfillstyle(1,6); floodfill(560,380,1); line(560,335,560,425); arc(510,380,300,63,30); arc(610,380,117,240,30); char c=getch(); if(c=='1') game(); else if(c=='2') instructions(); else if(c==27||'4') exit(0); closegraph(); }
int main() { // Create resource cache for both sf::Texture and sf::SoundBuffer thor::MultiResourceCache cache; // Create sf::Image to load texture from sf::Image image; image.create(529, 100, sf::Color(130, 70, 0)); // Create keys to load resources thor::ResourceKey<sf::Texture> textureKey1 = thor::Resources::fromImage<sf::Texture>(image); thor::ResourceKey<sf::Texture> textureKey2 = thor::Resources::fromFile<sf::Texture>("Media/image.jpg"); thor::ResourceKey<sf::SoundBuffer> soundKey = thor::Resources::fromFile<sf::SoundBuffer>("Media/click.wav"); thor::ResourceKey<sf::Font> fontKey = thor::Resources::fromFile<sf::Font>("Media/sansation.ttf"); // Create resource pointers to access the resources std::shared_ptr<sf::Texture> texture1, texture2; std::shared_ptr<sf::SoundBuffer> soundBuffer; std::shared_ptr<sf::Font> font; // Actually load resources, store them in resource pointers and react to loading errors try { texture1 = cache.acquire(textureKey1); texture2 = cache.acquire(textureKey2); soundBuffer = cache.acquire(soundKey); font = cache.acquire(fontKey); } catch (thor::ResourceLoadingException& e) { std::cout << e.what() << std::endl; return 1; } // Create instances that use the resources sf::Sprite sprite1(*texture1); sf::Sprite sprite2(*texture2); sf::Sound sound(*soundBuffer); sf::Text instructions("Press return to play sound, escape to quit", *font, 14u); // Move second sprite so that the sprites don't overlap sprite2.move( 0.f, static_cast<float>(texture1->getSize().y) ); // Create render window sf::RenderWindow window(sf::VideoMode(800, 600), "Thor Resources"); window.setVerticalSyncEnabled(true); for (;;) { // Handle events sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { return 0; } else if (event.type == sf::Event::KeyPressed) { switch (event.key.code) { case sf::Keyboard::Escape: return 0; case sf::Keyboard::Return: sound.play(); break; } } } // Draw sprites of the loaded textures window.clear(); window.draw(sprite1); window.draw(sprite2); window.draw(instructions); window.display(); } }