/* initializes the puzzle */ static void puzzle_init(void) { int i, r, temp, tsp[NUM_SPOTS]; moves = 0; /* shuffle spots */ for (i=NUM_SPOTS-1; i>=0; i--) { r = (rb->rand() % (i+1)); temp = spots[r]; spots[r] = spots[i]; spots[i] = temp; if (spots[i]==HOLE_ID) hole = i; } /* test if the puzzle is solvable */ for (i=0; i<NUM_SPOTS; i++) tsp[i] = spots[i]; r=0; /* First, check if the problem has even or odd parity, depending on where the empty square is */ if ((((SPOTS_X-1)-hole%SPOTS_X) + ((SPOTS_Y-1)-hole/SPOTS_X))%2 == 1) ++r; /* Now check how many swaps we need to solve it */ for (i=0; i<NUM_SPOTS-1; i++) { while (tsp[i] != (i+1)) { temp = tsp[i]; tsp[i] = tsp[temp-1]; tsp[temp-1] = temp; ++r; } } /* if the random puzzle isn't solvable just change two spots */ if (r%2 == 1) { if (spots[0]!=HOLE_ID && spots[1]!=HOLE_ID) { temp = spots[0]; spots[0] = spots[1]; spots[1] = temp; } else { temp = spots[2]; spots[2] = spots[3]; spots[3] = temp; } } draw_playfield(); }
void draw_scene() { glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); if (firstdraw == true || reset == true) { if (firstdraw == true) { timer = SDL_AddTimer(timer_speed, game_timer, 0); setfield("ghostmap.txt", ghostfield); setfield("pacmap-inversion.txt", ghostrun); pacman.next_x = pacman.x + 1; } setfield("pacmap.txt", playfield); //initialize ghosts g_blinky.status = ST_BLINKY; g_pinky.status = ST_PINKY; g_inky.status = ST_INKY; g_clyde.status = ST_CLYDE; g_blinky.direction = ST_LEFT; g_pinky.direction = ST_LEFT; g_inky.direction = ST_LEFT; g_clyde.direction = ST_LEFT; g_blinky.has_los = false; g_pinky.has_los = false; g_inky.has_los = false; g_clyde.has_los = false; g_blinky.x = 43; g_blinky.y = 8; g_pinky.x = 53; g_pinky.y = 15; g_inky.x = 51; g_inky.y = 22; g_clyde.x = 57; g_clyde.y = 22; } Ai::encompassing(); //displayfield(ghostfield); draw_playfield(); draw_pacman(); draw_ghosts(); draw_score(); SDL_GL_SwapBuffers(); int error = glGetError(); if (error != 0) { fileout << "Error: " << error << endl << flush; cout << "Error: " << error << endl << flush; } }
enum plugin_status plugin_start( const void* parameter) { int i, w, h; initial_bmp_path=(const char *)parameter; img_buf = rb->plugin_get_buffer(&img_buf_len); picmode = PICMODE_INITIAL_PICTURE; img_buf_path[0] = '\0'; /* If launched as a viewer, just go straight to the game without bothering with the splash or instructions page */ if(parameter==NULL) { /* if not launched as a viewer, use default puzzle, and show help */ picmode = PICMODE_DEFAULT_PICTURE; /* print title */ rb->lcd_getstringsize((unsigned char *)"Sliding Puzzle", &w, &h); w = (w+1)/2; h = (h+1)/2; rb->lcd_clear_display(); rb->lcd_putsxy(LCD_WIDTH/2-w, (LCD_HEIGHT/2)-h, (unsigned char *)"Sliding Puzzle"); rb->lcd_update(); rb->sleep(HZ); /* print instructions */ rb->lcd_clear_display(); rb->lcd_setfont(FONT_SYSFIXED); #if CONFIG_KEYPAD == RECORDER_PAD || CONFIG_KEYPAD == ARCHOS_AV300_PAD rb->lcd_putsxy(3, 18, "[OFF] to stop"); rb->lcd_putsxy(3, 28, "[F1] shuffle"); rb->lcd_putsxy(3, 38, "[F2] change pic"); #elif CONFIG_KEYPAD == ONDIO_PAD rb->lcd_putsxy(0, 18, "[OFF] to stop"); rb->lcd_putsxy(0, 28, "[MODE..] shuffle"); rb->lcd_putsxy(0, 38, "[MODE] change pic"); #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ (CONFIG_KEYPAD == IPOD_3G_PAD) || \ (CONFIG_KEYPAD == IPOD_1G2G_PAD) rb->lcd_putsxy(0, 18, "[S-MENU] to stop"); rb->lcd_putsxy(0, 28, "[S-LEFT] shuffle"); rb->lcd_putsxy(0, 38, "[S-RIGHT] change pic"); #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ (CONFIG_KEYPAD == IRIVER_H300_PAD) rb->lcd_putsxy(0, 18, "[STOP] to stop"); rb->lcd_putsxy(0, 28, "[SELECT] shuffle"); rb->lcd_putsxy(0, 38, "[PLAY] change pic"); #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD rb->lcd_putsxy(0, 18, "[OFF] to stop"); rb->lcd_putsxy(0, 28, "[REC] shuffle"); rb->lcd_putsxy(0, 38, "[PLAY] change pic"); #elif CONFIG_KEYPAD == GIGABEAT_PAD rb->lcd_putsxy(0, 18, "[POWER] to stop"); rb->lcd_putsxy(0, 28, "[SELECT] shuffle"); rb->lcd_putsxy(0, 38, "[A] change pic"); #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \ (CONFIG_KEYPAD == SANSA_C200_PAD) rb->lcd_putsxy(0, 18, "[OFF] to stop"); rb->lcd_putsxy(0, 28, "[REC] shuffle"); rb->lcd_putsxy(0, 38, "[SELECT] change pic"); #elif CONFIG_KEYPAD == IRIVER_H10_PAD rb->lcd_putsxy(0, 18, "[OFF] to stop"); rb->lcd_putsxy(0, 28, "[REW] shuffle"); rb->lcd_putsxy(0, 38, "[PLAY] change pic"); #elif CONFIG_KEYPAD == GIGABEAT_S_PAD || \ CONFIG_KEYPAD == SAMSUNG_YPR0_PAD rb->lcd_putsxy(0, 18, "[BACK] to stop"); rb->lcd_putsxy(0, 28, "[SELECT] shuffle"); rb->lcd_putsxy(0, 38, "[MENU] change pic"); #elif CONFIG_KEYPAD == IAUDIO_M3_PAD rb->lcd_putsxy(0, 18, "[REC] to stop"); rb->lcd_putsxy(0, 28, "[MODE] shuffle"); rb->lcd_putsxy(0, 38, "[MENU] change pic"); #endif #ifdef HAVE_TOUCHSCREEN rb->lcd_putsxy(0, 18, PUZZLE_QUIT_TEXT " to stop"); rb->lcd_putsxy(0, 28, PUZZLE_SHUFFLE_TEXT " shuffle"); rb->lcd_putsxy(0, 38, PUZZLE_PICTURE_TEXT " change pic"); #endif #ifdef HAVE_ALBUMART rb->lcd_putsxy(0,48," pic->albumart->num"); #else rb->lcd_putsxy(0,48," pic<->num"); #endif rb->lcd_update(); rb->button_get_w_tmo(HZ*2); } hole = INITIAL_HOLE; if( !load_resize_bitmap() ) { rb->lcd_clear_display(); rb->splash(HZ*2,"Failed to load bitmap!"); return PLUGIN_OK; } /* Calculate possible font sizes and text positions */ rb->lcd_setfont(FONT_UI); rb->lcd_getstringsize("15", &w, &h); if ((w > (SPOTS_WIDTH-2)) || (h > (SPOTS_HEIGHT-2))) num_font = FONT_SYSFIXED; #if LCD_WIDTH > LCD_HEIGHT rb->lcd_getstringsize("Moves", &w, &h); if (w > (LCD_WIDTH-IMAGE_WIDTH-1)) moves_font = FONT_SYSFIXED; rb->lcd_setfont(moves_font); rb->lcd_getstringsize("Moves", &w, &h); moves_y = 10 + h; #else rb->lcd_getstringsize("Moves: 999", &w, &h); if ((w > LCD_WIDTH) || (h > (LCD_HEIGHT-IMAGE_HEIGHT-1))) moves_font = FONT_SYSFIXED; rb->lcd_setfont(moves_font); rb->lcd_getstringsize("Moves: 999", &w, &h); moves_y = (IMAGE_HEIGHT+1+(LCD_HEIGHT-IMAGE_HEIGHT-1)/2) - h / 2; #endif for (i=0; i<NUM_SPOTS; i++) spots[i]=(i+1); #ifdef HAVE_LCD_COLOR rb->lcd_set_background(LCD_BLACK); rb->lcd_set_foreground(LCD_WHITE); rb->lcd_set_backdrop(NULL); #elif LCD_DEPTH > 1 rb->lcd_set_background(LCD_WHITE); rb->lcd_set_foreground(LCD_BLACK); rb->lcd_set_backdrop(NULL); #endif draw_playfield(); rb->sleep(HZ*2); return puzzle_loop(); }
/* the main game loop */ static int puzzle_loop(void) { int button; #if defined(PUZZLE_SHUFFLE_PICTURE_PRE) int lastbutton = BUTTON_NONE; #endif bool load_success; puzzle_init(); while(true) { button = rb->button_get(true); switch (button) { #ifdef PUZZLE_RC_QUIT case PUZZLE_RC_QUIT: #endif case PUZZLE_QUIT: /* get out of here */ return PLUGIN_OK; case PUZZLE_SHUFFLE: #ifdef PUZZLE_SHUFFLE_PICTURE_PRE if (lastbutton != PUZZLE_SHUFFLE_PICTURE_PRE) break; #endif /* mix up the pieces */ puzzle_init(); break; case PUZZLE_PICTURE: #ifdef PUZZLE_SHUFFLE_PICTURE_PRE if (lastbutton != PUZZLE_SHUFFLE_PICTURE_PRE) break; #endif /* change picture */ picmode = (picmode+1)%PICMODE_LAST_XXX; /* if load_resize_bitmap fails to load bitmap, try next picmode */ do { load_success = load_resize_bitmap(); if( !load_success ) picmode = (picmode+1)%PICMODE_LAST_XXX; } while( !load_success ); /* tell the user what mode we picked in the end! */ rb->splash(HZ,picmode_descriptions[ picmode ] ); draw_playfield(); break; case PUZZLE_LEFT: if ((hole%SPOTS_X)<(SPOTS_X-1) && !puzzle_finished()) move_spot(-1, 0); break; case PUZZLE_RIGHT: if ((hole%SPOTS_X)>0 && !puzzle_finished()) move_spot(1, 0); break; case PUZZLE_UP: if ((hole/SPOTS_X)<(SPOTS_Y-1) && !puzzle_finished()) move_spot(0, -1); break; case PUZZLE_DOWN: if ((hole/SPOTS_X)>0 && !puzzle_finished()) move_spot(0, 1); break; default: if (rb->default_event_handler(button) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; break; } #if defined(PUZZLE_SHUFFLE_PICTURE_PRE) if (button != BUTTON_NONE) lastbutton = button; #endif } }
void tetris(void) { char c, part_no; byte i, stop, start; show_splashscreen(); io_write(5, 42); io_write(6, 15); draw_playfield(); start_song(); start = 1; while (1) { if (start) { next_part_no = rand() % 7; lines = 0; curr_y = 10; remove_complete_lines(); clear_next_part(); while (io_read(128) != 255); do { vputs(95, 65, "GET READY"); buf2screen(); delay_ms(300); vputs(95, 65, " "); buf2screen(); delay_ms(300); } while (io_read(128) == 255); start = 0; } stop = 0; curr_x = 5; curr_y = 1; clear_next_part(); part_no = next_part_no; next_part_no = rand() % 7; draw_next_part(); select_part(part_no); draw_curr_part(); buf2screen(); while (!stop) { for (i = 0; i < 20 && !stop; i++) { if (lines < 20) delay_ms(35); else if (lines < 50) delay_ms(25); else if (lines < 70) delay_ms(18); else if (lines < 100) delay_ms(12); else delay_ms(8); if (!stop) { c = io_read(128); if (c == ' ') { // rotate part rotate_curr_part(); buf2screen(); } else if (c == 0) { // left, right, down c = io_read(128); if (c == 75) { // left move_left(); buf2screen(); } else if (c == 77) { // right move_right(); buf2screen(); } else if (c == 80) { // down while (!move_down()) buf2screen(); buf2screen(); stop = 1; } } else if (c == 27) return; } // if (!stop) } if (!stop) { stop = move_down(); buf2screen(); } } remove_complete_lines(); if (curr_y <= 2) { clear_playfield(); vputs(95, 65, "GAME OVER"); buf2screen(); getchar(); vputs(95, 65, " "); start = 1; } } }