int main() { BITMAP *backbuffer = NULL, *mysha; int count = 0; int old_time = 0, old_time2 = 0; int depth; int i; int use_alleg = 0; allegro_init(); install_keyboard(); install_timer(); set_config_file("examples.cfg"); depth = get_config_int("examples", "depth", 16); set_color_depth(depth); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { set_color_depth(16); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { set_color_depth(15); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { set_color_depth(32); if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) { allegro_message("Unable to set 640x480 screen mode!\n"); return -1; } } } } mysha = load_bitmap("mysha.pcx", NULL); if (!mysha) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to load mysha.pcx. Copy it from the allegro examples directory.\n"); return -2; } backbuffer = create_bitmap(SCREEN_W, SCREEN_H); if (!backbuffer) { destroy_bitmap(mysha); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Not enough memory to create backbuffer.\n"); return -3; } LOCK_FUNCTION(the_timer); LOCK_VARIABLE(chrono); stretch_blit(mysha, backbuffer, 0, 0, mysha->w, mysha->h, 0, 0, SCREEN_W, SCREEN_H); for (i = 0; i < 4; i++) { fade[i].x = (SCREEN_W/2) * (i & 1); fade[i].y = (SCREEN_H/2) * (i & 2) >> 1; fade[i].fact = rand() & 255; fade[i].dir = (rand() & 1) ? 1 : -1; fade[i].src = create_sub_bitmap(backbuffer, fade[i].x, fade[i].y, SCREEN_W/2, SCREEN_H/2); fade[i].color = makecol((i & 1) * 255, ((i & 2) >> 1) * 255, 0); } install_int(the_timer, 1); old_time = chrono; while (!key[KEY_ESC]) { if (use_alleg) { stretch_blit(mysha, backbuffer, 0, 0, mysha->w, mysha->h, 0, 0, SCREEN_W, SCREEN_H); } textprintf(backbuffer, font, 0, 0, makecol(255, 255, 255), "%s %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using FBlend", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono); if (use_alleg) { drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); for (i = 0; i < 4; i++) { set_trans_blender(0, 0, 0, 255 - fade[i].fact); rectfill(fade[i].src, 0, 0, fade[i].src->w - 1, fade[i].src->h - 1, fade[i].color); } drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } else { for (i = 0; i < 4; i++) { fblend_fade_to_color(fade[i].src, screen, fade[i].x, fade[i].y, fade[i].color, fade[i].fact); } } if (key[KEY_SPACE]) { use_alleg = !use_alleg; key[KEY_SPACE] = 0; chrono = 0; count = 0; old_time = 0; old_time2 = 0; } count++; old_time2 = chrono; /* Draw the buffer */ if (use_alleg) { blit(backbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } for (i = 0; i < 4; i++) { fade[i].fact += fade[i].dir; if (fade[i].fact >= 255 || fade[i].fact <= 0) fade[i].dir = -fade[i].dir; fade[i].fact = MID(0, fade[i].fact, 255); } } for (i = 0; i < 4; i++) { destroy_bitmap(fade[i].src); } destroy_bitmap(backbuffer); destroy_bitmap(mysha); return 0; }
int select_a_ship(void) { int ship_box [8] = {0,0,0,0,0,0,0,0}; int sbox2; int ship_chosen = 0; int level_chosen = 1; int max_level, wpixels; menu_counter = 0; counter2 = 0; int anykey = 0; int i, x, y, k; int holding_key = 1; while (TRUE) { menu_counter ++; clear_to_color(display, COL_BACK1); run_menu_background(); x = 30; y = 40; #define Y_INTERVAL 100 #define Y_BASE 45 // stages aabox(200, 50, 550, 250); TRANS_MODE rectfill(display, 375 - 80, 70, 375 + 80, 100, TRANS_BLUE2); rect(display, 375 - 80, 70 - 0, 375 + 80, 100, TRANS_BLUE3); rect(display, 375 - 81, 70 - 1, 375 + 81, 100 + 1, TRANS_BLUE2); END_TRANS textprintf_centre_ex(display, font, 375, 80, -1, -1, "select stage"); switch(arena.difficulty) { case 0: textprintf_centre_ex(display, font, 375, 115, -1, -1, "NORMAL"); break; case 1: textprintf_centre_ex(display, font, 375, 115, -1, -1, "HARD"); break; case 2: textprintf_centre_ex(display, font, 375, 115, -1, -1, "PUNISHMENT"); break; } for (i = 0; i < 3; i ++) { if (i == 0) { aabox(230 + i * 70, 140 + i * 25, 270 + i * 70, 180 + i * 25); textprintf_centre_ex(display, font, 250 + i * 70, 152 + i * 25, -1, -1, "%i", i + 1); rect(display, 276 + i * 70, 141 + i * 25, 302 + i * 70, 152 + i * 25, TRANS_BLUE3); } else if (options.stage_power [ship_chosen] [i - 1] [arena.difficulty] != 0 || options.stage_power_bar [ship_chosen] [i - 1] [arena.difficulty] != 0) { aabox(230 + i * 70, 140 + i * 25, 270 + i * 70, 180 + i * 25); if (options.stage_power [ship_chosen] [i - 1] [arena.difficulty] < 0 || options.stage_power [ship_chosen] [i - 1] [arena.difficulty] > 9) options.stage_power [ship_chosen] [i - 1] [arena.difficulty] = 0; // sanity check textprintf_centre_ex(display, font, 250 + i * 70, 152 + i * 25, -1, -1, "%i", i + 1); TRANS_MODE for (k = 0; k < options.stage_power [ship_chosen] [i - 1] [arena.difficulty]; k ++) { rectfill(display, 305 + i * 70 + k * 4, 143 + i * 25, 307 + i * 70 + k * 4, 150 + i * 25, TRANS_RED1); rect(display, 305 + i * 70 + k * 4, 143 + i * 25, 307 + i * 70 + k * 4, 150 + i * 25, TRANS_RED4); } // rect(display, 275 + i * 70, 143 + i * 25, 303 + i * 70, 152 + i * 25, COL_OUTLINE); // rect(display, 276 + i * 70, 144 + i * 25, 302 + i * 70, 151 + i * 25, COL_LGREY); rect(display, 276 + i * 70, 141 + i * 25, 302 + i * 70, 152 + i * 25, TRANS_BLUE3); #define LEVEL_CALC2 (3500 + (1100 * options.stage_power [ship_chosen] [i - 1] [arena.difficulty])) // duplicated in enemy.c and level.c wpixels = ((float) (options.stage_power_bar [ship_chosen] [i - 1] [arena.difficulty] * 20) / LEVEL_CALC2); if (wpixels >= 20 || wpixels < 0) wpixels = 19; if (wpixels > 0) { rectfill(display, 279 + i * 70, 143 + i * 25, 279 + i * 70 + wpixels, 150 + i * 25, TRANS_RED1); rect(display, 278 + i * 70, 143 + i * 25, 278 + wpixels + i * 70, 150 + i * 25, TRANS_RED5); } END_TRANS } TRANS_MODE if (level_chosen - 1 == i) rectfill(display, 230 + i * 70, 140 + i * 25, 270 + i * 70, 180 + i * 25, TRANS_BLUE2); END_TRANS } if (options.clear [ship_chosen] [arena.difficulty]) { TRANS_MODE rectfill(display, 207, 236, 214, 243, TRANS_BLUE4); END_TRANS textprintf_ex(display, font, 219, 231, -1, -1, "cleared"); } else if (options.finished [ship_chosen] [arena.difficulty]) { TRANS_MODE rectfill(display, 207, 236, 214, 243, TRANS_RED4); END_TRANS textprintf_ex(display, font, 219, 231, -1, -1, "finished"); } // ships draw_rle_sprite(display, eRLE_player [S_PLAYER1_1], x + 25 - 16, y + Y_BASE - 20 + 7); draw_rle_sprite(display, eRLE_player [S_PLAYER2_1], x + 25 - 19, y + Y_INTERVAL + Y_BASE - 8 - 5); draw_rle_sprite(display, eRLE_player [S_PLAYER3_1], x + 25 - 22, y + Y_INTERVAL * 2 + Y_BASE - 7 - 6); draw_rle_sprite(display, eRLE_player [S_PLAYER4_1], x + 25 - 16, y + Y_INTERVAL * 3 + Y_BASE - 9 - 4); draw_rle_sprite(display, eRLE_player [S_PLAYER4_1L], x + 25 - 16, y + Y_INTERVAL * 3 + Y_BASE - 4 + 3); draw_rle_sprite(display, eRLE_player [S_PLAYER5_1], x + 25 - 17, y + Y_INTERVAL * 4 + Y_BASE - 21); // draw_rle_sprite(display, eRLE_player [S_PLAYER6_1], x + 25 - 16, y + Y_INTERVAL * 5 + 25 - 16); /* textprintf_centre_ex(display, font, 100, 32, -1, -1, "g"); textprintf_centre_ex(display, font, 100, 44, -1, -1, "g"); textprintf_centre_ex(display, font, 100, 56, -1, -1, "g"); textprintf_centre_ex(display, font, 100, 68, -1, -1, "g"); textprintf_centre_ex(display, font, 100, 80, -1, -1, "g"); */ TRANS_MODE for (i = 0; i < 5; i ++) { rectfill(display, x, y - 25 + Y_BASE + i * Y_INTERVAL, x + 50, y + 25 + Y_BASE + i * Y_INTERVAL, TRANS_BLUE1); rect(display, x - 1, y - 25 + Y_BASE + i * Y_INTERVAL - 1, x + 50 + 1, y + 25 + Y_BASE + i * Y_INTERVAL + 1, TRANS_BLUE2); rect(display, x - 2, y - 25 + Y_BASE + i * Y_INTERVAL - 2, x + 50 + 2, y + 25 + Y_BASE + i * Y_INTERVAL + 2, TRANS_BLUE3); rect(display, x - 3, y - 25 + Y_BASE + i * Y_INTERVAL - 3, x + 50 + 3, y + 25 + Y_BASE + i * Y_INTERVAL + 3, TRANS_BLUE1); if (ship_chosen == i) { switch((menu_counter / 4) % 4) { case 0: default: rectfill(display, x - 1, y + i * Y_INTERVAL - 1 - 25 + Y_BASE, x + 50 + 1, y + 25 + Y_BASE + i * Y_INTERVAL + 1, TRANS_BLUE2); break; /* case 1: rectfill(display, x - 1, y + i * Y_INTERVAL - 1, x + 50 + 1, y + 50 + i * Y_INTERVAL + 1, TRANS_BLUE3); break; case 2: rectfill(display, x - 1, y + i * Y_INTERVAL - 1, x + 50 + 1, y + 50 + i * Y_INTERVAL + 1, TRANS_BLUE2); break; case 3: rectfill(display, x - 1, y + i * Y_INTERVAL - 1, x + 50 + 1, y + 50 + i * Y_INTERVAL + 1, TRANS_BLUE1); break;*/ } } if (ship_box [i] > 0) { sbox2 = ship_box [i]; // if (ship_box [ship_chosen] > 12 + xpart(menu_counter * 8, 5)) // sbox2 = 12 + xpart(menu_counter * 8, 5); rect(display, x - 3 - sbox2, y + i * Y_INTERVAL - 3 - sbox2 - 25 + Y_BASE, x + 50 + 3 + sbox2, y + 25 + Y_BASE + i * Y_INTERVAL + 3 + sbox2, TRANS_BLUE3); ship_box [i] --; } } END_TRANS ship_box [ship_chosen] += 2; if (ship_box [ship_chosen] > 15)// + xpart(menu_counter * 8, 5)) ship_box [ship_chosen] = 15; #define TITLE_X 375 #define TITLE_Y 320 #define LINE_X 220 #define LINE1_Y 350 #define LINE2_Y 365 #define LINE3_Y 380 #define LINE4_Y 395 TRANS_MODE rectfill(display, 200, 300, 550, 550, TRANS_BLUE1); rect(display, 200 - 1, 300 - 1, 550 + 1, 550 + 1, TRANS_BLUE2); rect(display, 200 - 2, 300 - 2, 550 + 2, 550 + 2, TRANS_BLUE3); rect(display, 200 - 3, 300 - 3, 550 + 3, 550 + 3, TRANS_BLUE2); rect(display, 200 - 4, 300 - 4, 550 + 4, 550 + 4, TRANS_BLUE1); sbox2 = ship_box [ship_chosen]; rect(display, 200 - sbox2 - 0, 300 - sbox2 - 0, 550 + sbox2 + 0, 550 + sbox2 + 0, TRANS_BLUE1); rect(display, 200 - sbox2 - 1, 300 - sbox2 - 1, 550 + sbox2 + 1, 550 + sbox2 + 1, TRANS_BLUE2); rect(display, 200 - sbox2 - 2, 300 - sbox2 - 2, 550 + sbox2 + 2, 550 + sbox2 + 2, TRANS_BLUE3); rect(display, 200 - sbox2 - 3, 300 - sbox2 - 3, 550 + sbox2 + 3, 550 + sbox2 + 3, TRANS_BLUE2); rect(display, 200 - sbox2 - 4, 300 - sbox2 - 4, 550 + sbox2 + 4, 550 + sbox2 + 4, TRANS_BLUE1); vline(display, TITLE_X, 550 + sbox2 + 2, 590, TRANS_BLUE3); hline(display, 5, 590, TITLE_X, TRANS_BLUE3); vline(display, 5, 40 + 25 + ship_chosen * Y_INTERVAL, 590, TRANS_BLUE3); hline(display, 5, 40 + 25 + ship_chosen * Y_INTERVAL, 30 - sbox2 - 3, TRANS_BLUE3); END_TRANS char ftext [8] [9] [150] = { { "white butterfly", "1 - autocannon", "2 - heavy cannon", "3 - seekers", "fire1 - autocannon", "fire2 - charge heavy cannon", "fire1 while charging - seekers", "" }, { "anemone", "1 - single cannon", "2 - strong, short-range blade", "3 - weak, long-range blade", "fire1 - single cannon", "fire2 - blade slash", "fire1 + fire2 - blade swing", " hold blade buttons for full circle", "" }, { "spinneret", "1 - orb beams", "2 - orb scatter fire", "3 - bomb launcher", "fire1 - orb beams", "fire1 + fire2 - orb fire", "fire2 - bomb launcher", "" }, { "hand of xom", "1 - multi-cannon", "2 - closed hand", "3 - open hand", "fire1 - multi-cannon", "fire2 - open up hand" "", "" } , { "chaos squid", "1 - chaos droplets", "2 - chaos swarm", "3 - orb field", "fire1 while orb docked - fire droplets", "fire1 while orb loose - fire swarm", "fire2 - control orb", "fire1 + fire2 - repel orb" } }; #define TEXT_X 230 TRANS_MODE rectfill(display, TITLE_X - 80, TITLE_Y - 0, TITLE_X + 80, TITLE_Y + 30, TRANS_BLUE2); rect(display, TITLE_X - 80, TITLE_Y - 0, TITLE_X + 80, TITLE_Y + 30, TRANS_BLUE3); rect(display, TITLE_X - 81, TITLE_Y - 1, TITLE_X + 81, TITLE_Y + 31, TRANS_BLUE2); textprintf_centre_ex(display, font, TITLE_X, TITLE_Y + 10, -1, -1, ftext [ship_chosen] [0]); if (ship_chosen == 4 && options.unlock [arena.difficulty] == 0) { textprintf_centre_ex(display, font, TITLE_X, TITLE_Y + 80, -1, -1, "finish stage 3 to unlock"); } else { hline(display, 198, LINE1_Y + 30, 320, TRANS_BLUE3); textprintf_ex(display, font, TEXT_X - 5, LINE1_Y + 20, -1, -1, "weapons"); textprintf_ex(display, font, TEXT_X, LINE1_Y + 40, -1, -1, ftext [ship_chosen] [1]); textprintf_ex(display, font, TEXT_X, LINE1_Y + 55, -1, -1, ftext [ship_chosen] [2]); textprintf_ex(display, font, TEXT_X, LINE1_Y + 70, -1, -1, ftext [ship_chosen] [3]); // textprintf_ex(display, font, TEXT_X, LINE1_Y + 60, -1, -1, ftext [ship_chosen] [4]); hline(display, 198, LINE1_Y + 110, 320, TRANS_BLUE3); textprintf_ex(display, font, TEXT_X - 5, LINE1_Y + 100, -1, -1, "controls"); textprintf_ex(display, font, TEXT_X, LINE1_Y + 120, -1, -1, ftext [ship_chosen] [4]); textprintf_ex(display, font, TEXT_X, LINE1_Y + 135, -1, -1, ftext [ship_chosen] [5]); textprintf_ex(display, font, TEXT_X, LINE1_Y + 150, -1, -1, ftext [ship_chosen] [6]); textprintf_ex(display, font, TEXT_X, LINE1_Y + 165, -1, -1, ftext [ship_chosen] [7]); } END_TRANS // ship_box [ship_chosen] = 15 + xpart(menu_counter * 8, 5); /* draw_rle_sprite(display, eRLE_player [S_PLAYER1_1], x + 25 - 16, y + 25 - 20 + 7); draw_rle_sprite(display, eRLE_player [S_PLAYER2_1], x + 90 + 25 - 19, y + 25 - 8 - 5); draw_rle_sprite(display, eRLE_player [S_PLAYER3_1], x + 25 - 22, y + Y_INTERVAL + 25 - 7 - 6); draw_rle_sprite(display, eRLE_player [S_PLAYER4_1], x + 90 + 25 - 16, y + Y_INTERVAL + 25 - 9 - 4); textprintf_centre_ex(display, font, 30, 102, -1, -1, "g"); textprintf_centre_ex(display, font, 30, 114, -1, -1, "g"); textprintf_centre_ex(display, font, 30, 126, -1, -1, "g"); textprintf_centre_ex(display, font, 30, 138, -1, -1, "g"); textprintf_centre_ex(display, font, 30, 150, -1, -1, "g"); TRANS_MODE for (i = 0; i < 4; i ++) { rectfill(display, x, y + i * Y_INTERVAL, x + 50, y + 50 + i * Y_INTERVAL, TRANS_BLUE1); rect(display, x - 1, y + i * Y_INTERVAL - 1, x + 50 + 1, y + 50 + i * Y_INTERVAL + 1, TRANS_BLUE2); rect(display, x - 2, y + i * Y_INTERVAL - 2, x + 50 + 2, y + 50 + i * Y_INTERVAL + 2, TRANS_BLUE3); rect(display, x - 3, y + i * Y_INTERVAL - 3, x + 50 + 3, y + 50 + i * Y_INTERVAL + 3, TRANS_BLUE1); rectfill(display, x + 90, y + i * Y_INTERVAL, x + 140, y + 50 + i * Y_INTERVAL, TRANS_BLUE1); rect(display, x + 90 - 1, y + i * Y_INTERVAL - 1, x + 140 + 1, y + 50 + i * Y_INTERVAL + 1, TRANS_BLUE2); rect(display, x + 90 - 2, y + i * Y_INTERVAL - 2, x + 140 + 2, y + 50 + i * Y_INTERVAL + 2, TRANS_BLUE3); rect(display, x + 90 - 3, y + i * Y_INTERVAL - 3, x + 140 + 3, y + 50 + i * Y_INTERVAL + 3, TRANS_BLUE1); } END_TRANS */ if (key [KEY_ESC]) return -1; anykey = 0; for (i = KEY_A; i < KEY_CAPSLOCK + 1; i ++) { if (key [i]) { anykey = 1; } } if (anykey == 0 && (options.joystick == 0 || any_joystick_input() == 0)) { key_wait = 0; holding_key = 0; } /* if (anykey == 0) { key_wait = 0; holding_key = 0; }*/ max_level = 1; if (options.stage_power [ship_chosen] [0] [arena.difficulty] > 0 || options.stage_power_bar [ship_chosen] [0] [arena.difficulty] > 0) max_level = 2; if (options.stage_power [ship_chosen] [1] [arena.difficulty] > 0 || options.stage_power_bar [ship_chosen] [1] [arena.difficulty] > 0) max_level = 3; // if (key_wait <= 0 && holding_key == 0) if (holding_key == 0) { if (key [player.key [CKEY_UP]] || menu_command(MC_UP)) { ship_chosen --; if (ship_chosen < 0) ship_chosen = 4; holding_key = 1; key_wait = 7; level_chosen = 1; } if (key [player.key [CKEY_DOWN]] || menu_command(MC_DOWN)) { ship_chosen ++; if (ship_chosen > 4) ship_chosen = 0; holding_key = 1; key_wait = 7; level_chosen = 1; } if (key [player.key [CKEY_LEFT]] || menu_command(MC_LEFT)) { level_chosen --; if (level_chosen < 1) level_chosen = max_level; holding_key = 1; key_wait = 7; } if (key [player.key [CKEY_RIGHT]] || menu_command(MC_RIGHT)) { level_chosen ++; if (level_chosen > max_level) level_chosen = 1; holding_key = 1; key_wait = 7; } if (key [player.key [CKEY_FIRE1]] || key [KEY_ENTER] || key [KEY_SPACE] || key [KEY_Z] || menu_command(MC_SELECT)) { if (ship_chosen != 4 || options.unlock [arena.difficulty] == 1) { arena.level = level_chosen; return ship_chosen; } } // if (key [KEY_UP] || key [KEY_8_PAD]) /* if (key [KEY_UP] || key [KEY_8_PAD]) { menu_select --; if (menu_select < 0) menu_select = MENU_EXIT; if (menu_select == MENU_CALIBRATE && options.joystick == 0) menu_select = MENU_KEYS; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_JOY_OR_KEYS - 1; // key_wait = 7; holding_key = 1; } if (key [KEY_DOWN] || key [KEY_2_PAD]) { menu_select ++; if (menu_select > MENU_EXIT) menu_select = 0; if (menu_select == MENU_CALIBRATE && options.joystick == 0) menu_select = MENU_EXIT; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_KEYS; // key_wait = 7; holding_key = 1; }*/ /* if (key [KEY_LEFT] || key [KEY_4_PAD]) { // if (menu_select == 2) // arena.starting_level = 1; key_wait = 7; holding_key = 1; }*/ } // } else key_wait --; do { thing ++; } while (ticked == 0); ticked = 0; if (arena.shift_palette > 0 && menu_counter % 12 == 0) { run_palette_shift(); build_new_palette(0, 0, 0, 0); set_palette(palet); if (arena.shift_palette == 1) arena.shift_palette = 0; } vsync(); blit(display, screen, 0, 0, 100, 0, 600, 600); };
void key_box(const char ktext [], int command) { rectfill(display, 200, 240, 400, 290, COL_OUTLINE); rect(display, 201, 241, 399, 289, COL_COL1); textprintf_centre_ex(display, font, 300, 257, -1, -1, ktext); vsync(); blit(display, screen, 0, 0, 100, 0, 600, 600); int inputted = KEY_ESC; int i; int anykey = 0; char holding = 1; do { do { thing ++; } while (ticked == 0); ticked = 0; key_wait --; anykey = 0; for (i = KEY_A; i < KEY_CAPSLOCK + 1; i ++) { if (key [i]) { anykey = 1; } } if (anykey == 0) holding = 0; // if (key_wait > 0) // continue; if (holding == 0) { for (i = KEY_A; i < KEY_CAPSLOCK + 1; i ++) { if (key [i]) { inputted = i; holding = 1; } } } // while(acceptable_char(inputted) == 0); if (acceptable_char(inputted) != 0) break; } while (TRUE); player.key [command] = inputted; key_wait = 10; }
struct optionsinfo goto_stats_menu(BITMAP *scrbuffer, DATAFILE *main_data, DATAFILE *plane_data, struct optionsinfo options, struct menuinfo stats_menu) { // function controls the stats options menu and optionally writes options to a file FILE *cfgfile; char count; float increment; char option_str[128] = ""; stats_menu.highlight = 0; // reset the selection stats_menu.selection = -1; do { // add or minus a set amount depending on which button was pressed increment = 0.05; if (stats_menu.selectupdn == -1) increment *= -1; switch (stats_menu.selection) { case 1 : stats_menu.optionval[1] += increment; break; // turn case 2 : stats_menu.optionval[2] += increment; break; // acceleration }; // add or minus a set amount depending on which button was pressed increment = 1; if (stats_menu.selectupdn == -1) increment *= -1; switch (stats_menu.selection) { case 0 : stats_menu.optionval[0] += increment; break; // plane case 3 : stats_menu.optionval[3] += increment; break; // min speed case 4 : stats_menu.optionval[4] += increment; break; // max speed case 5 : stats_menu.optionval[5] += increment; break; // num of shots case 6 : stats_menu.optionval[6] += increment; break; // shot life case 7 : stats_menu.optionval[7] += increment; break; // shot lag case 8 : stats_menu.optionval[8] += increment; break; // shot base speed case 9 : stats_menu.optionval[9] += increment; break; // laser len case 10: stats_menu = reset_type(cfgfile, stats_menu, stats_menu.optionval[0]); break; }; // make sure options are within boundaries (boundaries will be different for // each option) // vehicle if (stats_menu.optionval[0] > NUM_OF_VEHICLES-1) stats_menu.optionval[0] = 0; if (stats_menu.optionval[0] < 0) stats_menu.optionval[0] = NUM_OF_VEHICLES-1; // turn if (stats_menu.optionval[1] > 3.10) stats_menu.optionval[1] = 0; if (stats_menu.optionval[1] < 0) stats_menu.optionval[1] = 3.10; // acceleration if (stats_menu.optionval[2] > stats_menu.optionval[4]) stats_menu.optionval[2] = 0.05; if (stats_menu.optionval[2] < 0) stats_menu.optionval[2] = stats_menu.optionval[4]; // min speed if (stats_menu.optionval[3] > stats_menu.optionval[4]) stats_menu.optionval[3] = -1*stats_menu.optionval[4]; if (stats_menu.optionval[3] < -1*stats_menu.optionval[4]) stats_menu.optionval[3] = stats_menu.optionval[4]; // max speed if (stats_menu.optionval[4] > 127) stats_menu.optionval[4] = 0; if (stats_menu.optionval[4] < 0) stats_menu.optionval[4] = 127; // num of shots if (stats_menu.optionval[5] > 255) stats_menu.optionval[5] = 1; if (stats_menu.optionval[5] < 1) stats_menu.optionval[5] = 255; // shot life if (stats_menu.optionval[6] > 255) stats_menu.optionval[6] = 5; if (stats_menu.optionval[6] < 0) stats_menu.optionval[6] = 255; // shot lag if (stats_menu.optionval[7] > 255) stats_menu.optionval[7] = 0; if (stats_menu.optionval[7] < 0) stats_menu.optionval[7] = 255; // shot base speed if (stats_menu.optionval[8] > 255) stats_menu.optionval[8] = 0; if (stats_menu.optionval[8] < 0) stats_menu.optionval[8] = 255; // laser len if (stats_menu.optionval[9] > 255) stats_menu.optionval[9] = 0; if (stats_menu.optionval[9] < 0) stats_menu.optionval[9] = 255; // draw the options menu draw_menu(scrbuffer, main_data, stats_menu, stats_menu.row, stats_menu.col); textout_centre_ex(scrbuffer, main_data[FONTLARGE].dat, "Player Statistics", SCREEN_W/2, TITLE_ROW*8, GREY+15, -1); // draw the current data next to each option draw_sprite(scrbuffer, plane_data[((int)stats_menu.optionval[0])].dat, stats_menu.col+18*8, stats_menu.row-2); for (count = 1; count <= 9; count++) { sprintf(stats_menu.optionval_str[count], "%2.2f", stats_menu.optionval[count]); textout_ex(scrbuffer, font, stats_menu.optionval_str[count], stats_menu.col+18*8, stats_menu.row+count*16, YELLOW+15, -1); } blit(scrbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); // reset the selection stats_menu.selection = -1; // allow the user to make another selection stats_menu = move_menu_cursor(stats_menu); } while (stats_menu.selection != stats_menu.num_of_options-1); // copy the values back into the options structure options.vehicle = stats_menu.optionval[0]; options.turn_speed = stats_menu.optionval[1]; options.acceleration = stats_menu.optionval[2]; options.min_speed = stats_menu.optionval[3]; options.max_speed = stats_menu.optionval[4]; options.num_of_shots = stats_menu.optionval[5]; options.shot_life = stats_menu.optionval[6]; options.shot_lag = stats_menu.optionval[7]; options.shot_base_speed = stats_menu.optionval[8]; options.laser_length = stats_menu.optionval[9]; return(options); }
//--------------------------------------------------------------------- void TerrainLayerBlendMap::blit(const PixelBox &src) { blit(src, Box(0,0,0,mBuffer->getWidth(),mBuffer->getHeight(),1)); }
void show_intro_text(void) { int end=0; int time=0; int i; float alpha=0; float a_add=1; float x=-130; float y=200; float x_add=0.4; int row=0; float bx=0,by=0; float bx_add=0.2,by_add=0.4; float b_alpha=255; float b_alpha_add=-2; char *story_text[30] = {"The year is 1928.", "", "You are Nick Cane, a mineral expert at a", "mine-company in Boston. Today your job", "is to go to a little town in the woods", "called Lauder and do an investegation of", "a mine, to see if there is any chance of", "finding any valuable minerals there.", "", "Your comapny arranges a car to drive you", "there but since you will arrive quite late", "the car won't be back until the morning.", "You have therefor arranged so that you", "stay the night at George Smith, the man", "owning the mine.", "", "At ten past nine pm you arrive a lauder.", "END"}; char text[50]="GRIPDESIGN"; //BITMAP *bmp; //BITMAP *bmp2; //BITMAP *pic; //bmp = create_bitmap(480,40); //bmp2 = create_bitmap(480,480); //clear_to_color(bmp,makecol(255,0,255)); //font_intro = load_datafile("graphic/fonts/intro.dat"); //if(font_intro==NULL){allegro_message("couldn't load font intro");return;} fiend_fadeout(8); /*if(!play_fiend_music("Intro.it",0)) {allegro_message("couldn't load intro.it");return;} speed_counter = 0; pic = load_bitmap("graphic/menu/intro1.pcx",NULL); stretch_sprite(bmp2, pic,0,0,480,480); destroy_bitmap(pic); while(!end && !key[KEY_ESC]) { while(speed_counter>0) { time++; if(time==1750) { b_alpha_add = -b_alpha_add; } if(time==2000) { pic = load_bitmap("graphic/menu/intro2.pcx",NULL); stretch_sprite(bmp2, pic,0,0,480,480); destroy_bitmap(pic); bx_add=0.1; by_add=-0.25; b_alpha_add = -b_alpha_add; } if(time==4750) { b_alpha_add = -b_alpha_add; } if(time==5000) { pic = load_bitmap("graphic/menu/intro3.pcx",NULL); stretch_sprite(bmp2, pic,0,0,480,480); destroy_bitmap(pic); bx_add=-0.5; by_add=-0.2; b_alpha_add = -b_alpha_add; } if(time==7800) { b_alpha_add = -b_alpha_add; } if(time==250) { a_add = -a_add; } if(time==500) { strcpy(text,"PRESENTS"); a_add = -a_add; x = 100; x_add=-x_add; y = 255; } if(time==750) { a_add = -a_add; } if(time==1000) { strcpy(text,"FIEND"); a_add = -a_add; x = -100; x_add=-x_add; y = 220; } if(time==1400) { a_add = -a_add; } if(time==1650) { strcpy(text,"PROGRAMMING"); a_add = -a_add; x = 100; x_add=-x_add; y = 200; } if(time==1900) { a_add = -a_add; } if(time==2150) { strcpy(text,"THOMAS GRIP"); a_add = -a_add; x = -60; x_add=-x_add; y = 240; } if(time==2300) { a_add = -a_add; } if(time==2550) { strcpy(text,"PIERRE RENAUX"); a_add = -a_add; x = 70; x_add=-x_add; y = 230; } if(time==2700) { a_add = -a_add; } if(time==2950) { strcpy(text,"GRAPHICS"); a_add = -a_add; x = -100; x_add=-x_add; y = 170; } if(time==3200) { a_add = -a_add; } if(time==3450) { strcpy(text,"THOMAS GRIP"); a_add = -a_add; x = 80; x_add=-x_add; y = 230; } if(time==3700) { a_add = -a_add; } if(time==3950) { strcpy(text,"ARON MATTSON"); a_add = -a_add; x = -70; x_add=-x_add; y = 210; } if(time==4200) { a_add = -a_add; } if(time==4450) { strcpy(text,"IVAN SOBTCHOUK"); a_add = -a_add; x = 120; x_add=-x_add; y = 270; } if(time==4700) { a_add = -a_add; } if(time==4950) { strcpy(text,"GRAPHTALLICA"); a_add = -a_add; x = -30; x_add=-x_add; y = 220; } if(time==5200) { a_add = -a_add; } if(time==5450) { strcpy(text,"MUSIC"); a_add = -a_add; x = 130; x_add=-x_add; y = 200; } if(time==5700) { a_add = -a_add; } if(time==5950) { strcpy(text,"THOMAS GRIP"); a_add = -a_add; x = -120; x_add=-x_add; y = 260; } if(time==6200) { a_add = -a_add; } if(time==6450) { strcpy(text,"SOUND"); a_add = -a_add; x = 140; x_add=-x_add; y = 150; } if(time==6700) { a_add = -a_add; } if(time==6950) { strcpy(text,"LACHIE MOUAT"); a_add = -a_add; x = 30; x_add=-x_add; y = 250; } if(time==7200) { a_add = -a_add; } if(time==7450) { strcpy(text,"DEDICATED TO"); a_add = -a_add; x = 100; x_add=-x_add; y = 150; } if(time==7700) { a_add = -a_add; } if(time==7950) { strcpy(text,"HP LOVECRAFT"); a_add = -a_add; x = -50; x_add=-x_add; y = 200; } if(time==8200) { a_add = -a_add; } if(time==8520) { end=1; } x+=x_add; alpha+=a_add; if(alpha>255)alpha=255; if(alpha<0)alpha=0; bx+=bx_add; //bx = bx%480; by+=by_add; //by = by%480; b_alpha+=b_alpha_add; if(b_alpha>255)b_alpha=255; if(b_alpha<0)b_alpha=0; speed_counter--; } clear_to_color(bmp,makecol(255,0,255)); textout_centre(bmp,font_intro->dat,text, 200,0,makecol(200,200,200)); draw_background(virt,bmp2,((int)bx)%480,((int)by)%480,b_alpha); set_trans_blender(0,0,0,alpha); draw_trans_sprite(virt,bmp,x,y); vsync(); blit(virt,screen,0,0,80,0,480,480); } stop_fiend_music(); destroy_bitmap(bmp); destroy_bitmap(bmp2); unload_datafile(font_intro);*/ speed_counter = 0; alpha = 0; a_add=3; while(strcmp(story_text[row],"END")!=0 && !key[KEY_ESC]) { while(speed_counter>0) { time++; if(time%200==0) { row++; if(strcmp(story_text[row],"")==0)row++; alpha=0; } alpha+=a_add; if(alpha>255)alpha=255; if(alpha<0)alpha=0; speed_counter--; } clear(virt); textout_ex(virt,font_avalon2->dat,story_text[row], 0,row*25,makecol(alpha,alpha,alpha), -1); for(i=0;i<row;i++) { textout_ex(virt,font_avalon2->dat,story_text[i], 0,i*25,makecol(255,255,255), -1); } //textout(virt,font_avalon2->dat,text, x2,y2,makecol(alpha2,alpha2,alpha2)); blit(virt,screen,0,0,80,0,480,480); } while(time<310 && !key[KEY_ESC]) { while(speed_counter>0) { time++; speed_counter--; } } }
void show_poem(void) { char text1[] = "That is not dead which can eternal lie"; char text2[] = "And with strange aeons even death may die"; int end=0; int time=0; float alpha1=0; float alpha2=0; float x1,y1,x2,y2; speed_counter = 0; x1 = 0; y1 = 220; x2 = 0; y2 = 260; while(!key[KEY_ESC] && !end) { while(speed_counter>0) { time++; if(time==5) play_menu_sound("gong",0); if(time<200) { alpha1+=0.5; } else if(time<600) { alpha1+=0.5; alpha2+=0.7; } else if(time<800) { alpha1-=1.6; alpha2-=1.6; } else { end=1; } if(alpha1>255)alpha1=255; if(alpha1<0)alpha1=0; if(alpha2>255)alpha2=255; if(alpha2<0)alpha2=0; speed_counter--; } clear(virt); textout_ex(virt,font_avalon2->dat,text1, x1,y1,makecol(alpha1,alpha1,alpha1), -1); textout_ex(virt,font_avalon2->dat,text2, x2,y2,makecol(alpha2,alpha2,alpha2), -1); blit(virt,screen,0,0,80,0,480,480); } }
int main(int argc, char **argv) { //CURL *curl_handle; FILE *rfptmp; BITMAP *buffer; char request[512], rfpname[256]; int len, num_posts, i; char *title, *xml; typedef struct _pl_ { int id; char *poster; int posterid; char *postdate; char *post; BITMAP *avatar; } postlist; postlist *posts; if(argc != 2) { printf("Usage: %s [a.cc username]\n", argv[0]); return -1; } sprintf(request, "http://www.bafsoft.net/acc_cache/user.php?usr=%s&cmd=rfp", argv[1]); sprintf(rfpname, "temp/%s.rfp", argv[1]); printf("%s\n", request); /*temp = fopen(rfpname, "wb"); curl_global_init(CURL_GLOBAL_ALL); curl_handle = curl_easy_init(); curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl_handle, CURLOPT_HEADER, 0); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, fwrite); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)temp); curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); curl_easy_setopt(curl_handle, CURLOPT_URL, request); curl_easy_perform(curl_handle); //curl_easy_cleanup(curl_handle); fclose(temp);*/ curl.download(request, rfpname); /** printf("%d%s", strlen($rfp['title']), $rfp['title']); printf("%d%s", strlen($rfp['xml']), $rfp['xml']); printf("%d ", $rfp['pcount']); for($i = 0; $i < $rfp['pcount']; $i++) { printf("%d%s", strlen($rfp['posts'][$i]['poster']), $rfp['posts'][$i]['poster']); printf("%d ", $rfp['posts'][$i]['posterid']); printf("%d%s", strlen($rfp['posts'][$i]['postdate']), $rfp['posts'][$i]['postdate']); printf("%d %s ", strlen($rfp['posts'][$i]['post']), $rfp['posts'][$i]['post']); }**/ /// typedef struct { int id; char *poster, int posterid; char *postdate; char *post; } postlist; printf("Lets go to allegro...\n"); allegro_init(); install_keyboard(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768, 0, 0); buffer = create_bitmap(1024, 768); rfptmp = fopen(rfpname, "rb"); fscanf(rfptmp, "%d", &len); title = (char *)malloc(len + 1); fread(title, len, 1, rfptmp); title[len] = 0; fscanf(rfptmp, "%d", &len); xml = (char *)malloc(len + 1); fread(xml, len, 1, rfptmp); xml[len] = 0; fscanf(rfptmp, "%d ", &num_posts); posts = (postlist *)malloc(sizeof(postlist) * num_posts); for(i = 0; i < num_posts; ++i) { posts[i].id = i; fscanf(rfptmp, "%d", &len); posts[i].poster = (char *)malloc(len + 1); fread(posts[i].poster, len, 1, rfptmp); posts[i].poster[len] = 0; fscanf(rfptmp, "%d ", &posts[i].posterid); fscanf(rfptmp, "%d", &len); posts[i].postdate = (char *)malloc(len + 1); fread(posts[i].postdate, len, 1, rfptmp); posts[i].postdate[len] = 0; fscanf(rfptmp, "%d ", &len); posts[i].post = (char *)malloc(len + 1); fread(posts[i].post, len, 1, rfptmp); posts[i].post[len] = 0; printf("Avatar %d\n", i); posts[i].avatar = get_avatar(posts[i].posterid); //printf("DOWNLOADING AVATARS... (%d/%d) %d%% done\r", i + 1, num_posts, (int)(((float)(i + 1) / (float)num_posts) * 100)); clear_bitmap(buffer); textprintf_ex(buffer, font, 50, 50, makecol(255,255,255), -1, "Downloading Avatars...."); textprintf_ex(buffer, font, 70, 70, makecol(255,255,255), -1, "(%d/%d) %d%%", i + 1, num_posts, (int)(((float)(i + 1) / (float)num_posts) * 100)); /// 668 -> 868 rect(buffer, 412, 100, 612, 150, makecol(255,255,255)); rectfill(buffer, 413, 101, 412 + (2 * (int)(((float)(i + 1) / (float)num_posts) * 100)), 149, makecol(0,0,255)); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } //curl_easy_perform(curl_handle); //curl_easy_cleanup(curl_handle); clear_bitmap(screen); //set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0); //printf("Topic: %s XML URL: %s Number of Posts: %d\n", title, xml, num_posts); //for(i = 0; i < (num_posts < 9 ? num_posts : 9); ++i) for(i = 0; i < (num_posts < (SCREEN_W / 96) ? num_posts : (SCREEN_W / 96)); ++i) { //printf("Post %d Posted by: %s [%d] %s\n============================================================================\n%s\n============================================================================\n", i, posts[i].poster, posts[i].posterid, posts[i].postdate, posts[i].post); /// 96 height for each printf("\n%d", i); blit(posts[i].avatar, screen, 0, 0, 8, (i * 96) + 14, 80, 80); textprintf_ex(screen, font, 8, (i * 96) + 2, makecol(255,255,255), -1, "%s [%d]", posts[i].poster, posts[i].posterid); ///textprintf_ex(screen, font, 100, (i * 96) + 2 + text_height(font), makecol(255,255,255), -1, "%s", posts[i].post); do_wrapped_text(screen, font, 100, ((i * 96) + 2) + text_height(font), SCREEN_W - 102, (94 - text_height(font)) / text_height(font), makecol(255,255,255), -1, posts[i].post); } while(!keypressed()) ; for(i = 0; i < num_posts; ++i) { free(posts[i].poster); free(posts[i].postdate); free(posts[i].post); //destroy_bitmap(posts[i].avatar); } free(posts); clean_avatars(); return 0; }
void cScreen::blit( cSprite *pSprite, byte pSpriteNo ) { blit( pSprite->_surface, pSprite->mX, pSprite->mY, pSprite->_rPriority, pSpriteNo ); }
/////////////////////////////////////////////////////////////////// // // Function Name: refreshbmps // Description: Repaints the edges with new router coordinates. // /////////////////////////////////////////////////////////////////// void Edge::refreshbmps(bool useThread) { double dist, doubR1X, doubR1Y, doubR2X, doubR2Y; painted_usage = 0.0; painted_percent = -1; currX = 0; currY = 0; if (useThread) { r1x = threadZero->getRouterAt(sourceIndex) ->getXPixel(); // set coordinates of routers r1y = threadZero->getRouterAt(sourceIndex)->getYPixel(); r2x = threadZero->getRouterAt(destinationIndex)->getXPixel(); r2y = threadZero->getRouterAt(destinationIndex)->getYPixel(); } else { r1x = topoRouters[sourceIndex]->getXPixel(); // set coordinates of routers r1y = topoRouters[sourceIndex]->getYPixel(); r2x = topoRouters[destinationIndex]->getXPixel(); r2y = topoRouters[destinationIndex]->getYPixel(); } if (!useThread && r3x == r1x && r3y == r1y && r4x == r2x && r4y == r2y) return; else { r3x = r1x; r3y = r1y; r4x = r2x; r4y = r2y; if (r2x == r1x) { // straight up and down invunitX = 1.0; invunitY = 0.0; dist = abs(r2y - r1y); } else if (r2y == r1y) { // slope actually 0 invunitX = 0.0; invunitY = 1.0; dist = abs(r2x - r1x); } else { doubR1X = r1x; doubR1Y = r1y; doubR2X = r2x; doubR2Y = r2y; dist = sqrt((doubR2X - doubR1X) * (doubR2X - doubR1X) + (doubR2Y - doubR1Y) * (doubR2Y - doubR1Y)); // distance formula invunitX = -(r2y - r1y) / dist; // condense to inverse unit vector invunitY = (r2x - r1x) / dist; } double angle = atan((double)(r2y - r1y) / (double)(r2x - r1x)) * (256) / (2 * M_PI); if ((r1x == r2x || r1y == r2y) && sourceIndex > destinationIndex) { r1x -= 5 * invunitX; r1y -= 5 * invunitY; r2x -= 5 * invunitX; r2y -= 5 * invunitY; } else { r1x += 5 * invunitX; r1y += 5 * invunitY; r2x += 5 * invunitX; r2y += 5 * invunitY; } if (r2x < r1x) angle += 128.0; // for bitmap edges int distInt = ceil(dist); ALLEGRO_BITMAP *temp_bmp = al_create_bitmap(distInt, 13); ALLEGRO_BITMAP *temp_bmp2 = al_create_bitmap(distInt, distInt); if (r1x < r2x) putX = r1x; else putX = r2x; if (r1y < r2y) putY = r1y; else putY = r2y; int copyX = ((distInt - abs(r2x - r1x)) / 2) - 7; int copyY = ((distInt - abs(r2y - r1y)) / 2) - 7; if (copyX < 0) copyX = 0; if (copyY < 0) copyY = 0; for (int b = 0; b < 14; b++) { al_clear_to_color(temp_bmp, makecol(255, 0, 255)); stretch_blit(tailOriginals[b], temp_bmp, 0, 0, tailOriginals[b]->w, tailOriginals[b]->h, 15, 0, tailOriginals[b]->w, temp_bmp->h); stretch_blit(arrowOriginals[b], temp_bmp, 0, 0, arrowOriginals[b]->w, arrowOriginals[b]->h, distInt - 15 - arrowOriginals[b]->w, 0, arrowOriginals[b]->w, temp_bmp->h); stretch_blit(edgeOriginals[b], temp_bmp, 0, 0, edgeOriginals[b]->w, edgeOriginals[b]->h, 15 + tailOriginals[b]->w, 0, distInt - 30 - arrowOriginals[b]->w - tailOriginals[b]->w, temp_bmp->h); al_clear_to_color(temp_bmp2, makecol(255, 0, 255)); rotate_sprite(temp_bmp2, temp_bmp, 0, (temp_bmp2->h) / 2, itofix(angle)); al_destroy_bitmap(edgeBmps[b]); edgeBmps[b] = al_create_bitmap(abs(r2x - r1x) + 14, abs(r2y - r1y) + 14); al_clear_to_color(edgeBmps[b], makecol(255, 0, 255)); blit(temp_bmp2, edgeBmps[b], copyX, copyY, 0, 0, edgeBmps[0]->w, edgeBmps[0]->h); } al_destroy_bitmap(temp_bmp); al_destroy_bitmap(temp_bmp2); // end for bitmap edges } }
int is_route_possible(int fromx, int fromy, int tox, int toy, block wss) { wallscreen = wss; suggestx = -1; // ensure it's a memory bitmap, so we can use direct access to line[] array if ((wss == NULL) || (!is_memory_bitmap(wss)) || (bitmap_color_depth(wss) != 8)) quit("is_route_possible: invalid walkable areas bitmap supplied"); if (getpixel(wallscreen, fromx, fromy) < 1) return 0; block tempw = create_bitmap_ex(8, wallscreen->w, wallscreen->h); if (tempw == NULL) quit("no memory for route calculation"); if (!is_memory_bitmap(tempw)) quit("tempw is not memory bitmap"); blit(wallscreen, tempw, 0, 0, 0, 0, tempw->w, tempw->h); int dd, ff; // initialize array for finding widths of walkable areas int thisar, inarow = 0, lastarea = 0; int walk_area_times[MAX_WALK_AREAS + 1]; for (dd = 0; dd <= MAX_WALK_AREAS; dd++) { walk_area_times[dd] = 0; walk_area_granularity[dd] = 0; } for (ff = 0; ff < tempw->h; ff++) { for (dd = 0; dd < tempw->w; dd++) { thisar = tempw->line[ff][dd]; // count how high the area is at this point if ((thisar == lastarea) && (thisar > 0)) inarow++; else if (lastarea > MAX_WALK_AREAS) quit("!Calculate_Route: invalid colours in walkable area mask"); else if (lastarea != 0) { walk_area_granularity[lastarea] += inarow; walk_area_times[lastarea]++; inarow = 0; } lastarea = thisar; } } for (dd = 0; dd < tempw->w; dd++) { for (ff = 0; ff < tempw->h; ff++) { thisar = tempw->line[ff][dd]; if (thisar > 0) putpixel(tempw, dd, ff, 1); // count how high the area is at this point if ((thisar == lastarea) && (thisar > 0)) inarow++; else if (lastarea != 0) { walk_area_granularity[lastarea] += inarow; walk_area_times[lastarea]++; inarow = 0; } lastarea = thisar; } } // find the average "width" of a path in this walkable area for (dd = 1; dd <= MAX_WALK_AREAS; dd++) { if (walk_area_times[dd] == 0) { walk_area_granularity[dd] = MAX_GRANULARITY; continue; } walk_area_granularity[dd] /= walk_area_times[dd]; if (walk_area_granularity[dd] <= 4) walk_area_granularity[dd] = 2; else if (walk_area_granularity[dd] <= 15) walk_area_granularity[dd] = 3; else walk_area_granularity[dd] = MAX_GRANULARITY; /*char toprnt[200]; sprintf(toprnt,"area %d: Gran %d", dd, walk_area_granularity[dd]); winalert(toprnt); */ } walk_area_granularity[0] = MAX_GRANULARITY; floodfill(tempw, fromx, fromy, 232); if (getpixel(tempw, tox, toy) != 232) { // Destination pixel is not walkable // Try the 100x100 square around the target first at 3-pixel granularity int tryFirstX = tox - 50, tryToX = tox + 50; int tryFirstY = toy - 50, tryToY = toy + 50; if (!find_nearest_walkable_area(tempw, tryFirstX, tryFirstY, tryToX, tryToY, tox, toy, 3)) { // Nothing found, sweep the whole room at 5 pixel granularity find_nearest_walkable_area(tempw, 0, 0, tempw->w, tempw->h, tox, toy, 5); } wfreeblock(tempw); return 0; } wfreeblock(tempw); return 1; }
/*! \brief Draw the battle screen * \author Josh Bolduc * \date Created ???????? * \date Updated 20020914 - 16:16 (RB) * * Draw the battle screen. * * \param plyr Player * \param hl Highlighted * \param sall Select all */ void battle_render (int plyr, int hl, int sall) { int a = 0; int b = 0; int sz; int t; int z; if (plyr > 0) { curw = fighter[plyr - 1].cw; curx = fighter[plyr - 1].cx; cury = fighter[plyr - 1].cy; } else { curx = -1; cury = -1; } clear_bitmap (double_buffer); blit ((BITMAP *) backart->dat, double_buffer, 0, 0, 0, 0, 320, 240); #ifdef DEBUGMODE if (debugging > 1) { rectfill (double_buffer, 0, 0, rcount / 2, 9, 15); sprintf (strbuf, "%d", rcount); print_font (double_buffer, 0, 20, strbuf, FNORMAL); sprintf (strbuf, "0: %d - %d", fighter[0].sts[S_POISON], fighter[0].sts[S_REGEN]); print_font (double_buffer, 0, 28, strbuf, FNORMAL); sprintf (strbuf, "1: %d - %d", fighter[1].sts[S_POISON], fighter[1].sts[S_REGEN]); print_font (double_buffer, 0, 36, strbuf, FNORMAL); } #endif if ((sall == 0) && (curx > -1) && (cury > -1)) { draw_sprite (double_buffer, bptr, curx + (curw / 2) - 8, cury - 8); if (plyr - 1 >= PSIZE) { t = curx + (curw / 2); t -= (strlen (fighter[plyr - 1].name) * 4); z = fighter[plyr - 1].cy - 32; if (z < 0) z = fighter[plyr - 1].cy + fighter[plyr - 1].cl; menubox (double_buffer, t - 8, z, strlen (fighter[plyr - 1].name), 1, BLUE); print_font (double_buffer, t, z + 8, fighter[plyr - 1].name, FNORMAL); } #ifdef DEBUGMODE if (debugging > 1) { /* RB TODO: Check this out. */ sprintf (strbuf, _("HP:%d (%d)"), fighter[plyr - 1].hp, fighter[plyr - 1].mhp); print_font (double_buffer, 0, 8, strbuf, FNORMAL); sprintf (strbuf, _("MP:%d (%d)"), fighter[plyr - 1].mp, fighter[plyr - 1].mmp); print_font (double_buffer, 0, 16, strbuf, FNORMAL); print_font (double_buffer, 0, 24, _("Str"), FNORMAL); print_font (double_buffer, 0, 32, _("Agi"), FNORMAL); print_font (double_buffer, 0, 40, _("Vit"), FNORMAL); print_font (double_buffer, 0, 48, _("Int"), FNORMAL); print_font (double_buffer, 0, 56, _("Sag"), FNORMAL); print_font (double_buffer, 0, 64, _("Spd"), FNORMAL); print_font (double_buffer, 0, 72, _("Aura"), FNORMAL); print_font (double_buffer, 0, 80, _("Spir"), FNORMAL); print_font (double_buffer, 0, 88, _("Att"), FNORMAL); print_font (double_buffer, 0, 96, _("Hit%"), FNORMAL); print_font (double_buffer, 0, 104, _("Def"), FNORMAL); print_font (double_buffer, 0, 112, _("Evd%"), FNORMAL); print_font (double_buffer, 0, 120, _("Mdef"), FNORMAL); sprintf (strbuf, "%d, %d, %d, %d", fighter[plyr - 1].cwt, fighter[plyr - 1].welem, fighter[plyr - 1].unl, fighter[plyr - 1].crit); print_font (double_buffer, 0, 128, strbuf, FNORMAL); sprintf (strbuf, "i -> %d,%d,%d,%d", fighter[plyr - 1].imb_s, fighter[plyr - 1].imb_a, fighter[plyr - 1].imb[0], fighter[plyr - 1].imb[1]); print_font (double_buffer, 0, 136, strbuf, FNORMAL); for (t = 0; t < 13; t++) { sprintf (strbuf, "%d", fighter[plyr - 1].stats[t]); print_font (double_buffer, 40, t * 8 + 24, strbuf, FNORMAL); } } #endif } for (z = 0; z < numchrs; z++) { b = z * 216; if (fighter[z].sts[S_DEAD] == 0) { draw_fighter (z, (sall == 1)); } else { fighter[z].aframe = 3; draw_fighter (z, 0); } menubox (double_buffer, b, 184, 11, 5, BLUE); if (fighter[z].sts[S_DEAD] == 0) { sz = bspeed[z] * 88 / ROUND_MAX; if (sz > 88) sz = 88; a = 116; if (fighter[z].sts[S_TIME] == 1) a = 83; if (fighter[z].sts[S_TIME] == 2) a = 36; a += (sz / 11); hline (double_buffer, b + 8, 229, b + sz + 8, a + 1); hline (double_buffer, b + 8, 230, b + sz + 8, a); hline (double_buffer, b + 8, 231, b + sz + 8, a - 1); } print_font (double_buffer, b + 8, 192, fighter[z].name, (hl == z + 1) ? FGOLD : FNORMAL); sprintf (strbuf, _("HP: %3d/%3d"), fighter[z].hp, fighter[z].mhp); /* RB IDEA: If the character has less than 1/5 of his/her max */ /* health points, it shows the amount with red (the */ /* character is in danger). I suggest setting that '5' */ /* as a '#define WARNING_LEVEL 5' or something like */ /* that, so we can change it easily (maybe we can let */ /* the player choose when it should be turned red). */ /* TT TODO: I like this idea; maybe somewhere in the Options */ /* menu? I find that when the bar flashes red/yellow */ /* to warn the player, it's much more eye-pleasing than */ /* just a solid color (and not too hard to implement). */ print_font (double_buffer, b + 8, 208, strbuf, (fighter[z].hp < (fighter[z].mhp / 5)) ? FRED : FNORMAL); hline (double_buffer, b + 8, 216, b + 95, 21); sz = (fighter[z].hp > 0) ? fighter[z].hp * 88 / fighter[z].mhp : 88; hline (double_buffer, b + 8, 216, b + 8 + sz, 12); sprintf (strbuf, _("MP: %3d/%3d"), fighter[z].mp, fighter[z].mmp); /* RB IDEA: Same suggestion as with health, just above. */ print_font (double_buffer, b + 8, 218, strbuf, (fighter[z].mp < (fighter[z].mmp / 5)) ? FRED : FNORMAL); hline (double_buffer, b + 8, 226, b + 95, 21); sz = (fighter[z].mp > 0) ? fighter[z].mp * 88 / fighter[z].mmp : 88; hline (double_buffer, b + 8, 226, b + 8 + sz, 12); draw_stsicon (double_buffer, 1, z, 17, b + 8, 200); } for (t = PSIZE; t < PSIZE + numens; t++) { if (fighter[t].sts[S_DEAD] == 0) { draw_fighter (t, (sall == 2)); } } if (dct == 1) { menubox (double_buffer, 152 - (strlen (ctext) * 4), 8, strlen (ctext), 1, BLUE); print_font (double_buffer, 160 - (strlen (ctext) * 4), 16, ctext, FNORMAL); } }
/*! \brief Player defeated the enemies * \author Josh Bolduc * \date Created ???????? * \date Updated * * Distribute the booty! */ static void heroes_win (void) { int tgp = 0; int index; int b; int c; int z; int nc = 0; int txp = 0; int found_item = 0; int nr = 0; int ent = 0; s_fighter t1; s_fighter t2; play_music ("rend5.s3m", 0); kq_wait (500); revert_equipstats (); for (index = 0; index < numchrs; index++) fighter[index].aframe = 4; battle_render (0, 0, 0); blit2screen (0, 0); kq_wait (250); for (index = 0; index < numchrs; index++) { if ((fighter[index].sts[S_STONE] == 0) && (fighter[index].sts[S_DEAD] == 0)) nc++; ta[index] = 0; } for (index = PSIZE; index < PSIZE + numens; index++) { txp += fighter[index].xp; tgp += fighter[index].gp; } /* JB: nc should never be zero if we won, but whatever */ if (nc > 0) txp /= nc; gp += tgp; if (tgp > 0) sprintf (strbuf, _("Gained %d xp and found %d gp."), txp, tgp); else sprintf (strbuf, _("Gained %d xp."), txp); menubox (double_buffer, 152 - (strlen (strbuf) * 4), 8, strlen (strbuf), 1, BLUE); print_font (double_buffer, 160 - (strlen (strbuf) * 4), 16, strbuf, FNORMAL); blit2screen (0, 0); blit (double_buffer, back, 0, 0, 0, 0, 352, 280); for (index = 0; index < numens; index++) { /* PH bug: (?) should found_item be reset to zero at the start of this loop? * If you defeat 2 enemies, you should (possibly) get 2 items, right? */ if ((rand () % 100) < fighter[index + PSIZE].dip) { if (fighter[index + PSIZE].defeat_item_common > 0) found_item = fighter[index + PSIZE].defeat_item_common; if (fighter[index + PSIZE].defeat_item_rare > 0) { if ((rand () % 100) < 5) found_item = fighter[index + PSIZE].defeat_item_rare; } if (found_item > 0) { if (check_inventory (found_item, 1) != 0) { sprintf (strbuf, _("%s found!"), items[found_item].name); menubox (double_buffer, 148 - (strlen (strbuf) * 4), nr * 24 + 48, strlen (strbuf) + 1, 1, BLUE); draw_icon (double_buffer, items[found_item].icon, 156 - (strlen (strbuf) * 4), nr * 24 + 56); print_font (double_buffer, 164 - (strlen (strbuf) * 4), nr * 24 + 56, strbuf, FNORMAL); nr++; } } } } if (nr > 0) { blit2screen (0, 0); wait_enter (); blit (back, double_buffer, 0, 0, 0, 0, 352, 280); } nr = 0; for (c = 0; c < numchrs; c++) { if ((party[pidx[c]].sts[S_STONE] == 0) && (party[pidx[c]].sts[S_DEAD] == 0)) { b = c * 160; player2fighter (pidx[c], &t1); if (give_xp (pidx[c], txp, 0) == 1) { menubox (double_buffer, b, 40, 18, 9, BLUE); player2fighter (pidx[c], &t2); print_font (double_buffer, b + 8, 48, _("Level up!"), FGOLD); print_font (double_buffer, b + 8, 56, _("Max HP"), FNORMAL); print_font (double_buffer, b + 8, 64, _("Max MP"), FNORMAL); print_font (double_buffer, b + 8, 72, _("Strength"), FNORMAL); print_font (double_buffer, b + 8, 80, _("Agility"), FNORMAL); print_font (double_buffer, b + 8, 88, _("Vitality"), FNORMAL); print_font (double_buffer, b + 8, 96, _("Intellect"), FNORMAL); print_font (double_buffer, b + 8, 104, _("Sagacity"), FNORMAL); sprintf (strbuf, "%3d>", t1.mhp); print_font (double_buffer, b + 96, 56, strbuf, FNORMAL); sprintf (strbuf, "%3d", t2.mhp); print_font (double_buffer, b + 128, 56, strbuf, FGREEN); sprintf (strbuf, "%3d>", t1.mmp); print_font (double_buffer, b + 96, 64, strbuf, FNORMAL); sprintf (strbuf, "%3d", t2.mmp); print_font (double_buffer, b + 128, 64, strbuf, FGREEN); for (z = 0; z < 5; z++) { sprintf (strbuf, "%3d>", t1.stats[z]); print_font (double_buffer, b + 96, z * 8 + 72, strbuf, FNORMAL); sprintf (strbuf, "%3d", t2.stats[z]); if (t2.stats[z] > t1.stats[z]) print_font (double_buffer, b + 128, z * 8 + 72, strbuf, FGREEN); else print_font (double_buffer, b + 128, z * 8 + 72, strbuf, FNORMAL); } nr++; } else menubox (double_buffer, b, 104, 18, 1, BLUE); sprintf (strbuf, _("Next level %7d"), party[pidx[c]].next - party[pidx[c]].xp); print_font (double_buffer, b + 8, 112, strbuf, FGOLD); } } blit2screen (0, 0); for (c = 0; c < numchrs; c++) if ((party[pidx[c]].sts[S_STONE] == 0) && (party[pidx[c]].sts[S_DEAD] == 0)) ent += learn_new_spells (pidx[c]); if (ent == 0) wait_enter (); }
// Woot! Print a story! void NewsLayout::printStory( std::string &headline, int *pSX, int *pSY ) { // check if we're out of stories if (!m_storiesLeft.size()) return; // Get the headline width int storyId = m_storiesLeft.back(); m_storiesLeft.pop_back(); // find the upper left corner of the story int sx = -1, sy = -1; for (int i=0; i < m_ncols; i++) { for (int j=0; j < YCOLS; j++) { if (m_layout[i][j] == storyId) { sx = i; sy = j; break; } } if (sx>=0) break; } printf("Found story at %d %d\n", sx, sy ); int yChunkSz = ( (m_newsImg->h - MAST_HITE) - 3 ) / YCOLS; // return story location to app if ((pSX)&&(pSY)) { *pSX = sx*COL_SZ + 12; *pSY = MAST_HITE + sy*yChunkSz + 12; } // Fill the story with pseudo-text int colw = 0; for (int c=sx; (c < m_ncols) && (m_layout[c][sy] == storyId); c++) { // find height of column int colh=0; for (int r=sy; (r < YCOLS) && (m_layout[c][r] == storyId); r++) colh++; // Draw story text in column int hite = sy*yChunkSz; int offs = ((float)rand() / (float)RAND_MAX) * (m_bodyText->h - (colh*yChunkSz)); if (offs < 0) offs = 0; blit( m_bodyText, m_newsImg, 0, offs, c*COL_SZ, MAST_HITE + sy*yChunkSz, m_bodyText->w, colh * yChunkSz ); colw++; } // TODO: draw real headline for (int i=0; i < 5; i++ ) { hline( m_newsImg, sx*COL_SZ+3, MAST_HITE + sy*yChunkSz + i, (sx+colw)*COL_SZ-3, makecol32( 0,0,0 ) ); } // set dirty // TOTAL HACK -- don't set dirty, but always set // dirty in dropClip so new story doesn't show up // until clips reach us //m_dirty = true; }
void main(void) { int xy,i,c,x,y,front,back,n,minc,maxc; float dzdx,dzdy,a,b,dot,norm,tmp; long p,q; RGB rgb; long starttime; int numframes; // srand(456789); srand((int)time(NULL)); // printf("%d\n",(int)time(NULL)); mytime=10; maxc=0; minc=255; // Set up ripples numripples=3; for (i=0; i<numripples; i++) { newripple(i); } Map2d<int> dzdxmap=Map2d<int>(scrwid,scrhei); Map2d<int> dzdymap=Map2d<int>(scrwid,scrhei); allegro_init (); install_keyboard (); install_timer (); set_gfx_mode (GFX_AUTODETECT, scrwid, scrhei, 0, 0); set_pallete (desktop_palette); buffer = create_bitmap (scrwid, scrhei); clear (buffer); // Set up grayscale colours for (c=0;c<=255;c++) { i=0; rgb.r=c*63/255; rgb.g=0; rgb.b=0; set_color(c,&rgb); // colors[c]=GrAllocColor(c,i,i); } PALLETE my_pallete; BITMAP *scr_buffer; scr_buffer = load_bitmap("paulcld.pcx",my_pallete); set_pallete (my_pallete); blit (scr_buffer, screen, 0,0,0,0,320,200); // circlefill (buffer, x, y, 3, 255); textout_centre (buffer, font, "Press SPACE!", 60, 220, 4); blit (buffer, screen, 0, 0, 0, 0, scrwid, scrhei); starttime=uclock(); numframes=0; while(!key[KEY_ESC]) { for (x=0; x<scrwid; x=x+jump) { for (y=0; y<scrhei; y=y+jump) { dzdx=0; dzdy=0; for (i=0;i<numripples;i++) { ripples[i].front=ripples[i].v*(mytime-ripples[i].st); ripples[i].back=ripples[i].v*(mytime-ripples[i].st)-ripples[i].w; if (ripples[i].back>scrwid) newripple(i); } for (i=0;i<numripples;i++) { xy=(sqrt((x-ripples[i].x)*(x-ripples[i].x)+(y-ripples[i].y)*(y-ripples[i].y))); // printf("xy%i",xy); // printf("x%i",x); // printf("y%i",y); // printf("rx%i",ripples[i].x); // printf("ry%i",ripples[i].y); // printf("f%i\n",front); // printf("b%i\n",back); if ((xy>2)&&(xy<ripples[i].front)&&(xy>ripples[i].back)) { // printf("*********"); a=pi/ripples[i].w*sin(2*pi*ripples[i].n/ripples[i].w*(xy-ripples[i].v*(mytime-ripples[i].st))); // printf("a%f",a); b=(float)10.0/mysquare(xy+1); // printf("b%f",b); // norm=1500/(mysquare(xy))*(exp(3*(xy-(ripples[i].v)*((mytime-ripples[i].st)))/ripples[i].w)); norm=2.0*(xy-ripples[i].back)/(ripples[i].front-ripples[i].back); // printf("n%f",norm); dzdx=dzdx+a*b*(x-ripples[i].x)*ripples[i].w*norm; dzdy=dzdy+a*b*(y-ripples[i].y)*ripples[i].w*norm; } } // dot=dzdx*lx+dzdy*ly; // dot=dot*(dzdx*0.8+dzdy*0.6); // dot=dzdx*0.8+dzdy*0.6; // dot=dzdx * 1 * 0.8 + dzdy * 1 * 0.6; // float f=mymod(0.5+dot*0.5*scale); dzdxmap.pos[x][y]=refract*dzdx; dzdymap.pos[x][y]=refract*dzdy; if (x>0 && y>0) { int nwdx=dzdxmap.pos[x-jump][y-jump]; int nedx=dzdxmap.pos[x][y-jump]; int swdx=dzdxmap.pos[x-jump][y]; int sedx=dzdxmap.pos[x][y]; int nwdy=dzdymap.pos[x-jump][y-jump]; int nedy=dzdymap.pos[x][y-jump]; int swdy=dzdymap.pos[x-jump][y]; int sedy=dzdymap.pos[x][y]; for (int i=0;i<jump;i++) for (int j=0;j<jump;j++) { float a=(float)i/(float)jump; float d=(float)j/(float)jump; int idzdx=(1.0-a)*(1.0-d)*nwdx+(a)*(1.0-d)*nedx+(1.0-a)*(d)*swdx+(a)*(d)*sedx; int idzdy=(1.0-a)*(1.0-d)*nwdy+(a)*(1.0-d)*nedy+(1.0-a)*(d)*swdy+(a)*(d)*sedy; int rx=x-jump+i+idzdx; int ry=y-jump+j+idzdy; if (rx>=0 && ry>=0 && rx<scrwid && ry<scrhei) c=getpixel(scr_buffer,rx,ry); else c=0; // c=ucharchop(8*sqrt(idzdx*idzdx+idzdy*idzdy)); putpixel(buffer,x-jump+i,y-jump+j,c); } } // GrFilledBox(x,y,x+jump-1,y+jump-1,colors[c]); } } /* for (i=0;i<numripples;i++) { mycircle(ripples[i].x,ripples[i].y,ripples[i].front,colors[0]); mycircle(ripples[i].x,ripples[i].y,ripples[i].back,colors[0]); }*/ blit (buffer, screen, 0, 0, 0, 0, scrwid, scrhei); mytime=mytime+2; numframes++; // save_bitmap(getnextfilename("bmp"),buffer,my_pallete); } destroy_bitmap(buffer); allegro_exit(); printf("%d frames per second.\n",UCLOCKS_PER_SEC*numframes/(uclock()-starttime)); printf("max col %d\n",maxc); printf("min col %d\n",minc); }
/*! \brief Activate the special skill * * This function activates the special skill for a hero, * including targetting etc. if required. * * \param attack_fighter_index Hero to process * \returns 1 if the skill was used, otherwise 0 */ int skill_use(size_t attack_fighter_index) { int tgt, found_item, a, b, c, p, cts, tx, ty, next_target = 0, nn[NUM_FIGHTERS]; size_t enemy_index; size_t fighter_index; std::unique_ptr<Raster> temp; tempa = Magic.status_adjust(attack_fighter_index); switch (pidx[attack_fighter_index]) { case SENSAR: tgt = select_enemy(attack_fighter_index, TGT_ENEMY_ONE); if (tgt == -1) { return 0; } enemy_index = (unsigned int)tgt; temp = std::unique_ptr<Raster>(new Raster(320, 240)); blit(Combat.backart, temp.get(), 0, 0, 0, 0, 320, 240); Draw.color_scale(temp.get(), Combat.backart, 16, 31); b = fighter[attack_fighter_index].mhp / 20; strcpy(attack_string, _("Rage")); display_attack_string = 1; tempa.stats[eStat::Attack] = fighter[attack_fighter_index].stats[eStat::Attack]; tempa.stats[eStat::Hit] = fighter[attack_fighter_index].stats[eStat::Hit]; if (fighter[enemy_index].crit == 1) { tempa.stats[eStat::Attack] += b; tempa.stats[eStat::Hit] += b; } Combat.fight(attack_fighter_index, enemy_index, 1); if (fighter[enemy_index].IsDead()) { for (fighter_index = PSIZE; fighter_index < PSIZE + Combat.GetNumEnemies(); fighter_index++) { if (fighter[fighter_index].IsAlive()) { nn[next_target] = fighter_index; next_target++; } } if (next_target > 0) { enemy_index = nn[kqrandom->random_range_exclusive(0, next_target)]; Combat.fight(attack_fighter_index, enemy_index, 1); } } fighter[attack_fighter_index].hp -= (b * 2); Combat.AdjustHealth(attack_fighter_index, b * 2); display_attack_string = 0; blit(temp.get(), Combat.backart, 0, 0, 0, 0, 320, 240); Effects.display_amount(attack_fighter_index, FONT_DECIDE, 0); if (fighter[attack_fighter_index].IsAlive() && fighter[attack_fighter_index].hp <= 0) { Combat.fkill(attack_fighter_index); Effects.death_animation(attack_fighter_index, 0); } break; case SARINA: fighter[attack_fighter_index].ctmem = 1000; strcpy(attack_string, _("Sweep")); display_attack_string = 1; tempa.stats[eStat::Attack] = tempa.stats[eStat::Attack] * 75 / 100; fighter[attack_fighter_index].aframe = 6; Combat.UnsetDatafileImageCoords(); Combat.battle_render(0, 0, 0); Draw.blit2screen(0, 0); kq_wait(150); Combat.multi_fight(attack_fighter_index); display_attack_string = 0; break; case CORIN: strcpy(attack_string, _("Elemental Infusion")); display_attack_string = 1; fighter[attack_fighter_index].aux = 2; if (combat_spell_menu(attack_fighter_index) == 1) { Effects.draw_castersprite( attack_fighter_index, eff[magic[fighter[attack_fighter_index].csmem].eff].kolor); Combat.UnsetDatafileImageCoords(); play_effect(22, 128); Draw.convert_cframes( attack_fighter_index, eff[magic[fighter[attack_fighter_index].csmem].eff].kolor - 3, eff[magic[fighter[attack_fighter_index].csmem].eff].kolor + 3, 0); Combat.battle_render(0, 0, 0); fullblit(double_buffer, back); for (p = 0; p < 2; p++) { for (a = 0; a < 16; a++) { tx = fighter[attack_fighter_index].cx + (fighter[attack_fighter_index].cw / 2); ty = fighter[attack_fighter_index].cy + (fighter[attack_fighter_index].cl / 2); if (p == 0) { circlefill( double_buffer, tx, ty, a, eff[magic[fighter[attack_fighter_index].csmem].eff].kolor); } else { circlefill( double_buffer, tx, ty, 15 - a, eff[magic[fighter[attack_fighter_index].csmem].eff].kolor); Combat.draw_fighter(attack_fighter_index, 0); } Draw.blit2screen(0, 0); kq_wait(50); fullblit(back, double_buffer); } } Draw.revert_cframes(attack_fighter_index, 0); Combat.battle_render(0, 0, 0); Draw.blit2screen(0, 0); infusion(attack_fighter_index, fighter[attack_fighter_index].csmem); c = Magic.mp_needed(attack_fighter_index, fighter[attack_fighter_index].csmem); if (c < 1) { c = 1; } fighter[attack_fighter_index].mp -= c; Combat.SetEtherEffectActive(attack_fighter_index, false); fighter[attack_fighter_index].aux = 1; } else { fighter[attack_fighter_index].aux = 0; display_attack_string = 0; return 0; } display_attack_string = 0; fighter[attack_fighter_index].SetInfuse(magic[fighter[attack_fighter_index].csmem].elem); break; case AJATHAR: if (fighter[attack_fighter_index].unl > 0) { strcpy(attack_string, _("Dispel Undead")); display_attack_string = 1; fullblit(double_buffer, back); for (a = 0; a < 14/*MagicNumber*/; a++) { Draw.convert_cframes(PSIZE, 1 + a, 15, 1); for (fighter_index = PSIZE; fighter_index < PSIZE + Combat.GetNumEnemies(); fighter_index++) { if (Effects.is_active(fighter_index)) { Combat.draw_fighter(fighter_index, 0); } } Draw.blit2screen(0, 0); kq_wait(50); fullblit(back, double_buffer); } Draw.revert_cframes(PSIZE, 1); display_attack_string = 0; b = fighter[attack_fighter_index].lvl * 15; for (fighter_index = PSIZE; fighter_index < PSIZE + Combat.GetNumEnemies(); fighter_index++) { if (fighter[fighter_index].IsAlive() && fighter[fighter_index].mhp > 0) { if (fighter[fighter_index].unl == 99 || fighter[fighter_index].unl == 0) { cts = 0; } else { a = (fighter[attack_fighter_index].lvl + 5) - fighter[fighter_index].unl; if (a > 0) { cts = a * 8; } else { cts = 0; } } if (kqrandom->random_range_exclusive(0, 100) < cts) { if (b >= fighter[fighter_index].hp) { b -= fighter[fighter_index].hp; Combat.SetShowDeathEffectAnimation(fighter_index, true); Combat.fkill(fighter_index); } } } } Effects.death_animation(PSIZE, 1); Combat.UnsetDatafileImageCoords(); Combat.battle_render(attack_fighter_index, attack_fighter_index, 0); } else { a = kqrandom->random_range_exclusive(0, 100); c = fighter[attack_fighter_index].lvl / 10 + 1; if (a < 25) { b = kqrandom->random_range_exclusive(0, 5 * c) + 1; } else { if (a < 90) { b = kqrandom->random_range_exclusive(0, 10 * c) + (20 * c); } else { b = kqrandom->random_range_exclusive(0, 25 * c) + (50 * c); } } strcpy(attack_string, _("Divine Cure")); display_attack_string = 1; Effects.draw_spellsprite(0, 1, 15, 1); display_attack_string = 0; for (fighter_index = 0; fighter_index < numchrs; fighter_index++) { if (!fighter[fighter_index].IsStone() && fighter[fighter_index].IsAlive()) { int amount = Magic.do_shell_check(fighter_index, b); Combat.AdjustHealth(fighter_index, amount); } } Effects.display_amount(0, FONT_YELLOW, 1); for (fighter_index = 0; fighter_index < numchrs; fighter_index++) { if (!fighter[fighter_index].IsStone() && fighter[fighter_index].IsAlive()) { Magic.adjust_hp(fighter_index, Combat.GetHealthAdjust(fighter_index)); } } } break; case CASANDRA: fighter[attack_fighter_index].atrack[0] = fighter[attack_fighter_index].stats[eStat::Aura]; fighter[attack_fighter_index].atrack[1] = fighter[attack_fighter_index].stats[eStat::Spirit]; fighter[attack_fighter_index].stats[eStat::Aura] = fighter[attack_fighter_index].stats[eStat::Aura] * 15 / 10; fighter[attack_fighter_index].stats[eStat::Spirit] = fighter[attack_fighter_index].stats[eStat::Spirit] * 15 / 10; fighter[attack_fighter_index].atrack[2] = fighter[attack_fighter_index].mrp; fighter[attack_fighter_index].mrp = fighter[attack_fighter_index].mrp * 15 / 10; if (combat_spell_menu(attack_fighter_index) == 1) { Combat.SetEtherEffectActive(attack_fighter_index, false); fighter[attack_fighter_index].aux = 1; fighter[attack_fighter_index].stats[eStat::Aura] = fighter[attack_fighter_index].atrack[0]; fighter[attack_fighter_index].stats[eStat::Spirit] = fighter[attack_fighter_index].atrack[1]; fighter[attack_fighter_index].mrp = fighter[attack_fighter_index].atrack[2]; } else { fighter[attack_fighter_index].stats[eStat::Aura] = fighter[attack_fighter_index].atrack[0]; fighter[attack_fighter_index].stats[eStat::Spirit] = fighter[attack_fighter_index].atrack[1]; fighter[attack_fighter_index].mrp = fighter[attack_fighter_index].atrack[2]; return 0; } break; case TEMMIN: fighter[attack_fighter_index].aux = 1; fighter[attack_fighter_index].defend = 1; break; case AYLA: tgt = select_enemy(attack_fighter_index, TGT_ENEMY_ONE); if (tgt == -1) { return 0; } enemy_index = (uint32_t)tgt; tx = fighter[attack_fighter_index].cx; ty = fighter[attack_fighter_index].cy; fighter[attack_fighter_index].cx = fighter[enemy_index].cx - 16; fighter[attack_fighter_index].cy = fighter[enemy_index].cy + fighter[enemy_index].cl - 40; fighter[attack_fighter_index].facing = 1; strcpy(attack_string, _("Steal")); display_attack_string = 1; Combat.battle_render(0, attack_fighter_index + 1, 0); Draw.blit2screen(0, 0); kq_wait(100); play_effect(SND_MENU, 128); kq_wait(500); display_attack_string = 0; Combat.battle_render(attack_fighter_index, attack_fighter_index, 0); found_item = 0; #ifdef DEBUGMODE if (debugging > 2) { if (fighter[enemy_index].steal_item_rare > 0) { /* This steals a rare item from monster, if there is one */ found_item = fighter[enemy_index].steal_item_rare; fighter[enemy_index].steal_item_rare = 0; } else if (fighter[enemy_index].steal_item_common > 0) { /* This steals a common item from a monster, if there is one */ found_item = fighter[enemy_index].steal_item_common; fighter[enemy_index].steal_item_common = 0; } if (found_item > 0) { if (check_inventory(found_item, 1) != 0) { sprintf(strbuf, _("%s taken!"), items[found_item].name); Draw.message(strbuf, items[found_item].icon, 0, 0, 0); } } else { if (fighter[enemy_index].steal_item_common == 0 && fighter[enemy_index].steal_item_rare == 0) { Draw.message(_("Nothing to steal!"), 255, 0, 0, 0); } else { Draw.message(_("Couldn't steal!"), 255, 0, 0, 0); } } } #else cts = party[pidx[attack_fighter_index]].lvl * 2 + 35; if (cts > 95) { cts = 95; } if (kqrandom->random_range_exclusive(0, 100) < cts) { if (fighter[enemy_index].steal_item_rare > 0 && (kqrandom->random_range_exclusive(0, 100) < 5)) { /* This steals a rare item from monster, if there is one */ found_item = fighter[enemy_index].steal_item_rare; fighter[enemy_index].steal_item_rare = 0; } else if (fighter[enemy_index].steal_item_common > 0 && (kqrandom->random_range_exclusive(0, 100) < 95)) { /* This steals a common item from a monster, if there is one */ found_item = fighter[enemy_index].steal_item_common; fighter[enemy_index].steal_item_common = 0; } if (found_item > 0) { if (check_inventory(found_item, 1) != 0) { sprintf(strbuf, _("%s taken!"), items[found_item].name); Draw.message(strbuf, items[found_item].icon, 0, 0, 0); } } else { if (fighter[enemy_index].steal_item_common == 0 && fighter[enemy_index].steal_item_rare == 0) { Draw.message(_("Nothing to steal!"), 255, 0, 0, 0); } else { Draw.message(_("Couldn't steal!"), 255, 0, 0, 0); } } } else { Draw.message(_("Couldn't steal!"), 255, 0, 0, 0); } #endif fighter[attack_fighter_index].cx = tx; fighter[attack_fighter_index].cy = ty; display_attack_string = 0; fighter[attack_fighter_index].facing = 0; Combat.battle_render(attack_fighter_index, attack_fighter_index, 0); Draw.blit2screen(0, 0); break; case NOSLOM: tgt = select_enemy(attack_fighter_index, TGT_ENEMY_ONE); if (tgt == -1) { return 0; } enemy_index = (uint32_t)tgt; reveal(enemy_index); break; default: break; } return 1; }
void TutorialMode::draw() { BITMAP * tsbBuff = tsb->getBuffer(); BITMAP * mBuff = map->getBuffer(); Point focus = map->getFocus(); int mBuffX; int mBuffY; int screenX; int screenY; int wtc; int htc; // X axis calculations if(mBuff->w <= screen->w) { mBuffX = 0; screenX = (screen->w - mBuff->w) / 2; wtc = mBuff->w; } else { mBuffX = focus.getX() - (screen->w / 2); mBuffX = mBuffX < 0 ? 0 : mBuffX; mBuffX = mBuffX > mBuff->w - screen->w ? mBuff->w - screen->w : mBuffX; screenX = 0; wtc = screen->w; } // Y axis calculations if(mBuff->h <= screen->h - tsbBuff->h) { mBuffY = 0; screenY = (screen->h - tsbBuff->h - mBuff->h) / 2; htc = mBuff->h; } else { mBuffY = focus.getY() - ((screen->h - tsbBuff->h) / 2); mBuffY = mBuffY < 0 ? 0 : mBuffY; mBuffY = mBuffY > mBuff->h - (screen->h - tsbBuff->h) ? mBuff->h - (screen->h - tsbBuff->h) : mBuffY; screenY = 0; htc = screen->h - tsbBuff->h; } blit(tsbBuff, // from screen, // to 0, // start-point-x in buffer 0, // start-point-y in buffer 0, // start-point-x in screen 0, // start-point-y in screen tsbBuff->w, // width to copy from buffer tsbBuff->h); // height to copy from buffer blit(mBuff, // from screen, // to mBuffX, // start-point-x in buffer mBuffY, // start-point-y in buffer screenX, // start-point-x in screen screenY + tsbBuff->h, // start-point-y in screen wtc, // width to copy from buffer htc); // height to copy from buffer }
static void drawChallenges(void) { Mission *m; Challenge *c; SDL_Rect r; int i, start, end; r.x = 135; r.y = 165; r.w = r.h = 96; start = page * CHALLENGES_PER_PAGE; end = start + CHALLENGES_PER_PAGE; i = 0; for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next) { m->rect = r; if (i >= start && i < end) { if (game.currentMission == m) { blit(challengeIconHighlight, r.x, r.y, 0); } else { blit(challengeIcon, r.x, r.y, 0); } drawText(r.x + (r.w / 2), r.y + 28, 30, TA_CENTER, colors.white, "%d", i + 1); if (m->available) { drawText(r.x + (r.w / 2), r.y + r.w + 5, 18, TA_CENTER, (m->completedChallenges < m->totalChallenges) ? colors.white : colors.green, "%d / %d", m->completedChallenges, m->totalChallenges); } else { drawText(r.x + (r.w / 2), r.y + r.w + 5, 18, TA_CENTER, colors.lightGrey, LOCKED_TEXT); } r.x += 150; if (r.x > SCREEN_WIDTH - 200) { r.y += 165; r.x = 135; } } i++; } r.y = SCREEN_HEIGHT - 245; r.x = 100; r.w = SCREEN_WIDTH - 200; r.h = 150; SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_RenderFillRect(app.renderer, &r); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawColor(app.renderer, 64, 64, 64, SDL_ALPHA_OPAQUE); SDL_RenderDrawRect(app.renderer, &r); r.y = 240; if (game.currentMission) { drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - r.y, 24, TA_CENTER, colors.white, game.currentMission->description); r.y -= 50; c = game.currentMission->challengeData.challenges[0]; drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, CRAFT_TEXT, game.currentMission->craft); drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (c->passed) ? colors.green : colors.white, "1. %s", getChallengeDescription(c)); r.y -= 30; drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, TIME_TEXT, timeLimit); c = game.currentMission->challengeData.challenges[1]; if (c) { drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (c->passed) ? colors.green : colors.white, "2. %s", getChallengeDescription(c)); } r.y -= 30; drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, hasRestrictions ? colors.red : colors.white, RESTRICTIONS_TEXT, restrictions); c = game.currentMission->challengeData.challenges[2]; if (c) { drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (c->passed) ? colors.green : colors.white, "3. %s", getChallengeDescription(c)); } } }
void show_ending(void) { char *story_text[30] = {"You wake up in an hospital bed.", "A nurse stands beside you.", "She says there was a forest fire.", "She says you where the only one alive.", "", "You know that is not true.", "", "Your master is with you.", "You are one with him now.", "The cermony brought you two together.", "", "Suddenly you feel an urge for human flesh.", "", "Politly you ask the nurse to come closer...", "", "END"}; int end=0; int time=0; int i; float alpha=0; float a_add=1; int row=0; speed_counter = 0; alpha = 0; a_add=2.5; clear(virt); stop_all_sounds(); stop_fiend_music(); play_menu_sound("heartbeat",0); if(fiend_show_intro) { while(strcmp(story_text[row],"END")!=0) { while(speed_counter>0) { time++; if(time%240==0) { play_menu_sound("heartbeat",0); row++; if(strcmp(story_text[row],"")==0)row++; alpha=0; } alpha+=a_add; if(alpha>255)alpha=255; if(alpha<0)alpha=0; speed_counter--; } clear(virt); textout_ex(virt,font_avalon2->dat,story_text[row], 0,row*25,makecol(alpha,alpha,alpha), -1); for(i=0;i<row;i++) { textout_ex(virt,font_avalon2->dat,story_text[i], 0,i*25,makecol(255,255,255), -1); } //textout(virt,font_avalon2->dat,text, x2,y2,makecol(alpha2,alpha2,alpha2)); blit(virt,screen,0,0,80,0,480,480); } while(time<310 && !key[KEY_ESC]) { while(speed_counter>0) { time++; speed_counter--; } } } end =0; alpha = 255; while(!end) { while(speed_counter>0) { time++; if(time>200)alpha-=0.5; if(alpha==0)end=1; if(alpha>255)alpha=255; if(alpha<0)alpha=0; speed_counter--; } clear(virt); textout_centre_ex(virt,font_arial->dat,"T H E E N D",240,220,makecol(alpha,alpha,alpha), -1); blit(virt,screen,0,0,80,0,480,480); } }
int menu(char *kategoria, int *liczba_pytan) { BITMAP *tlo = prawko_load_bitmap("grafika/tlo.bmp"); BITMAP *kategoria_bmp = create_bitmap(1, 1); BITMAP *dodatek = create_bitmap(1, 1); BITMAP *pytania = create_bitmap(1, 1); BITMAP *pytania_statyczne = create_bitmap(1, 1); BITMAP *losowe = prawko_load_bitmap("grafika/losowe.bmp"); BITMAP *egzamin = prawko_load_bitmap("grafika/egzamin.bmp"); BITMAP *oprogramie = prawko_load_bitmap("grafika/oprogramie.bmp"); BITMAP *wyjscie = prawko_load_bitmap("grafika/wyjscie.bmp"); static int aktywny = 0; int wczytaj = 2; while(TRUE) { if(wczytaj == 1 || wczytaj == 2) { if(wczytaj == 1) { destroy_bitmap(kategoria_bmp); destroy_bitmap(dodatek); destroy_bitmap(pytania); destroy_bitmap(pytania_statyczne); } switch(*kategoria) { case 'a': kategoria_bmp = prawko_load_bitmap("grafika/A/kategoria.bmp"); dodatek = prawko_load_bitmap("grafika/A/dodatek.bmp"); pytania = prawko_load_bitmap("grafika/A/pytania.bmp"); pytania_statyczne = prawko_load_bitmap("grafika/A/pytania_statyczne.bmp"); wczytaj = 0; *liczba_pytan = 60; break; case 'b': kategoria_bmp = prawko_load_bitmap("grafika/B/kategoria.bmp"); dodatek = prawko_load_bitmap("grafika/B/dodatek.bmp"); pytania = prawko_load_bitmap("grafika/B/pytania.bmp"); pytania_statyczne = prawko_load_bitmap("grafika/B/pytania_statyczne.bmp"); wczytaj = 0; *liczba_pytan = 526; break; case 'c': kategoria_bmp = prawko_load_bitmap("grafika/C/kategoria.bmp"); dodatek = prawko_load_bitmap("grafika/C/dodatek.bmp"); pytania = prawko_load_bitmap("grafika/C/pytania.bmp"); pytania_statyczne = prawko_load_bitmap("grafika/C/pytania_statyczne.bmp"); wczytaj = 0; *liczba_pytan = 193; break; case 'd': kategoria_bmp = prawko_load_bitmap("grafika/D/kategoria.bmp"); dodatek = prawko_load_bitmap("grafika/D/dodatek.bmp"); pytania = prawko_load_bitmap("grafika/D/pytania.bmp"); pytania_statyczne = prawko_load_bitmap("grafika/D/pytania_statyczne.bmp"); wczytaj = 0; *liczba_pytan = 192; break; case 't': kategoria_bmp = prawko_load_bitmap("grafika/T/kategoria.bmp"); dodatek = prawko_load_bitmap("grafika/T/dodatek.bmp"); pytania = prawko_load_bitmap("grafika/T/pytania.bmp"); pytania_statyczne = prawko_load_bitmap("grafika/T/pytania_statyczne.bmp"); wczytaj = 0; *liczba_pytan = 61; break; } } clear_to_color(bufor_glowny, COLOR_TLA); blit(tlo, bufor_glowny, 0, 0, 0, 0, tlo->w, tlo->h); blit(kategoria_bmp, bufor_glowny, 0, 0, 52, 36, kategoria_bmp->w, kategoria_bmp->h); blit(dodatek, bufor_glowny, 0, 0, 300, 149, dodatek->w, dodatek->h); blit(pytania_statyczne, bufor_glowny, 0, 0, 288, 52, pytania_statyczne->w, pytania_statyczne->h); if(aktywny == 0) blit(pytania, bufor_glowny, 0, 0, 288, 52, pytania->w, pytania->h); else if(aktywny == 1) blit(losowe, bufor_glowny, 0, 0, 244, 91, losowe->w, losowe->h); else if(aktywny == 2) blit(egzamin, bufor_glowny, 0, 0, 197, 132, egzamin->w, egzamin->h); else if(aktywny == 3) blit(oprogramie, bufor_glowny, 0, 0, 148, 171, oprogramie->w, oprogramie->h); else if(aktywny == 4) blit(wyjscie, bufor_glowny, 0, 0, 106, 209, wyjscie->w, wyjscie->h); if(key[KEY_UP]) { if(aktywny-1 > -1) aktywny--; else aktywny = 4; } else if(key[KEY_DOWN]) { if(aktywny+1 < 5) aktywny++; else aktywny = 0; } else if(key[KEY_RIGHT]) { if((*kategoria)+1 < 'a'+4) { (*kategoria)++; wczytaj = 1; } else if(*kategoria == 'd') { *kategoria = 't'; wczytaj = 1; } } else if(key[KEY_LSHIFT]) { pomoc_menu(*liczba_pytan); } else if(key[KEY_LEFT]) { if(*kategoria == 't') { *kategoria = 'd'; wczytaj = 1; } else if((*kategoria)-1 > 'a'-1) { (*kategoria)--; wczytaj = 1; } } else if(key[KEY_SPACE] || key[KEY_ENTER]) { break; } blit(przycisk_ln, bufor_glowny, 0, 0, 10, 243, przycisk_ln->w, przycisk_ln->h); textprintf_ex(bufor_glowny, font, 10+przycisk_l->w, 249, makecol(255, 255, 255), -1, "Pomoc"); blit(bufor_glowny, screen, 0, 0, 0, 0, bufor_glowny->w, bufor_glowny->h); clear_key(); keypressed(); rest(60); } destroy_bitmap(tlo); destroy_bitmap(kategoria_bmp); destroy_bitmap(dodatek); destroy_bitmap(pytania); destroy_bitmap(pytania_statyczne); destroy_bitmap(losowe); destroy_bitmap(egzamin); destroy_bitmap(oprogramie); destroy_bitmap(wyjscie); return aktywny; }
int main(void) { BITMAP *textura, *back_buffer; int x, y, c; // para rellenar la textura int tecla; int nPol; int i; char angulo_x = 0, angulo_y = 0, angulo_z = 0; POLIGONO3D cara[6]; // un cubo PUNTO3D ver_t[4]; // v‚rtices transformados para un pol¡gono V3D_f ver_p[4]; // v‚rtices proyectados (2d) para un pol¡gono PUNTO3D cam_p; // posici¢n de la camara VECTOR cam_f; // vector frente de la camara VECTOR cam_a; // vector arriba de la camara MATRIX_f matriz; printf("\nEjemplo de c mara en un solo plano."); printf("\n\nControles:"); printf("\n Flechas: mover la camara."); printf("\n\n\nPresione una tecla para comenzar...\n"); getch(); // inicializar allegro y otras cosas allegro_init(); set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); install_keyboard(); install_timer(); install_int(&cont_frames, 1000); LOCK_VARIABLE(nFrames); LOCK_VARIABLE(nFramesPorSegundo); LOCK_FUNCTION(cont_frames); back_buffer = create_bitmap(SCREEN_W, SCREEN_H); clear(back_buffer); // crear una textura textura = create_bitmap(TEX_W, TEX_H); clear(textura); c = 1; // color for(x = 0; x < TEX_W; x++) { for(y = 0; y < TEX_H; y++) { putpixel(textura, x, y, c); if(c++ > 64) c = 1; } } line(textura, 0, 0, TEX_W, TEX_H, 4); line(textura, TEX_W, 0, 0, TEX_H, 4); line(textura, 0, 0, 0, TEX_H, 4); line(textura, 0, 0, TEX_W, 0, 4); line(textura, 0, TEX_H - 1, TEX_W - 1, TEX_H - 1, 4); line(textura, TEX_W - 1, TEX_H - 1, TEX_W - 1, 0, 4); textprintf(textura, font, 1, 1, 13, "Textura"); // inicializar las coordenadas 3d del cubo cara[0].ver[0].x = -2; cara[0].ver[0].y = -2; cara[0].ver[0].z = -2; cara[0].ver[1].x = 2; cara[0].ver[1].y = -2; cara[0].ver[1].z = -2; cara[0].ver[2].x = 2; cara[0].ver[2].y = 2; cara[0].ver[2].z = -2; cara[0].ver[3].x = -2; cara[0].ver[3].y = 2; cara[0].ver[3].z = -2; cara[1].ver[0].x = 2; cara[1].ver[0].y = -2; cara[1].ver[0].z = 2; cara[1].ver[1].x = -2; cara[1].ver[1].y = -2; cara[1].ver[1].z = 2; cara[1].ver[2].x = -2; cara[1].ver[2].y = 2; cara[1].ver[2].z = 2; cara[1].ver[3].x = 2; cara[1].ver[3].y = 2; cara[1].ver[3].z = 2; cara[2].ver[0].x = -2; cara[2].ver[0].y = -2; cara[2].ver[0].z = 2; cara[2].ver[1].x = -2; cara[2].ver[1].y = -2; cara[2].ver[1].z = -2; cara[2].ver[2].x = -2; cara[2].ver[2].y = 2; cara[2].ver[2].z = -2; cara[2].ver[3].x = -2; cara[2].ver[3].y = 2; cara[2].ver[3].z = 2; cara[3].ver[0].x = 2; cara[3].ver[0].y = -2; cara[3].ver[0].z = -2; cara[3].ver[1].x = 2; cara[3].ver[1].y = -2; cara[3].ver[1].z = 2; cara[3].ver[2].x = 2; cara[3].ver[2].y = 2; cara[3].ver[2].z = 2; cara[3].ver[3].x = 2; cara[3].ver[3].y = 2; cara[3].ver[3].z = -2; cara[4].ver[0].x = -2; cara[4].ver[0].y = -2; cara[4].ver[0].z = 2; cara[4].ver[1].x = 2; cara[4].ver[1].y = -2; cara[4].ver[1].z = 2; cara[4].ver[2].x = 2; cara[4].ver[2].y = -2; cara[4].ver[2].z = -2; cara[4].ver[3].x = -2; cara[4].ver[3].y = -2; cara[4].ver[3].z = -2; cara[5].ver[0].x = -2; cara[5].ver[0].y = 2; cara[5].ver[0].z = -2; cara[5].ver[1].x = 2; cara[5].ver[1].y = 2; cara[5].ver[1].z = -2; cara[5].ver[2].x = 2; cara[5].ver[2].y = 2; cara[5].ver[2].z = 2; cara[5].ver[3].x = -2; cara[5].ver[3].y = 2; cara[5].ver[3].z = 2; // inicializar las coordenadas de la textura ver_p[0].u = 0; ver_p[0].v = 0; ver_p[1].u = TEX_W; ver_p[1].v = 0; ver_p[2].u = TEX_W; ver_p[2].v = TEX_H; ver_p[3].u = 0; ver_p[3].v = TEX_H; // inicializar c mara cam_p.x = 0; cam_p.y = 0; cam_p.z = -35; cam_f.x = 0; cam_f.y = 0; cam_f.z = 1; cam_a.x = 0; cam_a.y = -1; cam_a.z = 0; set_projection_viewport(0, 0, SCREEN_W, SCREEN_H); do { // teclado if(key[KEY_RIGHT]) { get_rotation_matrix_f(&matriz, 0, -1, 0); apply_matrix_f(&matriz, cam_f.x, cam_f.y, cam_f.z, &cam_f.x, &cam_f.y, &cam_f.z); } if(key[KEY_LEFT]) { get_rotation_matrix_f(&matriz, 0, 1, 0); apply_matrix_f(&matriz, cam_f.x, cam_f.y, cam_f.z, &cam_f.x, &cam_f.y, &cam_f.z); } if(key[KEY_UP]) { cam_p.x += cam_f.x; cam_p.y += cam_f.y; cam_p.z += cam_f.z; } if(key[KEY_DOWN]) { cam_p.x -= cam_f.x; cam_p.y -= cam_f.y; cam_p.z -= cam_f.z; } get_camera_matrix_f(&matriz, cam_p.x, cam_p.y, cam_p.z, cam_f.x, cam_f.y, cam_f.z, cam_a.x, cam_a.y, cam_a.z, 32, 1); for(nPol = 0; nPol < 6; nPol++) { // cada pol¡gono for(i = 0; i < 4; i++) { // cada v‚rtice del pol¡gono // transformaci¢n apply_matrix_f(&matriz, cara[nPol].ver[i].x, cara[nPol].ver[i].y, cara[nPol].ver[i].z, &ver_t[i].x, &ver_t[i].y, &ver_t[i].z); // proyecci¢n persp_project_f(ver_t[i].x, ver_t[i].y, ver_t[i].z, &ver_p[i].x, &ver_p[i].y); ver_p[i].z = ver_t[i].z; // requerido para renderizar la textura } // backface culling if(polygon_z_normal_f(&ver_p[0], &ver_p[1], &ver_p[2]) > 0) { quad3d_f(back_buffer, POLYTYPE_PTEX, textura, &ver_p[0], &ver_p[1], &ver_p[2], &ver_p[3]); } } textprintf(back_buffer, font, 0, 190, 2, "%d FPS", nFramesPorSegundo); blit(back_buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); nFrames++; clear(back_buffer); } while(!key[KEY_ESC]); allegro_exit(); return 0; }
int main(void){ int in; ctr = 0; lastmove = 0; pos = 0; dir = 0; nextdir = 0; tick_delay = 10; spi_init(); initscr(); /* Start curses mode */ keypad(stdscr, TRUE); nodelay(stdscr, TRUE); cbreak(); noecho(); nunchuck_init(); effect_init(); welcome(); snakesetup(); logfile = fopen("snakelog.txt","a+"); fprintf(logfile, "snake inited\n"); while(42){ in = getch(); do{ while(nunchuck_read()){ nunchuck_init(); //nunchuck_read(); mvprintw(6,0,"nunchuck reinited\n"); } }while(joyX < 10 || joyX == 255 || joyY < 10 || joyY == 255); if (dir != 1 && (in == KEY_LEFT || (joyX < XCENTER - JOYDEADZONE && joyX > 10 ))){ nextdir = 0; } else if (dir != 0 && (in == KEY_RIGHT || (joyX > XCENTER + JOYDEADZONE && joyX < 240))){ nextdir = 1; } else if (dir != 3 && (in == KEY_UP || joyY > YCENTER + JOYDEADZONE)){ nextdir = 2; } else if (dir != 2 && (in == KEY_DOWN || (joyY < YCENTER - JOYDEADZONE && joyY > 10))){ nextdir = 3; } if (joyX > 150){ } if(lastmove+tick_delay <= ctr){ lastmove = ctr; dir = nextdir; snake_do(dir); //if(!buttonC && tick_delay > 0) tick_delay--; //if(!buttonZ && tick_delay < 30) tick_delay++; } //setpixel((accelX-512)/10+WIDTH/2,(accelY-512)/20+6,127,32,16); mvprintw(0,2,"pos: %d\n", pos); mvprintw(1,0,"joy X,Y: %d, %d\n", joyX, joyY); mvprintw(2,0,"Accel X,Y,Z: %d, %d, %d\n", accelX, accelY, accelZ); mvprintw(3,0,"Button C,Z: %d, %d\n", buttonC, buttonZ); calc_score(); mvprintw(4,5,"Score: %d ", score); refresh(); //ncurses snake_draw(); effect_draw(ctr); buffer[nompos*3+1] = 127; blit(); update(); ctr++; } endwin(); /* End curses mode */ return 0; }
/* Check user interface keys */ void check_ui_keys(void) { if(check_key(KEY_TILDE)) { static const char *msg[] = {"EMU2413", "YM2413"}; if(snd.fm_which == SND_EMU2413) snd.fm_which = SND_YM2413; else snd.fm_which = SND_EMU2413; add_msg("Using %s FM sound emulator.", msg[snd.fm_which]); sound_init(); } /* Frame skip keys */ if(check_key(KEY_F1)) { frame_skip = 1; add_msg("Frame skip disabled"); }; if(check_key(KEY_F2)) { frame_skip = 2; add_msg("Frame skip set to 1"); }; if(check_key(KEY_F3)) { frame_skip = 3; add_msg("Frame skip set to 2"); }; if(check_key(KEY_F4)) { frame_skip = 4; add_msg("Frame skip set to 3"); }; /* State save/load keys */ if(check_key(KEY_F5)) { if(save_state()) add_msg("State saved to slot %d", state_slot); }; if(check_key(KEY_F6)) { state_slot = (state_slot + 1) % 10; add_msg("Slot %d", state_slot); }; if(check_key(KEY_F7)) { if(load_state()) add_msg("State loaded from slot %d", state_slot); }; /* Screen snapshot */ if(check_key(KEY_F8)) { char name[PATH_MAX]; PALETTE snap_pal; BITMAP *snap_bmp = create_bitmap_ex(option.video_depth, bitmap.viewport.w, bitmap.viewport.h); if(snap_bmp) { int i; /* Get current palette */ get_palette(snap_pal); /* Remove unused palette entries */ for(i = 0x20; i < 0xFE; i++) snap_pal[i].r = snap_pal[i].g = snap_pal[i].b = 0x00; /* Clip image */ blit(sms_bmp, snap_bmp, bitmap.viewport.x, bitmap.viewport.y, 0, 0, bitmap.viewport.w, bitmap.viewport.h); /* Generate file name */ sprintf(name, "snap%04d.pcx", snap_count); /* Remove unused bits */ if(option.video_depth == 8) { int x, y; for(y = 0; y < bitmap.viewport.h; y++) for(x = 0; x < bitmap.viewport.w; x++) putpixel(snap_bmp, x, y, getpixel(snap_bmp, bitmap.viewport.x + x, bitmap.viewport.y + y) & PIXEL_MASK); } /* Save snapshot in PCX format */ save_pcx(name, snap_bmp, snap_pal); /* Deallocate temporary bitmap */ destroy_bitmap(snap_bmp); /* Bump snapshot counter */ snap_count = (snap_count + 1) & 0xFFFF; /* Display results */ add_msg("Saved screen to %s", name); } } /* FPS meter toggle */ if(check_key(KEY_F9)) { option.fps ^= 1; add_msg("FPS meter %s", option.fps ? "on" : "off"); } /* Speed throttling */ if(check_key(KEY_F10)) { if(!option.sound) { option.throttle ^= 1; add_msg("Speed throttling %s", option.throttle ? "on" : "off"); } } /* Speed throttling */ if(check_key(KEY_F11)) { option.vsync ^= 1; add_msg("VSync %s", option.vsync ? "on" : "off"); } /* Exit keys */ if(key[KEY_ESC] || key[KEY_END]) running = 0; }
int main() { int klaw = 0; allegro_init(); install_keyboard(); set_color_depth(16); set_gfx_mode(GFX_AUTODETECT,640,480,0,0); clear_to_color(screen,makecol(10,10,10)); while( !key[KEY_ESC]) { /* klaw = readkey(); clear_to_color(screen,makecol(10,10,10)); switch (klaw) { case 7217: textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : 1"); break; case 7474: textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : 2"); break; case 7731: textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : 3"); break; case 7988: textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : 4"); break; case 8245: textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : 5"); break; } if( key[KEY_LEFT]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_LEFT]"); if( key[KEY_RIGHT]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_RIGHT]"); if( key[KEY_UP]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_UP]"); if( key[KEY_DOWN]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_DOWN]"); if( key[KEY_0]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_0]"); if( key[KEY_1]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_1]"); if( key[KEY_2]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_2]"); if( key[KEY_3]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_3]"); if( key[KEY_4]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_4]"); if( key[KEY_5]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_5]"); if( key[KEY_6]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_6]"); if( key[KEY_7]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_7]"); if( key[KEY_8]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_8]"); if( key[KEY_9]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_9]"); if( key[KEY_SPACE]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_SPACE]"); if( key[KEY_ENTER]) textprintf(screen,font,20,20,makecol(255,255,128),"Klawisz to : [KEY_ENTER]"); */ BITMAP *plik = NULL; plik = load_bmp("bmp.bmp",default_palette); if (!plik) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("nie mogê za³adowaæ obrazka Plik!"); allegro_exit(); return 0; } blit( plik, screen, 0,0, 100,100, plik->w, plik->h); readkey(); destroy_bitmap(plik); allegro_exit(); } allegro_exit(); return 0; }
//--------------------------------------------------------------------- void TerrainLayerBlendMap::loadImage(const Image& img) { blit(img.getPixelBox()); }
void Sprite::blit(const Sprite &from, int32 x, int32 y, bool transp) { blit(from, from.getArea(), x, y, transp); }
void startup_menu(void) { reset_menu_palette(); menu_select = 0; key_wait = 30; // int counter; menu_counter = 0; counter2 = 0; arena.difficulty = 0; int y1 = 170; int y2 = 190 + menu_select * 30; int y3 = 218 + menu_select * 30; int y4 = 218 + menu_select * 30; int anykey = 0; int i; //#define TEST_MUSIC #ifdef TEST_MUSIC arena.level = 3; init_beat_new_level(); #endif init_menu_circles(); while (TRUE) { #ifdef TEST_MUSIC run_beat(); #endif clear_to_color(display, COL_BACK1); run_menu_background(); menu_counter += 4; if (menu_counter >= 40) menu_counter = 0; counter2 ++; if (counter2 >= 256) counter2 = 0; // textprintf_centre_ex(display, font, 300, 190, -1, -1, "W H I T E B U T T E R F L Y"); draw_rle_sprite(display, white_RLE, 150, 150); int my = 300; y1 = my - 23; y2 = my - 10 + menu_select * 30; y3 = my + 19 + menu_select * 30; y4 = my + 150; // rectfill(display, 370, y1, 600, y2, COL_COL1); TRANS_MODE rectfill(display, 370, y2 + 9, 640, y3 - 2, TRANS_BLUE3); rect(display, 368, y2 + 7, 641, y3 - 0, TRANS_BLUE3); END_TRANS // rectfill(display, 370, y3, 600, y4, TRANS_DGREEN); textprintf_ex(display, font, 400, my, -1, -1, "START GAME"); switch(arena.difficulty) { case 0: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - NORMAL"); break; case 1: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - HARD"); break; case 2: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - PUNISHMENT"); break; } // textprintf_ex(display [2], font, 400, 260, -1, -1, "STAGE - %i", arena.starting_level); textprintf_ex(display, font, 400, my + 90, -1, -1, "SET KEYS"); textprintf_ex(display, font, 400, my + 120, -1, -1, "OPTIONS"); textprintf_ex(display, font, 400, my + 150, -1, -1, "EXIT"); // textprintf_ex(display, font, 40, 10, -1, -1, "%i", joy[0].stick[options.joy_stick].axis[0].pos); // textprintf_ex(display, font, 40, 30, -1, -1, "%i", joy[0].stick[options.joy_stick].axis[1].pos); /* if (options.joystick) textprintf_ex(display, font, 400, my + 120, -1, -1, "CALIBRATE JOYSTICK"); else { textprintf_ex(display, font, 400, my + 120, -1, -1, "NO JOYSTICK"); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); rectfill(display, 399, my + 110, 530, my + 135, CONVERT_WHITE_TO_GREY); drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } */ if (options.joystick) { if (options.key_or_joy == 1) textprintf_ex(display, font, 400, my + 60, -1, -1, "CONTROLS - JOYSTICK"); else textprintf_ex(display, font, 400, my + 60, -1, -1, "CONTROLS - KEYBOARD"); } else { textprintf_ex(display, font, 400, my + 60, -1, -1, "NO JOYSTICK"); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); rectfill(display, 399, my + 50, 530, my + 75, CONVERT_WHITE_TO_GREY); drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } // textprintf_ex(display, font, 5, 5, -1, -1, "%i", any_joystick_input()); my = 330; y2 = my + 7 + arena.just_got_highscore * 30; y3 = my + 29 + arena.just_got_highscore * 30; if (arena.just_got_highscore > 0) { rectfill(display, 0, y2 - 5, 250, y3, COL_COL3); rect(display, -1, y2 - 5 - 2, 250 + 2, y3 + 2, COL_COL4); } // textprintf_right_ex(display, font, 137, my, -1, -1, "HIGH"); // textprintf_ex(display, font, 157, my, -1, -1, "SCORES"); textprintf_centre_ex(display, font, 147, my, -1, -1, "HIGHSCORES"); textprintf_right_ex(display, font, 137, my + 40, -1, -1, "NORMAL"); textprintf_ex(display, font, 157, my + 40, -1, -1, "%i", options.highscore [0]); textprintf_right_ex(display, font, 137, my + 70, -1, -1, "HARD"); textprintf_ex(display, font, 157, my + 70, -1, -1, "%i", options.highscore [1]); textprintf_right_ex(display, font, 137, my + 100, -1, -1, "PUNISHMENT"); textprintf_ex(display, font, 157, my + 100, -1, -1, "%i", options.highscore [2]); textprintf_right_ex(display, font, 600, 570, -1, -1, "COPYRIGHT 2009 LINLEY HENZELL"); // should print last score here... anykey = 0; for (i = KEY_A; i < KEY_CAPSLOCK + 1; i ++) { if (key [i]) { anykey = 1; } } if (anykey == 0 && (options.joystick == 0 || any_joystick_input() == 0)) key_wait = 0; if (key_wait == 0) { if (menu_command(MC_UP)) { menu_select --; if (menu_select < 0) menu_select = MENU_EXIT; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_JOY_OR_KEYS - 1; key_wait = 7; } if (menu_command(MC_DOWN)) { menu_select ++; if (menu_select > MENU_EXIT) menu_select = 0; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_KEYS; key_wait = 7; } if (menu_command(MC_LEFT)) { // if (menu_select == 2) // arena.starting_level = 1; if (menu_select == MENU_JOY_OR_KEYS) { if (options.key_or_joy == 0) options.key_or_joy = 1; else options.key_or_joy = 0; } if (menu_select == MENU_DIFFICULTY) { arena.difficulty --; if (arena.difficulty < 0) arena.difficulty = 0; } key_wait = 7; } if (menu_command(MC_RIGHT)) { // if (menu_select == 2) // arena.starting_level = 2; if (menu_select == MENU_JOY_OR_KEYS) { if (options.key_or_joy == 0) options.key_or_joy = 1; else options.key_or_joy = 0; } if (menu_select == MENU_DIFFICULTY) { arena.difficulty ++; if (arena.difficulty > 2) arena.difficulty = 2; } key_wait = 7; } // if (key [KEY_ESC]) // exit(0); if (menu_command(MC_SELECT)) { if (menu_select == MENU_EXIT) { goodbye_menu_circles(); return; } if (menu_select == MENU_KEYS) { key_wait = 10; define_keys(); key_wait = 10; } if (menu_select == MENU_OPTIONS) { key_wait = 10; set_options(); key_wait = 10; } /* if (menu_select == MENU_CALIBRATE) { jstick_calibrate(); key_wait = 20; ticked = 0; }*/ if (menu_select == MENU_START) { arena.level = 1;//arena.starting_level; ticked = 0; key_wait = 30; if (ship_select() == 1) { vsync(); // clear_bitmap(screen); // clear_bitmap(display); player.type = PTYPE_BASIC; // player.type = PTYPE_BOMBER; // player.type = PTYPE_ANENOME; // player.type = PTYPE_HAND; player.weapon_level = 0; int ship_select = select_a_ship(); if (ship_select != -1) { switch(ship_select) { default: case 0: player.type = PTYPE_BASIC; break; case 1: player.type = PTYPE_ANENOME; break; case 2: player.type = PTYPE_BOMBER; break; case 3: player.type = PTYPE_HAND; break; case 4: player.type = PTYPE_SQUID; break; } if (arena.level == 1) arena.from_start = 1; else arena.from_start = 0; arena.cleared = 0; arena.unlocked = 0; menu_counter = 0; goodbye_menu_circles(); new_game(); game_loop(); if (arena.level == 4) congratulations(); arena.target_palette = PAL_MENU; arena.shift_palette = 2; init_menu_circles(); // reset_menu_palette(); key_wait = 10; // was 1 // flower_dir *= -1; ticked = 0; } } else key_wait = 20; } else key_wait = 20; } } else key_wait --; do { thing ++; } while (ticked == 0); ticked = 0; if (arena.shift_palette > 0 && menu_counter % 12 == 0) { run_palette_shift(); build_new_palette(0, 0, 0, 0); set_palette(palet); if (arena.shift_palette == 1) arena.shift_palette = 0; } vsync(); blit(display, screen, 0, 0, 100, 0, 600, 600); }; }
void Pipe::checkMessage(unsigned int width, unsigned int height) { if (!width || ! height) return; if (hSocket == INVALID_HANDLE_VALUE) { hSocket = CreateFileW(L"\\\\.\\pipe\\MumbleOverlayPipe", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hSocket == INVALID_HANDLE_VALUE) { ods("Pipe: Connection failed"); return; } ods("Pipe: Connected"); uiWidth = 0; uiHeight = 0; // initially, instantiate and send an OverlayMessage with the current process id OverlayMsg om; om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; om.omh.uiType = OVERLAY_MSGTYPE_PID; om.omh.iLength = sizeof(OverlayMsgPid); om.omp.pid = GetCurrentProcessId(); if (!sendMessage(om)) return; ods("Pipe: Process ID sent"); } // if the passed width and height do not match the current overlays uiWidth and uiHeight, re-initialize if ((uiWidth != width) || (uiHeight != height)) { release(); uiWidth = width; uiHeight = height; // instantiate and send an initialization-OverlayMessage OverlayMsg om; om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; om.omh.uiType = OVERLAY_MSGTYPE_INIT; om.omh.iLength = sizeof(OverlayMsgInit); om.omi.uiWidth = uiWidth; om.omi.uiHeight = uiHeight; if (!sendMessage(om)) return; ods("Pipe: SentInitMsg with w h %d %d", uiWidth, uiHeight); } std::vector<RECT> blits; while (1) { DWORD dwBytesLeft; DWORD dwBytesRead; if (! PeekNamedPipe(hSocket, NULL, 0, NULL, &dwBytesLeft, NULL)) { ods("Pipe: Could not peek"); disconnect(); return; } if (! dwBytesLeft) break; if (omMsg.omh.iLength == -1) { if (! ReadFile(hSocket, reinterpret_cast<unsigned char *>(omMsg.headerbuffer) + dwAlreadyRead, sizeof(OverlayMsgHeader) - dwAlreadyRead, &dwBytesRead, NULL)) { ods("Pipe: Read header fail"); disconnect(); return; } dwBytesLeft -= dwBytesRead; dwAlreadyRead += dwBytesRead; if (dwAlreadyRead != sizeof(OverlayMsgHeader)) { break; } dwAlreadyRead = 0; if (omMsg.omh.uiMagic != OVERLAY_MAGIC_NUMBER) { ods("Pipe: Invalid magic number %x", omMsg.omh.uiMagic); disconnect(); return; } if (static_cast<int>(dwBytesLeft) < omMsg.omh.iLength) continue; } if (! ReadFile(hSocket, reinterpret_cast<unsigned char *>(omMsg.msgbuffer) + dwAlreadyRead, omMsg.omh.iLength - dwAlreadyRead, &dwBytesRead, NULL)) { ods("Pipe: Read data fail"); disconnect(); return; } dwAlreadyRead += dwBytesRead; if (static_cast<int>(dwBytesLeft) < omMsg.omh.iLength) continue; dwAlreadyRead = 0; switch (omMsg.omh.uiType) { case OVERLAY_MSGTYPE_SHMEM: { wchar_t memname[2048]; memname[0] = 0; MultiByteToWideChar(CP_UTF8, 0, omMsg.oms.a_cName, omMsg.omh.iLength, memname, 2048); release(); hMemory = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, uiWidth * uiHeight * 4, memname); if (GetLastError() != ERROR_ALREADY_EXISTS) { ods("Pipe: Memory %s(%d) => %ls doesn't exist", omMsg.oms.a_cName, omMsg.omh.iLength, memname); if (hMemory) { CloseHandle(hMemory); hMemory = NULL; break; } } if (! hMemory) { ods("Pipe: CreateFileMapping failed"); break; } a_ucTexture = reinterpret_cast<unsigned char *>(MapViewOfFile(hMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0)); if (a_ucTexture == NULL) { ods("Pipe: Failed to map memory"); CloseHandle(hMemory); hMemory = NULL; break; } MEMORY_BASIC_INFORMATION mbi; memset(&mbi, 0, sizeof(mbi)); if ((VirtualQuery(a_ucTexture, &mbi, sizeof(mbi)) == 0) || (mbi.RegionSize < (uiHeight * uiWidth * 4))) { ods("Pipe: Memory too small"); UnmapViewOfFile(a_ucTexture); CloseHandle(hMemory); a_ucTexture = NULL; hMemory = NULL; break; } OverlayMsg om; om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; om.omh.uiType = OVERLAY_MSGTYPE_SHMEM; om.omh.iLength = 0; if (!sendMessage(om)) return; newTexture(uiWidth, uiHeight); } break; case OVERLAY_MSGTYPE_BLIT: { RECT r = { static_cast<LONG>(omMsg.omb.x), static_cast<LONG>(omMsg.omb.y), static_cast<LONG>(omMsg.omb.x + omMsg.omb.w), static_cast<LONG>(omMsg.omb.y + omMsg.omb.h) }; std::vector<RECT>::iterator i = blits.begin(); while (i != blits.end()) { RECT is; if (::IntersectRect(&is, &r, & *i)) { ::UnionRect(&is, &r, & *i); r = is; blits.erase(i); i = blits.begin(); } else { ++i; } } blits.push_back(r); } break; case OVERLAY_MSGTYPE_ACTIVE: { uiLeft = omMsg.oma.x; uiTop = omMsg.oma.y; uiRight = omMsg.oma.x + omMsg.oma.w; uiBottom = omMsg.oma.y + omMsg.oma.h; if (a_ucTexture) { setRect(); blit(0, 0, uiWidth, uiHeight); } } break; default: break; } omMsg.omh.iLength = -1; } if (!a_ucTexture) return; for (std::vector<RECT>::iterator i = blits.begin(); i != blits.end(); ++i) blit((*i).left, (*i).top, (*i).right - (*i).left, (*i).bottom - (*i).top); }
void set_options(void) { int i, anykey = 0; int option_select = 0; while (TRUE) { rectfill(display, 200, 240, 400, 510, COL_OUTLINE); rect(display, 201, 241, 399, 509, COL_COL1); textprintf_centre_ex(display, font, 300, 257, -1, -1, "options"); rectfill(display, 202, 300 + option_select * 20, 398, 318 + option_select * 20, TRANS_GREEN3); hline(display, 202, 298 + option_select * 20, 398, TRANS_GREEN2); hline(display, 202, 320 + option_select * 20, 398, TRANS_GREEN2); textprintf_ex(display, font, 220, 300, -1, -1, "effects volume - %i", options.sfx_volume); textprintf_ex(display, font, 220, 320, -1, -1, "music volume - %i", options.ambience_volume); if (options.windowed == 0) textprintf_ex(display, font, 220, 340, -1, -1, "mode - fullscreen"); else textprintf_ex(display, font, 220, 340, -1, -1, "mode - windowed"); if (options.run_vsync == 0) textprintf_ex(display, font, 220, 360, -1, -1, "vsync - off"); else textprintf_ex(display, font, 220, 360, -1, -1, "vsync - on"); if (options.joystick) { textprintf_ex(display, font, 220, 380, -1, -1, "fire 1 - joystick %i", options.joy_button [0] + 1); textprintf_ex(display, font, 220, 400, -1, -1, "fire 2 - joystick %i", options.joy_button [1] + 1); textprintf_ex(display, font, 220, 420, -1, -1, "fire 3 - joystick %i", options.joy_button [3] + 1); textprintf_ex(display, font, 220, 440, -1, -1, "slow move - joystick %i", options.joy_button [2] + 1); } else { textprintf_ex(display, font, 220, 400, -1, -1, "no joystick"); } textprintf_ex(display, font, 220, 460, -1, -1, "exit"); vsync(); blit(display, screen, 0, 0, 100, 0, 600, 600); anykey = 0; for (i = KEY_A; i < KEY_CAPSLOCK + 1; i ++) { if (key [i]) { anykey = 1; } } if (anykey == 0 && (options.joystick == 0 || any_joystick_input() == 0)) key_wait = 0; if (key_wait <= 0) { if (menu_command(MC_UP)) { option_select --; if (option_select < 0) option_select = OPT_EXIT; if (option_select == OPT_JOYSLOW && options.joystick == 0) option_select = OPT_VSYNC; key_wait = 7; } if (menu_command(MC_DOWN)) { option_select ++; if (option_select > OPT_EXIT) option_select = 0; if (option_select == OPT_JOY1 && options.joystick == 0) option_select = OPT_EXIT; key_wait = 7; } if (menu_command(MC_LEFT)) { if (option_select == OPT_SFX_VOLUME) { options.sfx_volume -= 10; if (options.sfx_volume < 0) options.sfx_volume = 0; } if (option_select == OPT_MUSIC_VOLUME) { options.ambience_volume -= 10; if (options.ambience_volume < 0) options.ambience_volume = 0; } if (option_select == OPT_JOY1) { if (options.joy_button [0] == 0) options.joy_button [0] = joy[0].num_buttons - 1; else options.joy_button [0] --; } if (option_select == OPT_JOY2) { if (options.joy_button [1] == 0) options.joy_button [1] = joy[0].num_buttons - 1; else options.joy_button [1] --; } if (option_select == OPT_JOYSLOW) { if (options.joy_button [2] == 0) options.joy_button [2] = joy[0].num_buttons - 1; else options.joy_button [2] --; } if (option_select == OPT_JOY3) { if (options.joy_button [3] == 0) options.joy_button [3] = joy[0].num_buttons - 1; else options.joy_button [3] --; } key_wait = 7; } if (menu_command(MC_RIGHT)) { if (option_select == OPT_SFX_VOLUME) { options.sfx_volume += 10; if (options.sfx_volume > 100) options.sfx_volume = 100; } if (option_select == OPT_MUSIC_VOLUME) { options.ambience_volume += 10; if (options.ambience_volume > 100) options.ambience_volume = 100; } if (option_select == OPT_JOY1) { if (options.joy_button [0] >= joy[0].num_buttons - 1) options.joy_button [0] = 0; else options.joy_button [0] ++; } if (option_select == OPT_JOY2) { if (options.joy_button [1] >= joy[0].num_buttons - 1) options.joy_button [1] = 0; else options.joy_button [1] ++; } if (option_select == OPT_JOY3) { if (options.joy_button [3] >= joy[0].num_buttons - 1) options.joy_button [3] = 0; else options.joy_button [3] ++; } if (option_select == OPT_JOYSLOW) { if (options.joy_button [2] >= joy[0].num_buttons - 1) options.joy_button [2] = 0; else options.joy_button [2] ++; } key_wait = 7; } if (key [KEY_ESC]) break; if (menu_command(MC_SELECT)) { if (option_select == OPT_EXIT) { break; } } if (menu_command(MC_SELECT) || menu_command(MC_LEFT) || menu_command(MC_RIGHT)) { if (option_select == OPT_MODE) { options.windowed ^= 1; key_wait = 7; } if (option_select == OPT_VSYNC) { options.run_vsync ^= 1; key_wait = 7; } } /* if (menu_select == MENU_KEYS) { key_wait = 10; define_keys(); key_wait = 10; } if (menu_select == MENU_OPTIONS) { key_wait = 10; set_options(); key_wait = 10; }*/ } // else key_wait --; do { thing ++; } while (ticked == 0); ticked = 0; vsync(); blit(display, screen, 0, 0, 100, 0, 600, 600); }; set_config_int("Misc", "sfx_volume", options.sfx_volume); set_config_int("Misc", "ambience_volume", options.ambience_volume); if (options.joystick) { set_config_int("Misc", "joy_button_1", options.joy_button [0]); set_config_int("Misc", "joy_button_2", options.joy_button [1]); set_config_int("Misc", "joy_button_slow", options.joy_button [2]); set_config_int("Misc", "joy_button_3", options.joy_button [3]); } set_config_int("Misc", "vsync", options.run_vsync); set_config_int("Misc", "Windowed", options.windowed); }
void toMenu() { BITMAP *menuBuffer = NULL; menuBuffer = create_bitmap(1024,768); //Create an empty bitmap. BITMAP *menuBackground = NULL; menuBackground = load_bitmap("Menu Background.bmp", NULL); // Load our picture BITMAP *highlighter = NULL; highlighter = load_bitmap("Menu Highlighter.bmp", NULL); // Load our picture BITMAP *smoke = NULL; smoke = load_bitmap("Menu Smoke.bmp", NULL); // Load our picture MIDI *menuMusic = NULL; menuMusic = load_midi("Soundtrack1.mid"); SAMPLE *menuClick = load_sample("Click.wav"); clear_bitmap(menuBuffer); // Clear the contents of the buffer bitmap int highlightedOption = 1; int inMenu = 1; int smokePosition = 1024; int smokePosition2 = 1024; draw_sprite(menuBuffer, menuBackground, 0, 0); draw_sprite(menuBuffer, highlighter, 6, 186); blit(menuBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen play_midi(menuMusic, 1); while (inMenu == 1) { draw_sprite(menuBuffer, menuBackground, 0, 0); smokePosition --; smokePosition2 -= 3; if (smokePosition <= -1024) { smokePosition = 0; } readkey(); if(key[KEY_UP]) { play_sample(menuClick, 155, 0, 2000, 0); highlightedOption--; if (highlightedOption <= 0) { highlightedOption = 5; } } else if(key[KEY_DOWN]) { play_sample(menuClick, 155, 0, 2000, 0); highlightedOption++; if (highlightedOption >= 6) { highlightedOption = 1; } } else if(key[KEY_ENTER]) { play_sample(menuClick, 155, 0, 4000, 0); switch (highlightedOption) { case 1: isXenoPatriots = selectRace(); newGame(); startGame(); play_midi(menuMusic, 1); break; case 2: loadGame(); break; case 3: gameOptions(); break; case 4: break; case 5: quitGame(); inMenu ^= 0; return; break; } } switch (highlightedOption) { case 1: draw_sprite(menuBuffer, highlighter, 6, 186); break; case 2: draw_sprite(menuBuffer, highlighter, 6, 278); break; case 3: draw_sprite(menuBuffer, highlighter, 6, 373); break; case 4: draw_sprite(menuBuffer, highlighter, 6, 465); break; case 5: draw_sprite(menuBuffer, highlighter, 6, 629); break; } /*draw_sprite(menuBuffer, smoke, smokePosition, 0); draw_sprite(menuBuffer, smoke, smokePosition + 1024, 0); draw_sprite(menuBuffer, smoke, smokePosition2, 0); draw_sprite(menuBuffer, smoke, smokePosition2 + 1024, 0);*/ blit(menuBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen } }