From: Tobias Gläßer Date: Sat, 28 Feb 2004 18:13:08 +0000 (+0000) Subject: Gameplay has been repaired a bit. A menu effect was added. OpenGL works without SDL_O... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=416e3a38d49f534ba8b65a63723bdb33ec018c68;p=supertux.git Gameplay has been repaired a bit. A menu effect was added. OpenGL works without SDL_OPENGLBLIT now. The leveleditor get closer to a useable state. Lots of cleanups. SVN-Revision: 151 --- diff --git a/src/badguy.c b/src/badguy.c index 622d25451..80c5f9c39 100644 --- a/src/badguy.c +++ b/src/badguy.c @@ -44,7 +44,7 @@ void badguy_init(bad_guy_type* pbad, float x, float y, int kind) pbad->base.ym = 4.8; pbad->dir = LEFT; pbad->seen = NO; - timer_init(&pbad->timer); + timer_init(&pbad->timer,YES); physic_init(&pbad->physic); } @@ -90,7 +90,7 @@ void badguy_action(bad_guy_type* pbad) } } - /* Fall if we get off the ground: */ + /* Fall if we get off the ground: */ if (pbad->dying != FALLING) { @@ -102,7 +102,7 @@ void badguy_action(bad_guy_type* pbad) physic_set_start_vy(&pbad->physic,2.); } - pbad->base.ym = physic_get_velocity(&pbad->physic); + pbad->base.ym = physic_get_velocity(&pbad->physic); } else { @@ -270,20 +270,32 @@ void badguy_action(bad_guy_type* pbad) physic_set_start_vy(&pbad->physic,0.); } - if(issolid(pbad->base.x, pbad->base.y + 32)) + if (pbad->dying != FALLING) { - physic_set_state(&pbad->physic,PH_VT); - physic_set_start_vy(&pbad->physic,6.); - pbad->base.ym = physic_get_velocity(&pbad->physic); - } - else if(issolid(pbad->base.x, pbad->base.y - 1)) - { /* This works, but isn't the best solution imagineable */ - physic_set_state(&pbad->physic,PH_VT); - physic_set_start_vy(&pbad->physic,0.); - pbad->base.ym = physic_get_velocity(&pbad->physic); + if(issolid(pbad->base.x, pbad->base.y + 32)) + { + physic_set_state(&pbad->physic,PH_VT); + physic_set_start_vy(&pbad->physic,6.); + pbad->base.ym = physic_get_velocity(&pbad->physic); + } + else if(issolid(pbad->base.x, pbad->base.y - 1)) + { /* This works, but isn't the best solution imagineable */ + physic_set_state(&pbad->physic,PH_VT); + physic_set_start_vy(&pbad->physic,0.); + pbad->base.ym = physic_get_velocity(&pbad->physic); + } + else + { + pbad->base.ym = physic_get_velocity(&pbad->physic); + } } else { + if(!physic_is_set(&pbad->physic)) + { + physic_set_state(&pbad->physic,PH_VT); + physic_set_start_vy(&pbad->physic,0.); + } pbad->base.ym = physic_get_velocity(&pbad->physic); } @@ -534,6 +546,9 @@ void badguy_collision(bad_guy_type* pbad, void *p_c_object, int c_object) else if (pbad->kind == BAD_LAPTOP) add_score(pbad->base.x - scroll_x, pbad->base.y, 25 * score_multiplier); + else if (pbad->kind == BAD_MONEY) + add_score(pbad->base.x - scroll_x, pbad->base.y, + 50 * score_multiplier); /* Play death sound: */ play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); diff --git a/src/button.c b/src/button.c index be7808a96..b52ed4ca8 100644 --- a/src/button.c +++ b/src/button.c @@ -184,8 +184,8 @@ int max_cols, row, col; row = pbutton_panel->num_items / max_cols; col = pbutton_panel->num_items % max_cols; - pbutton_panel->item[pbutton_panel->num_items-1].x = pbutton_panel->x + row * 32; - pbutton_panel->item[pbutton_panel->num_items-1].y = pbutton_panel->y + col * 32; + pbutton_panel->item[pbutton_panel->num_items-1].x = pbutton_panel->x + col * 32; + pbutton_panel->item[pbutton_panel->num_items-1].y = pbutton_panel->y + row * 32; } diff --git a/src/gameloop.c b/src/gameloop.c index 9b2d00d4e..8593b133e 100644 --- a/src/gameloop.c +++ b/src/gameloop.c @@ -186,15 +186,15 @@ void game_event(void) break; case SDLK_TAB: if(debug_mode == YES) - { - tux.size = !tux.size; - if(tux.size == BIG) - { - tux.base.height = 64; - } - else - tux.base.height = 32; - } + { + tux.size = !tux.size; + if(tux.size == BIG) + { + tux.base.height = 64; + } + else + tux.base.height = 32; + } break; case SDLK_END: if(debug_mode == YES) @@ -551,7 +551,9 @@ int gameloop(char * subset, int levelnb, int mode) { int fps_cnt, jump, done; timer_type fps_timer, frame_timer; - + timer_init(&fps_timer, YES); + timer_init(&frame_timer, YES); + game_started = YES; st_gl_mode = mode; @@ -571,7 +573,7 @@ int gameloop(char * subset, int levelnb, int mode) level_load_song(¤t_level); } - + player_init(&tux); if(st_gl_mode != ST_GL_TEST) @@ -583,6 +585,7 @@ int gameloop(char * subset, int levelnb, int mode) levelintro(); + timer_init(&time_left,YES); start_timers(); if(st_gl_mode == ST_GL_LOAD_GAME) @@ -596,8 +599,8 @@ int gameloop(char * subset, int levelnb, int mode) quit = 0; frame = 0; game_pause = 0; - timer_init(&fps_timer); - timer_init(&frame_timer); + timer_init(&fps_timer,YES); + timer_init(&frame_timer,YES); fps_cnt = 0; /* Clear screen: */ @@ -637,16 +640,17 @@ int gameloop(char * subset, int levelnb, int mode) { switch (menu_check(&game_menu)) { - case 0: + case 2: st_pause_ticks_stop(); break; - case 1: + case 3: update_load_save_game_menu(&save_game_menu, NO); break; - case 2: + case 4: update_load_save_game_menu(&load_game_menu, YES); break; - case 4: + case 7: + st_pause_ticks_stop(); done = 1; break; } @@ -1483,7 +1487,7 @@ void trybreakbrick(float x, float y) /* Replace it with broken bits: */ - add_broken_brick(((x + 1) / 32) * 32, + add_broken_brick(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32); @@ -1515,8 +1519,6 @@ void tryemptybox(float x, float y) if (shape(x, y) == 'A') { - DEBUG_MSG("Here I am"); - /* Box with a distro! */ add_bouncy_distro(((int)(x + 1) / 32) * 32, @@ -1534,7 +1536,7 @@ void tryemptybox(float x, float y) { /* Tux is small, add mints! */ - add_upgrade(((x + 1) / 32) * 32, + add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, UPGRADE_MINTS); } @@ -1542,7 +1544,7 @@ void tryemptybox(float x, float y) { /* Tux is big, add coffee: */ - add_upgrade(((x + 1) / 32) * 32, + add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, UPGRADE_COFFEE); } @@ -1553,7 +1555,7 @@ void tryemptybox(float x, float y) { /* Add a golden herring */ - add_upgrade(((x + 1) / 32) * 32, + add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, UPGRADE_HERRING); } diff --git a/src/intro.c b/src/intro.c index ad223786b..f973a14f9 100644 --- a/src/intro.c +++ b/src/intro.c @@ -52,10 +52,9 @@ int intro(void) int done, i, quit, j, scene; int * height, * height_speed; timer_type timer; - - + /* Load sprite images: */ - texture_load(&bkgd, DATA_PREFIX "/images/intro/intro.png", IGNORE_ALPHA); + texture_load(&bkgd, DATA_PREFIX "/images/intro/intro.png", IGNORE_ALPHA); texture_load(&gown_sit, DATA_PREFIX "/images/intro/gown-sit.png", USE_ALPHA); texture_load(&gown_lookup, DATA_PREFIX "/images/intro/gown-lookup.png", USE_ALPHA); texture_load(&gown_upset, DATA_PREFIX "/images/intro/gown-upset.png", USE_ALPHA); @@ -93,6 +92,7 @@ int intro(void) scene = 0; i = 0; + timer_init(&timer,NO); timer_start(&timer,10000); while (timer_check(&timer) && !done && !quit) diff --git a/src/leveleditor.c b/src/leveleditor.c index 7a50922da..1e3756fa7 100644 --- a/src/leveleditor.c +++ b/src/leveleditor.c @@ -63,6 +63,7 @@ void unloadshared(void); int le_init(); void le_quit(); void le_drawlevel(); +void le_drawinterface(); void le_checkevents(); void le_change(float x, float y, unsigned char c); void le_testlevel(); @@ -73,10 +74,12 @@ void le_activate_bad_guys(void); void le_highlight_selection(); /* leveleditor internals */ +static char **level_subsets; +static int subsets_num; static int le_level_changed; /* if changes, ask for saving, when quiting*/ static int pos_x, cursor_x, cursor_y, cursor_tile, fire; static int le_level; -static st_level le_current_level; +static st_level* le_current_level; static st_subset le_level_subset; static int le_show_grid; static int le_frame; @@ -91,7 +94,13 @@ static button_type le_rubber_bt; static button_type le_select_mode_one_bt; static button_type le_select_mode_two_bt; static button_type le_bad_bsod_bt; +static button_type le_settings_bt; static button_panel_type le_bt_panel; +static menu_type leveleditor_menu; +static menu_type subset_load_menu; +static menu_type subset_new_menu; +static menu_type subset_settings_menu; +static menu_type level_settings_menu; static square selection; static int le_selection_mode; @@ -107,17 +116,20 @@ void le_activate_bad_guys(void) the badguys from tiles */ for (y = 0; y < 15; ++y) - for (x = 0; x < le_current_level.width; ++x) - if (le_current_level.tiles[y][x] >= '0' && le_current_level.tiles[y][x] <= '9') - add_bad_guy(x * 32, y * 32, le_current_level.tiles[y][x] - '0'); + for (x = 0; x < le_current_level->width; ++x) + if (le_current_level->tiles[y][x] >= '0' && le_current_level->tiles[y][x] <= '9') + add_bad_guy(x * 32, y * 32, le_current_level->tiles[y][x] - '0'); } void le_set_defaults() { - /* Set defaults: */ + if(le_current_level != NULL) + { + /* Set defaults: */ - if(le_current_level.time_left == 0) - le_current_level.time_left = 255; + if(le_current_level->time_left == 0) + le_current_level->time_left = 255; + } } /* FIXME: Needs to be implemented. It should ask the user for the level(file)name and then let him create a new level based on this. */ @@ -130,12 +142,20 @@ void selectlevel() int leveleditor(int levelnb) { - int last_time, now_time; + int last_time, now_time, i; le_level = levelnb; if(le_init() != 0) return 1; + /* Clear screen: */ + + clearscreen(0, 0, 0); + updatescreen(); + + while (SDL_PollEvent(&event)) + {} + while(YES) { last_time = SDL_GetTicks(); @@ -143,14 +163,22 @@ int leveleditor(int levelnb) le_checkevents(); - /* making events results to be in order */ - if(pos_x < 0) - pos_x = 0; - if(pos_x > (le_current_level.width * 32) - screen->w) - pos_x = (le_current_level.width * 32) - screen->w; + if(le_current_level != NULL) + { + /* making events results to be in order */ + if(pos_x < 0) + pos_x = 0; + if(pos_x > (le_current_level->width * 32) - screen->w) + pos_x = (le_current_level->width * 32) - screen->w; + + /* draw the level */ + le_drawlevel(); + } + else + clearscreen(0, 0, 0); - /* draw the level */ - le_drawlevel(); + /* draw editor interface */ + le_drawinterface(); if(show_menu) { @@ -159,14 +187,61 @@ int leveleditor(int levelnb) { switch (menu_check(&leveleditor_menu)) { - case 0: + case 2: show_menu = NO; break; - case 4: + case 7: done = DONE_LEVELEDITOR; break; } } + else if(current_menu == &level_settings_menu) + { + switch (menu_check(&level_settings_menu)) + { + case 0: + break; + case 1: + show_menu = YES; + break; + case 4: + break; + case 11: + strcpy(le_current_level->name,level_settings_menu.item[1].input); + break; + } + } + else if(current_menu == &subset_load_menu) + { + switch (i = menu_check(&subset_load_menu)) + { + case 0: + break; + default: + if(i != -1) + { + printf("%d",i); + printf("Load %s\n",level_subsets[i-2]); + subset_load(&le_level_subset,level_subsets[i-2]); + leveleditor_menu.item[3].kind = MN_GOTO; + le_level = 1; + arrays_init(); + loadshared(); + printf("%s\n",le_level_subset.name); + le_current_level = (st_level*) malloc(sizeof(st_level)); + if(level_load(le_current_level, le_level_subset.name, le_level) != 0) + { + le_quit(); + return 1; + } + le_set_defaults(); + level_load_gfx(le_current_level); + le_activate_bad_guys(); + show_menu = YES; + } + break; + } + } } if(done) @@ -194,70 +269,153 @@ int leveleditor(int levelnb) int le_init() { - subset_load(&le_level_subset,"default"); - le_show_grid = YES; + int i; + char str[80]; + level_subsets = NULL; + level_subsets = dsubdirs("/levels", "info", &subsets_num); + le_show_grid = YES; + /* level_changed = NO;*/ fire = DOWN; done = 0; - menu_reset(); - menu_set_current(&leveleditor_menu); le_frame = 0; /* support for frames in some tiles, like waves and bad guys */ - - arrays_init(); - loadshared(); - le_set_defaults(); - le_level_changed = NO; - if(level_load(&le_current_level, le_level_subset.name, le_level) != 0) - { - le_quit(); - return 1; - } - if(le_current_level.time_left == 0) - le_current_level.time_left = 255; - - level_load_gfx(&le_current_level); + + /* + subset_load(&le_level_subset,"default"); + arrays_init(); + loadshared(); + le_set_defaults(); + + + if(level_load(&le_current_level, le_level_subset.name, le_level) != 0) + { + le_quit(); + return 1; + } + if(le_current_level.time_left == 0) + le_current_level.time_left = 255; + + level_load_gfx(&le_current_level); + le_activate_bad_guys(); + */ + le_current_level = NULL; le_current_tile = '.'; le_mouse_pressed = NO; - le_activate_bad_guys(); texture_load(&le_selection,DATA_PREFIX "/images/leveleditor/select.png", USE_ALPHA); /* Load buttons */ - button_load(&le_test_level_bt,"/images/icons/test-level.png","Test Level",SDLK_F4,150,screen->h - 64); button_load(&le_next_level_bt,"/images/icons/up.png","Test Level", SDLK_PAGEUP,screen->w-64,0); button_load(&le_previous_level_bt,"/images/icons/down.png","Test Level",SDLK_PAGEDOWN,screen->w-32,0); button_load(&le_rubber_bt,"/images/icons/rubber.png","Rubber",SDLK_DELETE,screen->w-64,32); button_load(&le_select_mode_one_bt,"/images/icons/select-mode1.png","Select Tile",SDLK_F3,screen->w-64,16); button_load(&le_select_mode_two_bt,"/images/icons/select-mode2.png","Select Tiles",SDLK_F3,screen->w-32,16); - button_load(&le_bad_bsod_bt,"/images/shared/bsod-left-1.png","Select Tiles",'0',screen->w-32,32); - button_panel_init(&le_bt_panel, 500,100, 64, 400); - button_panel_additem(&le_bt_panel, button_create("/images/shared/bsod-left-1.png","Select Tiles",'0',screen->w-32,32)); + button_load(&le_test_level_bt,"/images/icons/test-level.png","Test Level",SDLK_F4,screen->w-64,screen->h - 64); + button_load(&le_settings_bt,"/images/icons/settings.png","Level settings",SDLK_0,screen->w-32,screen->h - 64); + button_panel_init(&le_bt_panel, screen->w - 64,64, 64, 380); + + menu_init(&leveleditor_menu); + menu_additem(&leveleditor_menu,menu_item_create(MN_LABEL,"Level Editor Menu",0,0)); + menu_additem(&leveleditor_menu,menu_item_create(MN_HL,"",0,0)); + menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Return To Level Editor",0,0)); + menu_additem(&leveleditor_menu,menu_item_create(MN_DEACTIVE,"Level Subset Settings",0,&subset_settings_menu)); + menu_additem(&leveleditor_menu,menu_item_create(MN_GOTO,"Load Level Subset",0,&subset_load_menu)); + menu_additem(&leveleditor_menu,menu_item_create(MN_GOTO,"New Level Subset",0,&subset_new_menu)); + menu_additem(&leveleditor_menu,menu_item_create(MN_HL,"",0,0)); + menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Quit Level Editor",0,0)); + + menu_reset(); + menu_set_current(&leveleditor_menu); + show_menu = YES; + + menu_init(&subset_load_menu); + menu_additem(&subset_load_menu,menu_item_create(MN_LABEL,"Load Level Subset",0,0)); + menu_additem(&subset_load_menu,menu_item_create(MN_HL,"",0,0)); + for(i = 0; i < subsets_num; ++i) + { + menu_additem(&subset_load_menu,menu_item_create(MN_ACTION,level_subsets[i],0,0)); + } + menu_additem(&subset_load_menu,menu_item_create(MN_HL,"",0,0)); + menu_additem(&subset_load_menu,menu_item_create(MN_BACK,"Back",0,0)); + + menu_init(&subset_new_menu); + menu_additem(&subset_new_menu,menu_item_create(MN_LABEL,"New Level Subset",0,0)); + menu_additem(&subset_new_menu,menu_item_create(MN_HL,"",0,0)); + menu_additem(&subset_new_menu,menu_item_create(MN_TEXTFIELD,"Enter Name",0,0)); + menu_additem(&subset_new_menu,menu_item_create(MN_ACTION,"Create",0,0)); + menu_additem(&subset_new_menu,menu_item_create(MN_HL,"",0,0)); + menu_additem(&subset_new_menu,menu_item_create(MN_BACK,"Back",0,0)); + + menu_init(&subset_settings_menu); + menu_additem(&subset_settings_menu,menu_item_create(MN_LABEL,"Level Subset Settings",0,0)); + menu_additem(&subset_settings_menu,menu_item_create(MN_HL,"",0,0)); + menu_additem(&subset_settings_menu,menu_item_create(MN_BACK,"Back",0,0)); + + menu_init(&level_settings_menu); + level_settings_menu.arrange_left = YES; + menu_additem(&level_settings_menu,menu_item_create(MN_LABEL,"Level Settings",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_HL,"",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_TEXTFIELD,"Name:",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_TEXTFIELD,"Theme:",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_TEXTFIELD,"Song:",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_TEXTFIELD,"Background:",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_NUMFIELD,"Length: ",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_NUMFIELD,"Time: ",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_NUMFIELD,"Gravity:",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_NUMFIELD,"Red: ",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_NUMFIELD,"Green: ",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_NUMFIELD,"Blue: ",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_HL,"",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_ACTION,"Apply Changes",0,0)); + /*menu_additem(&level_settings_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu)); + menu_additem(&level_settings_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu)); + menu_additem(&level_settings_menu,menu_item_create(MN_ACTION,"Level editor",0,0)); + menu_additem(&level_settings_menu,menu_item_create(MN_ACTION,"Quit",0,0));*/ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); return 0; } +void update_level_settings() +{ + char str[80]; + + menu_item_change_input(&level_settings_menu.item[1], le_current_level->name); + sprintf(str,"%d",le_current_level->width); + menu_item_change_input(&level_settings_menu.item[5], str); + sprintf(str,"%d",le_current_level->time_left); + menu_item_change_input(&level_settings_menu.item[6], str); + sprintf(str,"%2.0f",le_current_level->gravity); + menu_item_change_input(&level_settings_menu.item[7], str); + sprintf(str,"%d",le_current_level->bkgd_red); + menu_item_change_input(&level_settings_menu.item[8], str); + sprintf(str,"%d",le_current_level->bkgd_green); + menu_item_change_input(&level_settings_menu.item[9], str); + sprintf(str,"%d",le_current_level->bkgd_blue); + menu_item_change_input(&level_settings_menu.item[10], str); +} + void le_goto_level(int levelnb) { - level_free(&le_current_level); - if(level_load(&le_current_level, le_level_subset.name, levelnb) != 0) + level_free(le_current_level); + if(level_load(le_current_level, le_level_subset.name, levelnb) != 0) { - level_load(&le_current_level, le_level_subset.name, le_level); + level_load(le_current_level, le_level_subset.name, le_level); } else { le_level = levelnb; } - if(le_current_level.time_left == 0) - le_current_level.time_left = 255; + + le_set_defaults(); level_free_gfx(); - level_load_gfx(&le_current_level); + level_load_gfx(le_current_level); le_activate_bad_guys(); } @@ -271,11 +429,81 @@ void le_quit(void) SDL_EnableKeyRepeat(0, 0); // disables key repeating button_free(&le_test_level_bt); - level_free_gfx(); - level_free(&le_current_level); - unloadshared(); - arrays_free(); texture_free(&le_selection); + menu_free(&leveleditor_menu); + + if(le_current_level != NULL) + { + level_free_gfx(); + level_free(le_current_level); + unloadshared(); + arrays_free(); + } +} + +void le_drawinterface() +{ + int x,y; + char str[80]; + + if(le_current_level != NULL) + { + /* draw a grid (if selected) */ + if(le_show_grid) + { + for(x = 0; x < 19; x++) + fillrect(x*32 - ((int)pos_x % 32), 0, 1, screen->h, 225, 225, 225,255); + for(y = 0; y < 15; y++) + fillrect(0, y*32, screen->w - 32, 1, 225, 225, 225,255); + } + } + + if(le_selection_mode == CURSOR) + texture_draw(&le_selection, cursor_x - pos_x, cursor_y, NO_UPDATE); + else if(le_selection_mode == SQUARE) + { + int w, h; + le_highlight_selection(); + /* draw current selection */ + w = selection.x2 - selection.x1; + h = selection.y2 - selection.y1; + fillrect(selection.x1 - pos_x, selection.y1, w, SELECT_W, SELECT_CLR); + fillrect(selection.x1 - pos_x + w, selection.y1, SELECT_W, h, SELECT_CLR); + fillrect(selection.x1 - pos_x, selection.y1 + h, w, SELECT_W, SELECT_CLR); + fillrect(selection.x1 - pos_x, selection.y1, SELECT_W, h, SELECT_CLR); + } + + + /* draw button bar */ + fillrect(screen->w - 64, 0, 64, screen->h, 50, 50, 50,255); + drawshape(19 * 32, 14 * 32, le_current_tile); + + if(le_current_level != NULL) + { + button_draw(&le_test_level_bt); + button_draw(&le_next_level_bt); + button_draw(&le_previous_level_bt); + button_draw(&le_rubber_bt); + button_draw(&le_select_mode_one_bt); + button_draw(&le_select_mode_two_bt); + button_draw(&le_bad_bsod_bt); + button_draw(&le_settings_bt); + button_panel_draw(&le_bt_panel); + + sprintf(str, "%d/%d", le_level,le_level_subset.levels); + text_draw(&white_text, "LEV", 0, 0, 1, NO_UPDATE); + text_draw(&gold_text, str, 80, 0, 1, NO_UPDATE); + + text_draw(&white_small_text, "F1 for Help", 10, 430, 1, NO_UPDATE); + } + else + { + if(show_menu == NO) + text_draw(&white_small_text, "No Level Subset loaded - Press ESC and choose one in the menu", 10, 430, 1, NO_UPDATE); + else + text_draw(&white_small_text, "No Level Subset loaded", 10, 430, 1, NO_UPDATE); + } + } void le_drawlevel() @@ -284,7 +512,7 @@ void le_drawlevel() static char str[LEVEL_NAME_MAX]; /* Draw the real background */ - if(le_current_level.bkgd_image[0] != '\0') + if(le_current_level->bkgd_image[0] != '\0') { s = pos_x / 30; texture_draw_part(&img_bkgd,s,0,0,0,img_bkgd.w - s - 32, img_bkgd.h, NO_UPDATE); @@ -292,7 +520,7 @@ void le_drawlevel() } else { - clearscreen(le_current_level.bkgd_red, le_current_level.bkgd_green, le_current_level.bkgd_blue); + clearscreen(le_current_level->bkgd_red, le_current_level->bkgd_green, le_current_level->bkgd_blue); } /* clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue); */ @@ -300,11 +528,11 @@ void le_drawlevel() for (y = 0; y < 15; ++y) for (x = 0; x < 20; ++x) { - drawshape(x * 32 - ((int)pos_x % 32), y * 32, le_current_level.tiles[y][x + (int)(pos_x / 32)]); + drawshape(x * 32 - ((int)pos_x % 32), y * 32, le_current_level->tiles[y][x + (int)(pos_x / 32)]); /* draw whats inside stuff when cursor is selecting those */ /* (draw them all the time - is this the right behaviour?) */ - switch(le_current_level.tiles[y][x + (int)(pos_x/32)]) + switch(le_current_level->tiles[y][x + (int)(pos_x/32)]) { case 'B': texture_draw(&img_mints, x * 32 - ((int)pos_x % 32), y*32, NO_UPDATE); @@ -336,61 +564,10 @@ void le_drawlevel() texture_draw(&img_money_left[(le_frame / 5) % 2], bad_guys[i].base.x - pos_x, bad_guys[i].base.y, NO_UPDATE); } + /* Draw the player: */ /* for now, the position is fixed at (0, 240) */ texture_draw(&tux_right[(frame / 5) % 3], 0 - pos_x, 240, NO_UPDATE); - - /* draw a grid (if selected) */ - if(le_show_grid) - { - for(x = 0; x < 19; x++) - fillrect(x*32 - ((int)pos_x % 32), 0, 1, screen->h, 225, 225, 225,255); - for(y = 0; y < 15; y++) - fillrect(0, y*32, screen->w - 32, 1, 225, 225, 225,255); - } - - if(le_selection_mode == CURSOR) - texture_draw(&le_selection, cursor_x - pos_x, cursor_y, NO_UPDATE); - else if(le_selection_mode == SQUARE) - { - int w, h; - le_highlight_selection(); - /* draw current selection */ - w = selection.x2 - selection.x1; - h = selection.y2 - selection.y1; - fillrect(selection.x1 - pos_x, selection.y1, w, SELECT_W, SELECT_CLR); - fillrect(selection.x1 - pos_x + w, selection.y1, SELECT_W, h, SELECT_CLR); - fillrect(selection.x1 - pos_x, selection.y1 + h, w, SELECT_W, SELECT_CLR); - fillrect(selection.x1 - pos_x, selection.y1, SELECT_W, h, SELECT_CLR); - } - - - /* draw button bar */ - fillrect(screen->w - 64, 0, 64, screen->h, 50, 50, 50,255); - drawshape(19 * 32, 14 * 32, le_current_tile); - - button_draw(&le_test_level_bt); - button_draw(&le_next_level_bt); - button_draw(&le_previous_level_bt); - button_draw(&le_rubber_bt); - button_draw(&le_select_mode_one_bt); - button_draw(&le_select_mode_two_bt); - button_draw(&le_bad_bsod_bt); - button_panel_draw(&le_bt_panel); - - sprintf(str, "%d", le_current_level.time_left); - text_draw(&white_text, "TIME", 324, 0, 1, NO_UPDATE); - text_draw(&gold_text, str, 404, 0, 1, NO_UPDATE); - - text_draw(&white_text, "NAME", 0, 0, 1, NO_UPDATE); - text_draw(&gold_text, le_current_level.name, 80, 0, 1, NO_UPDATE); - - sprintf(str, "%d/%d", le_level,le_level_subset.levels); - text_draw(&white_text, "NUMB", 0, 20, 1, NO_UPDATE); - text_draw(&gold_text, str, 80, 20, 1, NO_UPDATE); - - text_draw(&white_small_text, "F1 for Help", 10, 430, 1, NO_UPDATE); - text_draw(&white_small_text, "F2 for Testing", 150, 430, 1, NO_UPDATE); } void le_checkevents() @@ -474,7 +651,7 @@ void le_checkevents() pos_x = cursor_x; break; case SDLK_END: - cursor_x = (le_current_level.width * 32) - 32; + cursor_x = (le_current_level->width * 32) - 32; pos_x = cursor_x; break; case SDLK_PAGEUP: @@ -621,7 +798,7 @@ void le_checkevents() break; } break; - case SDL_KEYUP: // key released + case SDL_KEYUP: /* key released */ switch(event.key.keysym.sym) { case SDLK_LCTRL: @@ -675,38 +852,54 @@ void le_checkevents() } - - if(event.type == SDL_KEYDOWN || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > screen->w-64 && event.motion.x < screen->w && - event.motion.y > 0 && event.motion.y < screen->h))) + if(le_current_level != NULL) { - /* Check for button events */ - button_event(&le_test_level_bt,&event); - if(button_get_state(&le_test_level_bt) == BN_CLICKED) - le_testlevel(); - button_event(&le_next_level_bt,&event); - if(button_get_state(&le_next_level_bt) == BN_CLICKED) - { - if(le_level < le_level_subset.levels) - le_goto_level(++le_level); - } - button_event(&le_previous_level_bt,&event); - if(button_get_state(&le_previous_level_bt) == BN_CLICKED) + if(event.type == SDL_KEYDOWN || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > screen->w-64 && event.motion.x < screen->w && + event.motion.y > 0 && event.motion.y < screen->h))) { - if(le_level > 1) - le_goto_level(--le_level); + /* Check for button events */ + button_event(&le_test_level_bt,&event); + if(button_get_state(&le_test_level_bt) == BN_CLICKED) + le_testlevel(); + button_event(&le_next_level_bt,&event); + if(button_get_state(&le_next_level_bt) == BN_CLICKED) + { + if(le_level < le_level_subset.levels) + le_goto_level(++le_level); + } + button_event(&le_previous_level_bt,&event); + if(button_get_state(&le_previous_level_bt) == BN_CLICKED) + { + if(le_level > 1) + le_goto_level(--le_level); + } + button_event(&le_rubber_bt,&event); + if(button_get_state(&le_rubber_bt) == BN_CLICKED) + le_current_tile = '.'; + button_event(&le_select_mode_one_bt,&event); + if(button_get_state(&le_select_mode_one_bt) == BN_CLICKED) + le_selection_mode = CURSOR; + button_event(&le_select_mode_two_bt,&event); + if(button_get_state(&le_select_mode_two_bt) == BN_CLICKED) + le_selection_mode = SQUARE; + button_event(&le_bad_bsod_bt,&event); + if(button_get_state(&le_bad_bsod_bt) == BN_CLICKED) + le_current_tile = '0'; + button_event(&le_settings_bt,&event); + if(button_get_state(&le_settings_bt) == BN_CLICKED) + { + if(show_menu == NO) + { + menu_set_current(&level_settings_menu); + show_menu = YES; + } + else + { + menu_set_current(&leveleditor_menu); + show_menu = NO; + } + } } - button_event(&le_rubber_bt,&event); - if(button_get_state(&le_rubber_bt) == BN_CLICKED) - le_current_tile = '.'; - button_event(&le_select_mode_one_bt,&event); - if(button_get_state(&le_select_mode_one_bt) == BN_CLICKED) - le_selection_mode = CURSOR; - button_event(&le_select_mode_two_bt,&event); - if(button_get_state(&le_select_mode_two_bt) == BN_CLICKED) - le_selection_mode = SQUARE; - button_event(&le_bad_bsod_bt,&event); - if(button_get_state(&le_bad_bsod_bt) == BN_CLICKED) - le_current_tile = '0'; } if(le_mouse_pressed) @@ -752,92 +945,95 @@ void le_highlight_selection() void le_change(float x, float y, unsigned char c) { - int xx,yy,i; - int x1, x2, y1, y2; + if(le_current_level != NULL) + { + int xx,yy,i; + int x1, x2, y1, y2; - /* level_changed = YES; */ + /* level_changed = YES; */ - switch(le_selection_mode) - { - case CURSOR: - level_change(&le_current_level,x,y,c); - - yy = ((int)y / 32); - xx = ((int)x / 32); - - /* if there is a bad guy over there, remove it */ - for(i = 0; i < num_bad_guys; ++i) - if (bad_guys[i].base.alive) - if(xx == bad_guys[i].base.x/32 && yy == bad_guys[i].base.y/32) - bad_guys[i].base.alive = NO; - - if(c == '0') /* if it's a bad guy */ - add_bad_guy(xx*32, yy*32, BAD_BSOD); - else if(c == '1') - add_bad_guy(xx*32, yy*32, BAD_LAPTOP); - else if(c == '2') - add_bad_guy(xx*32, yy*32, BAD_MONEY); - - break; - case SQUARE: - if(selection.x1 < selection.x2) - { - x1 = selection.x1; - x2 = selection.x2; - } - else - { - x1 = selection.x2; - x2 = selection.x1; - } - if(selection.y1 < selection.y2) + switch(le_selection_mode) { - y1 = selection.y1; - y2 = selection.y2; - } - else - { - y1 = selection.y2; - y2 = selection.y1; - } + case CURSOR: + level_change(le_current_level,x,y,c); - x1 /= 32; - x2 /= 32; - y1 /= 32; - y2 /= 32; + yy = ((int)y / 32); + xx = ((int)x / 32); - /* if there is a bad guy over there, remove it */ - for(i = 0; i < num_bad_guys; ++i) - if(bad_guys[i].base.alive) - if(bad_guys[i].base.x/32 >= x1 && bad_guys[i].base.x/32 <= x2 - && bad_guys[i].base.y/32 >= y1 && bad_guys[i].base.y/32 <= y2) - bad_guys[i].base.alive = NO; + /* if there is a bad guy over there, remove it */ + for(i = 0; i < num_bad_guys; ++i) + if (bad_guys[i].base.alive) + if(xx == bad_guys[i].base.x/32 && yy == bad_guys[i].base.y/32) + bad_guys[i].base.alive = NO; - for(xx = x1; xx <= x2; xx++) - for(yy = y1; yy <= y2; yy++) - { - level_change(&le_current_level, xx*32, yy*32, c); - - if(c == '0') // if it's a bad guy - add_bad_guy(xx*32, yy*32, BAD_BSOD); - else if(c == '1') - add_bad_guy(xx*32, yy*32, BAD_LAPTOP); - else if(c == '2') - add_bad_guy(xx*32, yy*32, BAD_MONEY); - } - break; - default: - break; + if(c == '0') /* if it's a bad guy */ + add_bad_guy(xx*32, yy*32, BAD_BSOD); + else if(c == '1') + add_bad_guy(xx*32, yy*32, BAD_LAPTOP); + else if(c == '2') + add_bad_guy(xx*32, yy*32, BAD_MONEY); + + break; + case SQUARE: + if(selection.x1 < selection.x2) + { + x1 = selection.x1; + x2 = selection.x2; + } + else + { + x1 = selection.x2; + x2 = selection.x1; + } + if(selection.y1 < selection.y2) + { + y1 = selection.y1; + y2 = selection.y2; + } + else + { + y1 = selection.y2; + y2 = selection.y1; + } + + x1 /= 32; + x2 /= 32; + y1 /= 32; + y2 /= 32; + + /* if there is a bad guy over there, remove it */ + for(i = 0; i < num_bad_guys; ++i) + if(bad_guys[i].base.alive) + if(bad_guys[i].base.x/32 >= x1 && bad_guys[i].base.x/32 <= x2 + && bad_guys[i].base.y/32 >= y1 && bad_guys[i].base.y/32 <= y2) + bad_guys[i].base.alive = NO; + + for(xx = x1; xx <= x2; xx++) + for(yy = y1; yy <= y2; yy++) + { + level_change(le_current_level, xx*32, yy*32, c); + + if(c == '0') // if it's a bad guy + add_bad_guy(xx*32, yy*32, BAD_BSOD); + else if(c == '1') + add_bad_guy(xx*32, yy*32, BAD_LAPTOP); + else if(c == '2') + add_bad_guy(xx*32, yy*32, BAD_MONEY); + } + break; + default: + break; + } } } void le_testlevel() { - level_save(&le_current_level,"test",le_level); + level_save(le_current_level,"test",le_level); gameloop("test",le_level, ST_GL_TEST); menu_set_current(&leveleditor_menu); arrays_init(); - level_load_gfx(&le_current_level); + level_load_gfx(le_current_level); loadshared(); le_activate_bad_guys(); } diff --git a/src/menu.c b/src/menu.c index 146909cdf..33dccbebe 100644 --- a/src/menu.c +++ b/src/menu.c @@ -37,7 +37,7 @@ int show_menu; int menu_change; texture_type checkbox, checkbox_checked, back; -menu_type main_menu, game_menu, options_menu, leveleditor_menu, highscore_menu, load_game_menu, save_game_menu; +menu_type main_menu, game_menu, options_menu, highscore_menu, load_game_menu, save_game_menu; menu_type* current_menu, * last_menu; /* input implementation variables */ @@ -52,6 +52,7 @@ void menu_set_current(menu_type* pmenu) menu_change = YES; last_menu = current_menu; current_menu = pmenu; + timer_start(&pmenu->effect, 500); } } @@ -67,7 +68,8 @@ menu_item_type* menu_item_create(int kind, char *text, int init_toggle, void* ta else pnew_item->toggled = NO; pnew_item->target_menu = target_menu; - pnew_item->input = NULL; + pnew_item->input = (char*) malloc(sizeof(char)); + pnew_item->input[0] = '\0'; return pnew_item; } @@ -80,6 +82,15 @@ void menu_item_change_text(menu_item_type* pmenu_item, char *text) strcpy(pmenu_item->text,text); } } +void menu_item_change_input(menu_item_type* pmenu_item, char *text) +{ + if(text) + { + free(pmenu_item->input); + pmenu_item->input = (char*) malloc(sizeof(char )*(strlen(text)+1)); + strcpy(pmenu_item->input,text); + } +} /* Free a menu and all its items */ void menu_free(menu_type* pmenu) @@ -99,9 +110,11 @@ void menu_free(menu_type* pmenu) /* Initialize a menu */ void menu_init(menu_type* pmenu) { + pmenu->arrange_left = 0; pmenu->num_items = 0; pmenu->active_item = 0; pmenu->item = NULL; + timer_init(&pmenu->effect,NO); } /* Add an item to a menu */ @@ -142,7 +155,7 @@ void menu_action(menu_type* pmenu) pmenu->item[pmenu->active_item].toggled = !pmenu->item[pmenu->active_item].toggled; menu_change = YES; } - else if(pmenu->item[pmenu->active_item].kind == MN_ACTION || pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD) + else if(pmenu->item[pmenu->active_item].kind == MN_ACTION || pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD || pmenu->item[pmenu->active_item].kind == MN_NUMFIELD) { pmenu->item[pmenu->active_item].toggled = YES; } @@ -153,7 +166,7 @@ void menu_action(menu_type* pmenu) } break; case MN_REMOVE: - if(pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD) + if(pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD || pmenu->item[pmenu->active_item].kind == MN_NUMFIELD) { if(pmenu->item[pmenu->active_item].input != NULL) { @@ -168,7 +181,7 @@ void menu_action(menu_type* pmenu) } break; case MN_INPUT: - if(pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD) + if(pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD || (pmenu->item[pmenu->active_item].kind == MN_NUMFIELD && mn_input_char >= '0' && mn_input_char <= '9')) { if(pmenu->item[pmenu->active_item].input != NULL) { @@ -188,7 +201,7 @@ void menu_action(menu_type* pmenu) } } - if(pmenu->item[pmenu->active_item].kind == MN_DEACTIVE || pmenu->item[pmenu->active_item].kind == MN_LABEL) + if(pmenu->item[pmenu->active_item].kind == MN_DEACTIVE || pmenu->item[pmenu->active_item].kind == MN_LABEL || pmenu->item[pmenu->active_item].kind == MN_HL) { if(menuaction != MN_UP && menuaction != MN_DOWN) menuaction = MN_DOWN; @@ -204,7 +217,7 @@ int menu_check(menu_type* pmenu) { if(pmenu->num_items != 0 && pmenu->item != NULL) { - if((pmenu->item[pmenu->active_item].kind == MN_ACTION || pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD) && pmenu->item[pmenu->active_item].toggled == YES) + if((pmenu->item[pmenu->active_item].kind == MN_ACTION || pmenu->item[pmenu->active_item].kind == MN_TEXTFIELD || pmenu->item[pmenu->active_item].kind == MN_NUMFIELD) && pmenu->item[pmenu->active_item].toggled == YES) { pmenu->item[pmenu->active_item].toggled = NO; show_menu = 0; @@ -224,13 +237,13 @@ int menu_check(menu_type* pmenu) /* Draw the current menu. */ void menu_draw(menu_type* pmenu) { - int i, y, menu_height, menu_width; + int i, y, a, b, e, f, menu_height, menu_width; /* The width of the menu has to be more than the width of the text with the most characters */ menu_width = 0; for(i = 0; i < pmenu->num_items; ++i) { - y = strlen(pmenu->item[i].text) + (pmenu->item[i].input ? strlen(pmenu->item[i].input) : 0); + y = strlen(pmenu->item[i].text) + (pmenu->item[i].input ? strlen(pmenu->item[i].input) + 1 : 0); if( y > menu_width ) { menu_width = y; @@ -238,54 +251,88 @@ void menu_draw(menu_type* pmenu) menu_width += 2; } } + if(pmenu->arrange_left == YES) + a = menu_width * 16; + else + a = 0; + menu_width = menu_width * 16 + 48; menu_height = (pmenu->num_items) * 24; /* Draw a transparent background */ fillrect(screen->w/2 - menu_width/2,screen->h/2-(((pmenu->num_items)*24)/2),menu_width,menu_height,150,150,150,100); + if(timer_check(&pmenu->effect)) + { + e = timer_get_left(&pmenu->effect) / 4; + } + else + { + e = 0; + } + for(i = 0; i < pmenu->num_items; ++i) { + if(pmenu->arrange_left == YES) + b = (a - ((strlen(pmenu->item[i].text)+strlen(pmenu->item[i].input)) * 16)) / 2; + else + b = 0; + + if(e != 0) + { + if(i % 2) + f = e; + else + f = -e; + } + else + f = 0; + if(pmenu->item[i].kind == MN_DEACTIVE) { - text_drawf(&black_text,pmenu->item[i].text,0,(i)*24 - menu_height/2 + 10,A_HMIDDLE, A_VMIDDLE,2,NO_UPDATE); + text_drawf(&black_text,pmenu->item[i].text, - b,(i)*24 - menu_height/2 + 10 + f,A_HMIDDLE, A_VMIDDLE,2,NO_UPDATE); + } + else if(pmenu->item[i].kind == MN_HL) + { + /* Draw a horizontal line with a little 3d effect */ + fillrect(screen->w/2 - menu_width/2,(i)*24 - menu_height/2 + 6 + screen->h /2,menu_width,4,210,50,50,225); + fillrect(screen->w/2 - menu_width/2,(i)*24 - menu_height/2 + 10 + screen->h /2,menu_width,2,0,0,0,255); } else if(pmenu->item[i].kind == MN_LABEL) { - text_drawf(&gold_text,pmenu->item[i].text,0,(i)*24 - menu_height/2 + 10,A_HMIDDLE, A_VMIDDLE,2,NO_UPDATE); - fillrect(screen->w/2 - menu_width/2,(i)*24 - menu_height/2 + 20 + screen->h /2,menu_width,2,190,190,190,100); + text_drawf(&gold_text,pmenu->item[i].text, - b,(i)*24 - menu_height/2 + 10,A_HMIDDLE, A_VMIDDLE,2,NO_UPDATE); } - else if(pmenu->item[i].kind == MN_TEXTFIELD) + else if(pmenu->item[i].kind == MN_TEXTFIELD || pmenu->item[i].kind == MN_NUMFIELD) { - text_drawf(&gold_text,pmenu->item[i].input,(strlen(pmenu->item[i].text) * 16)/2,(i)*24 - menu_height/2 + 10,A_HMIDDLE, A_VMIDDLE,2,NO_UPDATE); + text_drawf(&gold_text,pmenu->item[i].input, - b + ((strlen(pmenu->item[i].text)+1) * 16)/2,(i)*24 - menu_height/2 + 10 + f,A_HMIDDLE, A_VMIDDLE,2,NO_UPDATE); if(i == pmenu->active_item) { - text_drawf(&blue_text,pmenu->item[i].text,-((strlen(pmenu->item[i].input) * 16)/2),(i)*24 - menu_height/2 + 10,A_HMIDDLE, A_VMIDDLE,3,NO_UPDATE); + text_drawf(&blue_text,pmenu->item[i].text, - b -(((strlen(pmenu->item[i].input)+1) * 16)/2),(i)*24 - menu_height/2 + 10 + f,A_HMIDDLE, A_VMIDDLE,3,NO_UPDATE); } else { - text_drawf(&white_text,pmenu->item[i].text,-((strlen(pmenu->item[i].input) * 16)/2),(i)*24 - menu_height/2 +10,A_HMIDDLE, A_VMIDDLE,2,NO_UPDATE); + text_drawf(&white_text,pmenu->item[i].text, - b -(((strlen(pmenu->item[i].input)+1) * 16)/2),(i)*24 - menu_height/2 +10 + f,A_HMIDDLE, A_VMIDDLE,2,NO_UPDATE); } } else if(i == pmenu->active_item) { - text_drawf(&blue_text,pmenu->item[i].text,0,(i)*24 - menu_height/2 + 10 ,A_HMIDDLE, A_VMIDDLE,3,NO_UPDATE); + text_drawf(&blue_text,pmenu->item[i].text, - b,(i)*24 - menu_height/2 + 10 + f ,A_HMIDDLE, A_VMIDDLE,3,NO_UPDATE); } else { - text_drawf(&white_text,pmenu->item[i].text,0,(i)*24 - menu_height/2 + 10,A_HMIDDLE, A_VMIDDLE,2,NO_UPDATE); + text_drawf(&white_text,pmenu->item[i].text, - b,(i)*24 - menu_height/2 + 10 + f ,A_HMIDDLE, A_VMIDDLE,2,NO_UPDATE); } if(pmenu->item[i].kind == MN_TOGGLE) { if(pmenu->item[i].toggled == YES) - texture_draw(&checkbox_checked,screen->w / 2 + (strlen(pmenu->item[i].text) * 16)/2 + 16,(i)*24 - menu_height/2 + 10 + screen->h / 2 -8,NO_UPDATE); + texture_draw(&checkbox_checked, - b + screen->w / 2 + (strlen(pmenu->item[i].text) * 16)/2 + 16,(i)*24 - menu_height/2 + 10 + screen->h / 2 -8 + f,NO_UPDATE); else - texture_draw(&checkbox,screen->w / 2 + (strlen(pmenu->item[i].text) * 16)/2 + 16,(i)*24 - menu_height/2 + 10 + screen->h / 2 - 8,NO_UPDATE); + texture_draw(&checkbox, - b + screen->w / 2 + (strlen(pmenu->item[i].text) * 16)/2 + 16,(i)*24 - menu_height/2 + 10 + screen->h / 2 - 8 + f,NO_UPDATE); } else if(pmenu->item[i].kind == MN_BACK) { - texture_draw(&back,screen->w / 2 + (strlen(pmenu->item[i].text) * 16)/2 + 16,(i)*24 - menu_height/2 + 10 + screen->h / 2 -8,NO_UPDATE); + texture_draw(&back, - b + screen->w / 2 + (strlen(pmenu->item[i].text) * 16)/2 + 16,(i)*24 - menu_height/2 + 10 + screen->h / 2 -8 + f,NO_UPDATE); } } } @@ -348,8 +395,7 @@ void menu_event(SDL_keysym* keysym) menuaction = MN_DOWN; menu_change = YES; break; - case SDLK_SPACE: /* Menu Hit */ - case SDLK_RETURN: + case SDLK_RETURN: /* Menu Hit */ menuaction = MN_HIT; menu_change = YES; break; @@ -360,13 +406,7 @@ void menu_event(SDL_keysym* keysym) delete_character++; break; default: - if( key >= SDLK_0 && key <= SDLK_9) - { - menuaction = MN_INPUT; - menu_change = YES; - mn_input_char = *ch; - } - else if( key >= SDLK_a && key <= SDLK_z ) + if( (key >= SDLK_0 && key <= SDLK_9) || (key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_SPACE && key <= SDLK_SLASH)) { menuaction = MN_INPUT; menu_change = YES; diff --git a/src/menu.h b/src/menu.h index 98467eb02..923efac85 100644 --- a/src/menu.h +++ b/src/menu.h @@ -15,6 +15,7 @@ #include #include "texture.h" +#include "timer.h" typedef struct menu_item_type { @@ -28,12 +29,15 @@ menu_item_type; menu_item_type* menu_item_create(int kind, char *text, int init_toggle, void* target_menu); void menu_item_change_text(menu_item_type* pmenu_item, char *text); +void menu_item_change_input(menu_item_type* pmenu_item, char *text); typedef struct menu_type { int num_items; int active_item; + int arrange_left; menu_item_type *item; + timer_type effect; } menu_type; @@ -53,7 +57,9 @@ enum { MN_BACK, MN_DEACTIVE, MN_TEXTFIELD, - MN_LABEL + MN_NUMFIELD, + MN_LABEL, + MN_HL /* horizontal line */ }; /* Action done on the menu */ @@ -71,7 +77,7 @@ extern int show_menu; extern int menu_change; extern texture_type checkbox, checkbox_checked, back; -extern menu_type main_menu, game_menu, options_menu, leveleditor_menu, highscore_menu, load_game_menu, save_game_menu; +extern menu_type main_menu, game_menu, options_menu, highscore_menu, load_game_menu, save_game_menu; extern menu_type* current_menu, * last_menu; /* input implementation variables */ diff --git a/src/player.c b/src/player.c index 0b8fb6147..919596c2e 100644 --- a/src/player.c +++ b/src/player.c @@ -68,9 +68,9 @@ void player_init(player_type* pplayer) pplayer->keymap.right = SDLK_RIGHT; pplayer->keymap.fire = SDLK_LCTRL; - timer_init(&pplayer->invincible_timer); - timer_init(&pplayer->skidding_timer); - timer_init(&pplayer->safe_timer); + timer_init(&pplayer->invincible_timer,YES); + timer_init(&pplayer->skidding_timer,YES); + timer_init(&pplayer->safe_timer,YES); physic_init(&pplayer->hphysic); physic_init(&pplayer->vphysic); } @@ -120,9 +120,9 @@ void player_level_begin(player_type* pplayer) pplayer->input.right = UP; pplayer->input.up = UP; - timer_init(&pplayer->invincible_timer); - timer_init(&pplayer->skidding_timer); - timer_init(&pplayer->safe_timer); + timer_init(&pplayer->invincible_timer,YES); + timer_init(&pplayer->skidding_timer,YES); + timer_init(&pplayer->safe_timer,YES); } void player_action(player_type* pplayer) @@ -149,22 +149,24 @@ void player_action(player_type* pplayer) } else {*/ - if(!issolid( pplayer->base.x + 16, pplayer->base.y + pplayer->base.height)) + if( /*!issolid( pplayer->base.x + 16, pplayer->base.y + pplayer->base.height )*/ !player_on_ground(pplayer)) { if(!physic_is_set(&pplayer->vphysic)) { physic_set_state(&pplayer->vphysic,PH_VT); physic_set_start_vy(&pplayer->vphysic,0.); + DEBUG_MSG("Ich bin jetzt ordentlich am Punkten"); } pplayer->base.ym = physic_get_velocity(&pplayer->vphysic); } else { - /* Land: */ + /* Land: */ if (pplayer->base.ym > 0) { - pplayer->base.y = (int)(pplayer->base.y / 32) * 32; + pplayer->base.y = (int)(((int)(pplayer->base.y +1) / 32) * 32); + printf("%f",pplayer->base.y); pplayer->base.ym = 0; } physic_init(&pplayer->vphysic); @@ -174,334 +176,192 @@ void player_action(player_type* pplayer) { --pplayer->base.y; } - while(issolid( pplayer->base.x + 16, pplayer->base.y) && !issolid( pplayer->base.x + 16, pplayer->base.y + pplayer->base.height)) + while(issolid( pplayer->base.x + 16, pplayer->base.y + 1) && !issolid( pplayer->base.x + 16, pplayer->base.y + pplayer->base.height)) { ++pplayer->base.y; } - while(issolid( pplayer->base.x - 1, pplayer->base.y) || issolid( pplayer->base.x - 1, pplayer->base.y+pplayer->base.height)) + while(issolid( pplayer->base.x - 1, pplayer->base.y + 1) || issolid( pplayer->base.x - 1, pplayer->base.y+pplayer->base.height)) { ++pplayer->base.x; } - while(issolid( pplayer->base.x + 32, pplayer->base.y) || issolid( pplayer->base.x + 32, pplayer->base.y+pplayer->base.height)) + while(issolid( pplayer->base.x + 32, pplayer->base.y + 1) || issolid( pplayer->base.x + 32, pplayer->base.y+pplayer->base.height)) { --pplayer->base.x; } - if (isbrick(pplayer->base.x, pplayer->base.y - 1) || - isfullbox(pplayer->base.x, pplayer->base.y - 1)) + if(pplayer->base.ym <= 0) { - trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE); - trybumpbadguy(pplayer->base.x, pplayer->base.y - 64); - bumpbrick(pplayer->base.x, pplayer->base.y - 1); - tryemptybox(pplayer->base.x, pplayer->base.y - 1); - } - if (isbrick(pplayer->base.x+ 31, pplayer->base.y - 1) || - isfullbox(pplayer->base.x+ 31, pplayer->base.y - 1)) - { - trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE); - trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64); - bumpbrick(pplayer->base.x+ 31, pplayer->base.y - 1); - tryemptybox(pplayer->base.x+ 31, pplayer->base.y - 1); - } + if (isbrick(pplayer->base.x, pplayer->base.y) || + isfullbox(pplayer->base.x, pplayer->base.y)) + { + DEBUG_MSG("My sear"); + trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE); + trybumpbadguy(pplayer->base.x, pplayer->base.y - 64); + if(pplayer->size == BIG) + trybreakbrick(pplayer->base.x, pplayer->base.y); - /* Get a distro from a brick? */ + bumpbrick(pplayer->base.x, pplayer->base.y); + tryemptybox(pplayer->base.x, pplayer->base.y); + } - if (shape(pplayer->base.x, pplayer->base.y - 1) == 'x' || - shape(pplayer->base.x, pplayer->base.y - 1) == 'y') - { - add_bouncy_distro((((int)pplayer->base.x) - / 32) * 32, - ((int)pplayer->base.y - 1 / 32) * 32); -DEBUG_MSG("should work"); - if (counting_distros == NO) + if (isbrick(pplayer->base.x+ 31, pplayer->base.y) || + isfullbox(pplayer->base.x+ 31, pplayer->base.y)) { - counting_distros = YES; - distro_counter = 100; - } + trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE); + trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64); - if (distro_counter <= 0) - level_change(¤t_level,pplayer->base.x,pplayer->base.y - 1, 'a'); + if(pplayer->size == BIG) + trybreakbrick(pplayer->base.x+ 31, pplayer->base.y); - play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); - score = score + SCORE_DISTRO; - distros++; - } - else if (shape(pplayer->base.x+ 31, pplayer->base.y - 1) == 'x' || - shape(pplayer->base.x+ 31, pplayer->base.y - 1) == 'y') - { - add_bouncy_distro((((int)pplayer->base.x + 31) - / 32) * 32, - ((int)pplayer->base.y - 1 / 32) * 32); -DEBUG_MSG("+31?"); - if (counting_distros == NO) - { - counting_distros = YES; - distro_counter = 100; + bumpbrick(pplayer->base.x+ 31, pplayer->base.y); + tryemptybox(pplayer->base.x+ 31, pplayer->base.y); } - if (distro_counter <= 0) - level_change(¤t_level,pplayer->base.x+ 31, pplayer->base.y - 1, 'a'); - play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); - score = score + SCORE_DISTRO; - distros++; - } + if(pplayer->size == SMALL) + { + /* Get a distro from a brick? */ + + if (shape(pplayer->base.x, pplayer->base.y) == 'x' || + shape(pplayer->base.x, pplayer->base.y) == 'y') + { + add_bouncy_distro((((int)pplayer->base.x) + / 32) * 32, + ((int)pplayer->base.y / 32) * 32); + DEBUG_MSG("should work"); + if (counting_distros == NO) + { + counting_distros = YES; + distro_counter = 100; + } - player_grabdistros(pplayer); + if (distro_counter <= 0) + level_change(¤t_level,pplayer->base.x,pplayer->base.y - 1, 'a'); - /* FIXME: this code is COMPLETLY broken!!! */ - /* if (issolid(pplayer->base.x, pplayer->base.y + 31) && - !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y + 31)) - { - while (issolid(pplayer->base.x, pplayer->base.y + 31)) - { - if (pplayer->base.xm < 0) - pplayer->base.x++; - else if (pplayer->base.xm > 0) - pplayer->base.x--; - } + play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); + score = score + SCORE_DISTRO; + distros++; + } + else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' || + shape(pplayer->base.x+ 31, pplayer->base.y) == 'y') + { + add_bouncy_distro((((int)pplayer->base.x + 31) + / 32) * 32, + ((int)pplayer->base.y / 32) * 32); + DEBUG_MSG("+31?"); + if (counting_distros == NO) + { + counting_distros = YES; + distro_counter = 100; + } - pplayer->base.xm = 0; - }*/ + if (distro_counter <= 0) + level_change(¤t_level,pplayer->base.x+ 31, pplayer->base.y, 'a'); - /*if (issolid(pplayer->base.x, pplayer->base.y) && - !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y)) - { - while (issolid(pplayer->base.x, (pplayer->base.y))) - { - if (pplayer->base.xm < 0) - pplayer->base.x++; - else if (pplayer->base.xm > 0) - pplayer->base.x--; + play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); + score = score + SCORE_DISTRO; + distros++; + } } + } - pplayer->base.xm = 0; - }*/ + player_grabdistros(pplayer); - /*if (issolid(pplayer->base.x, pplayer->base.y + 31)) - { - /* Set down properly: * / - - int debug_int = 0; - while (issolid(pplayer->base.x, pplayer->base.y + 31)) + /* FIXME: this code is COMPLETLY broken!!! */ + /* if (issolid(pplayer->base.x, pplayer->base.y + 31) && + !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y + 31)) + { + while (issolid(pplayer->base.x, pplayer->base.y + 31)) + { + if (pplayer->base.xm < 0) + pplayer->base.x++; + else if (pplayer->base.xm > 0) + pplayer->base.x--; + } + + pplayer->base.xm = 0; + }*/ + + /*if (issolid(pplayer->base.x, pplayer->base.y) && + !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y)) { - ++debug_int; - if(debug_int > 32) + while (issolid(pplayer->base.x, (pplayer->base.y))) { - DEBUG_MSG("FIXME - UNDER certain circumstances I'm hanging in a loop here!"); - /*the circumstances are: - issolid() is true and base.ym == 0 - use of floating point varibles for base stuff* / - break; + if (pplayer->base.xm < 0) + pplayer->base.x++; + else if (pplayer->base.xm > 0) + pplayer->base.x--; } - if (pplayer->base.ym < 0) - pplayer->base.y++; - else if (pplayer->base.ym > 0) - pplayer->base.y--; - } - - /* Reset score multiplier (for multi-hits): */ + pplayer->base.xm = 0; + }*/ - if (pplayer->base.ym > 0) - score_multiplier = 1; + /*if (issolid(pplayer->base.x, pplayer->base.y + 31)) + { + /* Set down properly: * / + int debug_int = 0; + while (issolid(pplayer->base.x, pplayer->base.y + 31)) + { + ++debug_int; + if(debug_int > 32) + { + DEBUG_MSG("FIXME - UNDER certain circumstances I'm hanging in a loop here!"); + /*the circumstances are: + issolid() is true and base.ym == 0 + use of floating point varibles for base stuff* / + break; + } + if (pplayer->base.ym < 0) + pplayer->base.y++; + else if (pplayer->base.ym > 0) + pplayer->base.y--; + } - /* Stop jumping! * / - pplayer->base.ym = 0; - pplayer->jumping = NO; - pplayer->input.up = UP; - } - /* FIXME: this code is COMPLETLY broken!!! */ - /*if (issolid(pplayer->base.x, pplayer->base.y) || - (pplayer->size == BIG && !pplayer->duck && - (issolid(pplayer->base.x, pplayer->base.y - 32)))) - {*/ - /*if (!issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y) && - (pplayer->size == SMALL || pplayer->duck || - !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32)))* / - - if (((!issolid(pplayer->base.x, pplayer->base.y- pplayer->base.ym * frame_ratio) && (issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x, pplayer->base.y+31)))) - ||((!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y) && (issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x+32, pplayer->base.y))))) - /*(pplayer->size == SMALL || pplayer->duck || - !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))* / - { - pplayer->base.y = pplayer->base.y- pplayer->base.ym * frame_ratio; - pplayer->base.ym = 0; - } + /* Reset score multiplier (for multi-hits): */ - if (((issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x+32, pplayer->base.y)) && (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y)) - /*(pplayer->size == SMALL || pplayer->duck || - !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))* /) || - (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y+pplayer->base.height) && (issolid(pplayer->base.x, pplayer->base.y+pplayer->base.height) || issolid(pplayer->base.x +32, pplayer->base.y+pplayer->base.height)))) - { - pplayer->base.x = pplayer->base.x- pplayer->base.xm * frame_ratio; - pplayer->base.xm = 0; - } + if (pplayer->base.ym > 0) + score_multiplier = 1; - if (pplayer->base.ym <= 0) - { - if (isbrick(pplayer->base.x, pplayer->base.y) || - isfullbox(pplayer->base.x, pplayer->base.y)) - { - trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE); - trybumpbadguy(pplayer->base.x, pplayer->base.y - 64); - bumpbrick(pplayer->base.x, pplayer->base.y); - tryemptybox(pplayer->base.x, pplayer->base.y); - } - if (isbrick(pplayer->base.x+ 31, pplayer->base.y) || - isfullbox(pplayer->base.x+ 31, pplayer->base.y)) - { - trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE); - trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64); - bumpbrick(pplayer->base.x+ 31, pplayer->base.y); - tryemptybox(pplayer->base.x+ 31, pplayer->base.y); - } - /* Get a distro from a brick? * / + /* Stop jumping! * / - if (shape(pplayer->base.x, pplayer->base.y) == 'x' || - shape(pplayer->base.x, pplayer->base.y) == 'y') - { - add_bouncy_distro(((pplayer->base.x+ 1) - / 32) * 32, - (int)(pplayer->base.y / 32) * 32); + pplayer->base.ym = 0; + pplayer->jumping = NO; + pplayer->input.up = UP; + } + /* FIXME: this code is COMPLETLY broken!!! */ + /*if (issolid(pplayer->base.x, pplayer->base.y) || + (pplayer->size == BIG && !pplayer->duck && + (issolid(pplayer->base.x, pplayer->base.y - 32)))) + {*/ + /*if (!issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y) && + (pplayer->size == SMALL || pplayer->duck || + !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32)))* / - if (counting_distros == NO) + if (((!issolid(pplayer->base.x, pplayer->base.y- pplayer->base.ym * frame_ratio) && (issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x, pplayer->base.y+31)))) + ||((!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y) && (issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x+32, pplayer->base.y))))) + /*(pplayer->size == SMALL || pplayer->duck || + !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))* / { - counting_distros = YES; - distro_counter = 100; + pplayer->base.y = pplayer->base.y- pplayer->base.ym * frame_ratio; + pplayer->base.ym = 0; } - if (distro_counter <= 0) - level_change(¤t_level,pplayer->base.x,pplayer->base.y, 'a'); - - play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); - score = score + SCORE_DISTRO; - distros++; - } - else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' || - shape(pplayer->base.x+ 31, pplayer->base.y) == 'y') - { - add_bouncy_distro(((pplayer->base.x+ 1 + 31) - / 32) * 32, - (int)(pplayer->base.y / 32) * 32); - - if (counting_distros == NO) + if (((issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x+32, pplayer->base.y)) && (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y)) + /*(pplayer->size == SMALL || pplayer->duck || + !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))* /) || + (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y+pplayer->base.height) && (issolid(pplayer->base.x, pplayer->base.y+pplayer->base.height) || issolid(pplayer->base.x +32, pplayer->base.y+pplayer->base.height)))) { - counting_distros = YES; - distro_counter = 100; + pplayer->base.x = pplayer->base.x- pplayer->base.xm * frame_ratio; + pplayer->base.xm = 0; } - if (distro_counter <= 0) - level_change(¤t_level,pplayer->base.x+ 31, pplayer->base.y, 'a'); - - play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); - score = score + SCORE_DISTRO; - distros++; - } - - } - else - { - pplayer->base.ym = 0; - pplayer->jumping = NO; - timer_start(&pplayer->jump_timer,MAX_JUMP_TIME); - } - /*}*/ - /* Bump into things: * / - - if (issolid(pplayer->base.x, pplayer->base.y) || - (pplayer->size == BIG && !pplayer->duck && - (issolid(pplayer->base.x, pplayer->base.y - 32)))) - { - - if (!issolid(pplayer->base.x, pplayer->base.y - pplayer->base.ym) && - (pplayer->size == SMALL || pplayer->duck || - !issolid(pplayer->base.x, pplayer->base.y - 32 - pplayer->base.ym))) - { if (pplayer->base.ym <= 0) { - /* Jumping up? */ - /* FIXME: this code is COMPLETLY broken!!! */ - if (pplayer->size == BIG) - { - /* Break bricks and empty boxes: * / - - if (!pplayer->duck) - { - if (isbrick(pplayer->base.x, pplayer->base.y - 32) || - isfullbox(pplayer->base.x, pplayer->base.y - 32)) - { - trygrabdistro(pplayer->base.x, pplayer->base.y - 64, BOUNCE); - trybumpbadguy(pplayer->base.x, pplayer->base.y - 96); - - if (isfullbox(pplayer->base.x, pplayer->base.y - 32)) - { - bumpbrick(pplayer->base.x, pplayer->base.y - 32); - } - - trybreakbrick(pplayer->base.x, pplayer->base.y - 32); - tryemptybox(pplayer->base.x, pplayer->base.y - 32); - } - - if (isbrick(pplayer->base.x+ 31, pplayer->base.y - 32) || - isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32)) - { - trygrabdistro(pplayer->base.x+ 31, - pplayer->base.y - 64, - BOUNCE); - trybumpbadguy(pplayer->base.x+ 31, - pplayer->base.y - 96); - - if (isfullbox(pplayer->base.x+ - printf("%f",pplayer->base.ym); 31, pplayer->base.y - 32)) - { - bumpbrick(pplayer->base.x+ 31, pplayer->base.y - 32); - } - - trybreakbrick(pplayer->base.x+ 31, - pplayer->base.y - 32); - tryemptybox(pplayer->base.x+ 31, - pplayer->base.y - 32); - } - } - else /* ducking * / - { - if (isbrick(pplayer->base.x, pplayer->base.y) || - isfullbox(pplayer->base.x, pplayer->base.y)) - { - trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE); - trybumpbadguy(pplayer->base.x, pplayer->base.y - 64); - if (isfullbox(pplayer->base.x, pplayer->base.y)) - bumpbrick(pplayer->base.x, pplayer->base.y); - trybreakbrick(pplayer->base.x, pplayer->base.y); - tryemptybox(pplayer->base.x, pplayer->base.y); - } - - if (isbrick(pplayer->base.x+ 31, pplayer->base.y) || - isfullbox(pplayer->base.x+ 31, pplayer->base.y)) - { - trygrabdistro(pplayer->base.x+ 31, - pplayer->base.y - 32, - BOUNCE); - trybumpbadguy(pplayer->base.x+ 31, - pplayer->base.y - 64); - if (isfullbox(pplayer->base.x+ 31, pplayer->base.y)) - bumpbrick(pplayer->base.x+ 31, pplayer->base.y); - trybreakbrick(pplayer->base.x+ 31, pplayer->base.y); - tryemptybox(pplayer->base.x+ 31, pplayer->base.y); - } - } - } - else - { - /* It's a brick and we're small, make the brick - bounce, and grab any distros above it: * / - if (isbrick(pplayer->base.x, pplayer->base.y) || isfullbox(pplayer->base.x, pplayer->base.y)) { @@ -519,8 +379,6 @@ DEBUG_MSG("+31?"); bumpbrick(pplayer->base.x+ 31, pplayer->base.y); tryemptybox(pplayer->base.x+ 31, pplayer->base.y); } - - /* Get a distro from a brick? * / if (shape(pplayer->base.x, pplayer->base.y) == 'x' || @@ -563,25 +421,184 @@ DEBUG_MSG("+31?"); score = score + SCORE_DISTRO; distros++; } - } - - /* Bump head: * / - - pplayer->base.y = (int)(pplayer->base.y / 32) * 32 + 30; } else { - /* Land on feet: * / - - pplayer->base.y = (int)(pplayer->base.y / 32) * 32 - 32; - } - pplayer->base.ym = 0; pplayer->jumping = NO; timer_start(&pplayer->jump_timer,MAX_JUMP_TIME); - }*/ - } + } + /*}*/ + /* Bump into things: * / + + if (issolid(pplayer->base.x, pplayer->base.y) || + (pplayer->size == BIG && !pplayer->duck && + (issolid(pplayer->base.x, pplayer->base.y - 32)))) + { + + if (!issolid(pplayer->base.x, pplayer->base.y - pplayer->base.ym) && + (pplayer->size == SMALL || pplayer->duck || + !issolid(pplayer->base.x, pplayer->base.y - 32 - pplayer->base.ym))) + { + if (pplayer->base.ym <= 0) + { + /* Jumping up? */ + /* FIXME: this code is COMPLETLY broken!!! */ + if (pplayer->size == BIG) + { + /* Break bricks and empty boxes: * / + + if (!pplayer->duck) + { + if (isbrick(pplayer->base.x, pplayer->base.y - 32) || + isfullbox(pplayer->base.x, pplayer->base.y - 32)) + { + trygrabdistro(pplayer->base.x, pplayer->base.y - 64, BOUNCE); + trybumpbadguy(pplayer->base.x, pplayer->base.y - 96); + + if (isfullbox(pplayer->base.x, pplayer->base.y - 32)) + { + bumpbrick(pplayer->base.x, pplayer->base.y - 32); + } + + trybreakbrick(pplayer->base.x, pplayer->base.y - 32); + tryemptybox(pplayer->base.x, pplayer->base.y - 32); + } + + if (isbrick(pplayer->base.x+ 31, pplayer->base.y - 32) || + isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32)) + { + trygrabdistro(pplayer->base.x+ 31, + pplayer->base.y - 64, + BOUNCE); + trybumpbadguy(pplayer->base.x+ 31, + pplayer->base.y - 96); + + if (isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32)) + { + bumpbrick(pplayer->base.x+ 31, pplayer->base.y - 32); + } + + trybreakbrick(pplayer->base.x+ 31, + pplayer->base.y - 32); + tryemptybox(pplayer->base.x+ 31, + pplayer->base.y - 32); + } + } + else /* ducking * / + { + if (isbrick(pplayer->base.x, pplayer->base.y) || + isfullbox(pplayer->base.x, pplayer->base.y)) + { + trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE); + trybumpbadguy(pplayer->base.x, pplayer->base.y - 64); + if (isfullbox(pplayer->base.x, pplayer->base.y)) + bumpbrick(pplayer->base.x, pplayer->base.y); + trybreakbrick(pplayer->base.x, pplayer->base.y); + tryemptybox(pplayer->base.x, pplayer->base.y); + } + + if (isbrick(pplayer->base.x+ 31, pplayer->base.y) || + isfullbox(pplayer->base.x+ 31, pplayer->base.y)) + { + trygrabdistro(pplayer->base.x+ 31, + pplayer->base.y - 32, + BOUNCE); + trybumpbadguy(pplayer->base.x+ 31, + pplayer->base.y - 64); + if (isfullbox(pplayer->base.x+ 31, pplayer->base.y)) + bumpbrick(pplayer->base.x+ 31, pplayer->base.y); + trybreakbrick(pplayer->base.x+ 31, pplayer->base.y); + tryemptybox(pplayer->base.x+ 31, pplayer->base.y); + } + } + } + else + { + /* It's a brick and we're small, make the brick + bounce, and grab any distros above it: * / + + if (isbrick(pplayer->base.x, pplayer->base.y) || + isfullbox(pplayer->base.x, pplayer->base.y)) + { + trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE); + trybumpbadguy(pplayer->base.x, pplayer->base.y - 64); + bumpbrick(pplayer->base.x, pplayer->base.y); + tryemptybox(pplayer->base.x, pplayer->base.y); + } + + if (isbrick(pplayer->base.x+ 31, pplayer->base.y) || + isfullbox(pplayer->base.x+ 31, pplayer->base.y)) + { + trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE); + trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64); + bumpbrick(pplayer->base.x+ 31, pplayer->base.y); + tryemptybox(pplayer->base.x+ 31, pplayer->base.y); + } + + + /* Get a distro from a brick? * / + + if (shape(pplayer->base.x, pplayer->base.y) == 'x' || + shape(pplayer->base.x, pplayer->base.y) == 'y') + { + add_bouncy_distro(((pplayer->base.x+ 1) + / 32) * 32, + (int)(pplayer->base.y / 32) * 32); + + if (counting_distros == NO) + { + counting_distros = YES; + distro_counter = 100; + } + + if (distro_counter <= 0) + level_change(¤t_level,pplayer->base.x,pplayer->base.y, 'a'); + + play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); + score = score + SCORE_DISTRO; + distros++; + } + else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' || + shape(pplayer->base.x+ 31, pplayer->base.y) == 'y') + { + add_bouncy_distro(((pplayer->base.x+ 1 + 31) + / 32) * 32, + (int)(pplayer->base.y / 32) * 32); + + if (counting_distros == NO) + { + counting_distros = YES; + distro_counter = 100; + } + + if (distro_counter <= 0) + level_change(¤t_level,pplayer->base.x+ 31, pplayer->base.y, 'a'); + + play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); + score = score + SCORE_DISTRO; + distros++; + } + } + + + /* Bump head: * / + + pplayer->base.y = (int)(pplayer->base.y / 32) * 32 + 30; + } + else + { + /* Land on feet: * / + + pplayer->base.y = (int)(pplayer->base.y / 32) * 32 - 32; + } + + pplayer->base.ym = 0; + pplayer->jumping = NO; + timer_start(&pplayer->jump_timer,MAX_JUMP_TIME); + }*/ + } } @@ -626,7 +643,7 @@ DEBUG_MSG("+31?"); } - + */ timer_check(&pplayer->safe_timer); @@ -675,6 +692,20 @@ DEBUG_MSG("+31?"); } +int player_on_ground(player_type *pplayer) +{ + if( issolid(pplayer->base.x + pplayer->base.width / 2, pplayer->base.y + pplayer->base.height + 1) || + issolid(pplayer->base.x + 1, pplayer->base.y + pplayer->base.height + 1) || + issolid(pplayer->base.x + pplayer->base.width - 1, pplayer->base.y + pplayer->base.height + 1) ) + { + return YES; + } + else + { + return NO; + } +} + void player_handle_horizontal_input(player_type *pplayer, int dir) { if (pplayer->jumping == NO) @@ -759,12 +790,13 @@ void player_handle_vertical_input(player_type *pplayer) { if(pplayer->input.up == DOWN) { - if (issolid(pplayer->base.x + 16, pplayer->base.y + pplayer->base.height + 1)) + if (player_on_ground(pplayer)) { if(!physic_is_set(&pplayer->vphysic)) { physic_set_state(&pplayer->vphysic,PH_VT); - physic_set_start_vy(&pplayer->vphysic,5.2); + physic_set_start_vy(&pplayer->vphysic,5.5); + --pplayer->base.y; pplayer->jumping = YES; if (pplayer->size == SMALL) play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER); @@ -796,16 +828,22 @@ void player_handle_vertical_input(player_type *pplayer) else { pplayer->jumping = NO; - physic_set_state(&pplayer->vphysic,PH_VT); - physic_set_start_vy(&pplayer->vphysic,0); - if(physic_is_set(&pplayer->vphysic) && pplayer->vphysic.start_vx != 0) + printf("%f",physic_get_velocity(&pplayer->vphysic)); + if(physic_is_set(&pplayer->vphysic)) { + if(physic_get_velocity(&pplayer->vphysic) < 0.) + { + physic_set_state(&pplayer->vphysic,PH_VT); + DEBUG_MSG("DUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUDE"); physic_set_start_vy(&pplayer->vphysic,0); + } } else { + DEBUG_MSG("CHUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUHHHHAAA"); if(!physic_is_set(&pplayer->vphysic)) { + DEBUG_MSG("CHUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUHHHHAAA"); physic_set_state(&pplayer->vphysic,PH_VT); } } @@ -1017,13 +1055,13 @@ void player_draw(player_type* pplayer) if (pplayer->dir == RIGHT) { texture_draw(&bigcape_right[frame % 2], - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } else { texture_draw(&bigcape_left[frame % 2], - pplayer->base.x-scroll_x, pplayer->base.y, + pplayer->base.x-scroll_x - 8, pplayer->base.y, NO_UPDATE); } } @@ -1039,13 +1077,13 @@ void player_draw(player_type* pplayer) if (pplayer->dir == RIGHT) { texture_draw(&bigtux_right[pplayer->frame], - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } else { texture_draw(&bigtux_left[pplayer->frame], - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } } @@ -1054,13 +1092,13 @@ void player_draw(player_type* pplayer) if (pplayer->dir == RIGHT) { texture_draw(&bigtux_right_jump, - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } else { texture_draw(&bigtux_left_jump, - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } } @@ -1070,13 +1108,13 @@ void player_draw(player_type* pplayer) if (pplayer->dir == RIGHT) { texture_draw(&skidtux_right, - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } else { texture_draw(&skidtux_left, - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } } @@ -1085,12 +1123,12 @@ void player_draw(player_type* pplayer) { if (pplayer->dir == RIGHT) { - texture_draw(&ducktux_right, pplayer->base.x- scroll_x, pplayer->base.y, + texture_draw(&ducktux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } else { - texture_draw(&ducktux_left, pplayer->base.x- scroll_x, pplayer->base.y, + texture_draw(&ducktux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } } @@ -1108,13 +1146,13 @@ void player_draw(player_type* pplayer) if (pplayer->dir == RIGHT) { texture_draw(&bigfiretux_right[pplayer->frame], - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } else { texture_draw(&bigfiretux_left[pplayer->frame], - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } } @@ -1123,13 +1161,13 @@ void player_draw(player_type* pplayer) if (pplayer->dir == RIGHT) { texture_draw(&bigfiretux_right_jump, - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } else { texture_draw(&bigfiretux_left_jump, - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } } @@ -1139,13 +1177,13 @@ void player_draw(player_type* pplayer) if (pplayer->dir == RIGHT) { texture_draw(&skidfiretux_right, - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } else { texture_draw(&skidfiretux_left, - pplayer->base.x- scroll_x, pplayer->base.y, + pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } } @@ -1154,12 +1192,12 @@ void player_draw(player_type* pplayer) { if (pplayer->dir == RIGHT) { - texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x, pplayer->base.y, + texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } else { - texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x, pplayer->base.y, + texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y, NO_UPDATE); } } diff --git a/src/player.h b/src/player.h index 3167644e4..0563db817 100644 --- a/src/player.h +++ b/src/player.h @@ -108,5 +108,6 @@ void player_kill(player_type *pplayer, int mode); void player_dying(player_type *pplayer); void player_remove_powerups(player_type *pplayer); void player_keep_in_bounds(player_type *pplayer); +int player_on_ground(player_type *pplayer); #endif /*SUPERTUX_PLAYER_H*/ diff --git a/src/scene.c b/src/scene.c index e43e3d90f..dad92df3d 100644 --- a/src/scene.c +++ b/src/scene.c @@ -74,7 +74,7 @@ void set_defaults(void) scroll_x = 0; score_multiplier = 1; - timer_init(&super_bkgd_timer); + timer_init(&super_bkgd_timer, YES); counting_distros = NO; distro_counter = 0; diff --git a/src/setup.c b/src/setup.c index 963379b33..899e85167 100644 --- a/src/setup.c +++ b/src/setup.c @@ -221,57 +221,63 @@ void st_directory_setup(void) void st_menu(void) { menu_init(&main_menu); + menu_additem(&main_menu,menu_item_create(MN_LABEL,"Main Menu",0,0)); + menu_additem(&main_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&main_menu,menu_item_create(MN_ACTION,"Start Game",0,0)); menu_additem(&main_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu)); menu_additem(&main_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu)); menu_additem(&main_menu,menu_item_create(MN_ACTION,"Level editor",0,0)); + menu_additem(&main_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&main_menu,menu_item_create(MN_ACTION,"Quit",0,0)); menu_init(&options_menu); + menu_additem(&options_menu,menu_item_create(MN_LABEL,"Options",0,0)); + menu_additem(&options_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Fullscreen",use_fullscreen,0)); if(audio_device == YES) { - menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Sound",use_sound,0)); - menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Music",use_music,0)); + menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Sound ",use_sound,0)); + menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Music ",use_music,0)); } else { - menu_additem(&options_menu,menu_item_create(MN_DEACTIVE,"Sound",use_sound,0)); - menu_additem(&options_menu,menu_item_create(MN_DEACTIVE,"Music",use_music,0)); + menu_additem(&options_menu,menu_item_create(MN_DEACTIVE,"Sound ",use_sound,0)); + menu_additem(&options_menu,menu_item_create(MN_DEACTIVE,"Music ",use_music,0)); } - menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Show FPS",show_fps,0)); + menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Show FPS ",show_fps,0)); + menu_additem(&options_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&options_menu,menu_item_create(MN_BACK,"Back",0,0)); - menu_init(&leveleditor_menu); - menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Return To Level Editor",0,0)); - menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"New Level",0,0)); - menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Load Level",0,0)); - menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Save Level",0,0)); - menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Quit Level Editor",0,0)); - menu_init(&load_game_menu); menu_additem(&load_game_menu,menu_item_create(MN_LABEL,"Load Game",0,0)); + menu_additem(&load_game_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 1",0,0)); menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 2",0,0)); menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 3",0,0)); menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 4",0,0)); menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 5",0,0)); + menu_additem(&load_game_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&load_game_menu,menu_item_create(MN_BACK,"Back",0,0)); menu_init(&save_game_menu); menu_additem(&save_game_menu,menu_item_create(MN_LABEL,"Save Game",0,0)); + menu_additem(&save_game_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 1",0,0)); menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 2",0,0)); menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 3",0,0)); menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 4",0,0)); menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 5",0,0)); + menu_additem(&save_game_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&save_game_menu,menu_item_create(MN_BACK,"Back",0,0)); menu_init(&game_menu); + menu_additem(&game_menu,menu_item_create(MN_LABEL,"InGame Menu",0,0)); + menu_additem(&game_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&game_menu,menu_item_create(MN_ACTION,"Return To Game",0,0)); menu_additem(&game_menu,menu_item_create(MN_GOTO,"Save Game",0,&save_game_menu)); menu_additem(&game_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu)); menu_additem(&game_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu)); + menu_additem(&game_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&game_menu,menu_item_create(MN_ACTION,"Quit Game",0,0)); menu_init(&highscore_menu); @@ -283,10 +289,10 @@ void update_load_save_game_menu(menu_type* pmenu, int load) { int i; - for(i = 1; i < 6; ++i) + for(i = 2; i < 7; ++i) { char *tmp; - slotinfo(&tmp,i); + slotinfo(&tmp,i-1); if(load && strlen(tmp) == strlen("Slot X - Free") ) pmenu->item[i].kind = MN_DEACTIVE; else @@ -326,19 +332,19 @@ void process_options_menu(void) { switch (menu_check(&options_menu)) { - case 0: - if(use_fullscreen != options_menu.item[0].toggled) + case 2: + if(use_fullscreen != options_menu.item[2].toggled) { use_fullscreen = !use_fullscreen; st_video_setup(); } break; - case 1: - if(use_sound != options_menu.item[1].toggled) + case 3: + if(use_sound != options_menu.item[3].toggled) use_sound = !use_sound; break; - case 2: - if(use_music != options_menu.item[2].toggled) + case 4: + if(use_music != options_menu.item[4].toggled) { if(use_music == YES) { @@ -358,8 +364,8 @@ void process_options_menu(void) } } break; - case 3: - if(show_fps != options_menu.item[3].toggled) + case 5: + if(show_fps != options_menu.item[5].toggled) show_fps = !show_fps; break; } @@ -415,7 +421,6 @@ void st_general_free(void) menu_free(&main_menu); menu_free(&game_menu); menu_free(&options_menu); - menu_free(&leveleditor_menu); menu_free(&highscore_menu); } @@ -496,7 +501,7 @@ void st_video_setup_gl(void) if (use_fullscreen == YES) { - screen = SDL_SetVideoMode(640, 480, 32, SDL_FULLSCREEN | SDL_OPENGL | SDL_OPENGLBLIT ) ; /* | SDL_HWSURFACE); */ + screen = SDL_SetVideoMode(640, 480, 32, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */ if (screen == NULL) { fprintf(stderr, @@ -509,7 +514,7 @@ void st_video_setup_gl(void) } else { - screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_OPENGL | SDL_OPENGLBLIT ); + screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL); if (screen == NULL) { diff --git a/src/supertux.c b/src/supertux.c index 3ae6fd9af..d18565fc9 100644 --- a/src/supertux.c +++ b/src/supertux.c @@ -32,7 +32,7 @@ int main(int argc, char * argv[]) st_joystick_setup(); st_general_setup(); st_menu(); - + done = intro(); done = 0; diff --git a/src/texture.c b/src/texture.c index 803c5b301..2284786c6 100644 --- a/src/texture.c +++ b/src/texture.c @@ -87,10 +87,10 @@ void texture_create_gl(SDL_Surface * surf, GLuint * tex) Uint8 saved_alpha; int w, h; SDL_Surface *conv; - + w = power_of_two(surf->w); h = power_of_two(surf->h), - conv = SDL_CreateRGBSurface(surf->flags, w, h, surf->format->BitsPerPixel, + conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel, #if SDL_BYTEORDER == SDL_BIG_ENDIAN 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); #else @@ -116,11 +116,8 @@ void texture_create_gl(SDL_Surface * surf, GLuint * tex) SDL_SetAlpha(surf, saved_flags, saved_alpha); } - glGenTextures(1, &*tex); - glBindTexture(GL_TEXTURE_2D , *tex); - glEnable(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -128,7 +125,7 @@ void texture_create_gl(SDL_Surface * surf, GLuint * tex) glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glDisable(GL_BLEND); + SDL_FreeSurface(conv); } @@ -224,28 +221,28 @@ float ph = power_of_two(ptexture->h); void texture_load_sdl(texture_type* ptexture, char * file, int use_alpha) { SDL_Surface * temp; - + temp = IMG_Load(file); if (temp == NULL) st_abort("Can't load", file); - if(use_alpha == IGNORE_ALPHA) + if(use_alpha == IGNORE_ALPHA && !use_gl) ptexture->sdl_surface = SDL_DisplayFormat(temp); else ptexture->sdl_surface = SDL_DisplayFormatAlpha(temp); - + if (ptexture->sdl_surface == NULL) st_abort("Can't covert to display format", file); - if (use_alpha == IGNORE_ALPHA) + if (use_alpha == IGNORE_ALPHA && !use_gl) SDL_SetAlpha(ptexture->sdl_surface, 0, 0); SDL_FreeSurface(temp); ptexture->w = ptexture->sdl_surface->w; ptexture->h = ptexture->sdl_surface->h; - + } void texture_load_part_sdl(texture_type* ptexture, char * file, int x, int y, int w, int h, int use_alpha) @@ -283,7 +280,7 @@ void texture_load_part_sdl(texture_type* ptexture, char * file, int x, int y, in SDL_SetAlpha(temp,0,0); SDL_BlitSurface(temp, &src, conv, NULL); - if(use_alpha == IGNORE_ALPHA) + if(use_alpha == IGNORE_ALPHA && !use_gl) ptexture->sdl_surface = SDL_DisplayFormat(conv); else ptexture->sdl_surface = SDL_DisplayFormatAlpha(conv); @@ -291,7 +288,7 @@ void texture_load_part_sdl(texture_type* ptexture, char * file, int x, int y, in if (ptexture->sdl_surface == NULL) st_abort("Can't covert to display format", file); - if (use_alpha == IGNORE_ALPHA) + if (use_alpha == IGNORE_ALPHA && !use_gl) SDL_SetAlpha(ptexture->sdl_surface, 0, 0); SDL_FreeSurface(temp); @@ -315,7 +312,7 @@ void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int SDL_SetAlpha(sdl_surf, 0, 0); } - if(use_alpha == IGNORE_ALPHA) + if(use_alpha == IGNORE_ALPHA && !use_gl) ptexture->sdl_surface = SDL_DisplayFormat(sdl_surf); else ptexture->sdl_surface = SDL_DisplayFormatAlpha(sdl_surf); @@ -330,7 +327,7 @@ void texture_from_sdl_surface(texture_type* ptexture, SDL_Surface* sdl_surf, int if (ptexture->sdl_surface == NULL) st_abort("Can't covert to display format", "SURFACE"); - if (use_alpha == IGNORE_ALPHA) + if (use_alpha == IGNORE_ALPHA && !use_gl) SDL_SetAlpha(ptexture->sdl_surface, 0, 0); ptexture->w = ptexture->sdl_surface->w; diff --git a/src/timer.c b/src/timer.c index ffe58cd05..eb9cccd8d 100644 --- a/src/timer.c +++ b/src/timer.c @@ -41,26 +41,35 @@ st_pause_ticks += SDL_GetTicks() - st_pause_count; st_pause_count = 0; } -void timer_init(timer_type* ptimer) +void timer_init(timer_type* ptimer, int st_ticks) { ptimer->period = 0; ptimer->time = 0; + + if(st_ticks == YES) + ptimer->get_ticks = st_get_ticks; + else + ptimer->get_ticks = SDL_GetTicks; + } void timer_start(timer_type* ptimer, unsigned int period) { - ptimer->time = st_get_ticks(); + ptimer->time = ptimer->get_ticks(); ptimer->period = period; } void timer_stop(timer_type* ptimer) { - timer_init(ptimer); +if(ptimer->get_ticks == st_get_ticks) + timer_init(ptimer,YES); +else + timer_init(ptimer,NO); } int timer_check(timer_type* ptimer) { - if((ptimer->time != 0) && (ptimer->time + ptimer->period > st_get_ticks())) + if((ptimer->time != 0) && (ptimer->time + ptimer->period > ptimer->get_ticks())) return YES; else { @@ -79,10 +88,10 @@ int timer_started(timer_type* ptimer) int timer_get_left(timer_type* ptimer) { - return (ptimer->period - (st_get_ticks() - ptimer->time)); + return (ptimer->period - (ptimer->get_ticks() - ptimer->time)); } int timer_get_gone(timer_type* ptimer) { - return (st_get_ticks() - ptimer->time); + return (ptimer->get_ticks() - ptimer->time); } diff --git a/src/timer.h b/src/timer.h index 9529242bc..8cd880a8e 100644 --- a/src/timer.h +++ b/src/timer.h @@ -18,6 +18,7 @@ typedef struct timer_type { unsigned int period; unsigned int time; + unsigned int (*get_ticks) (void); } timer_type; @@ -27,7 +28,7 @@ unsigned int st_get_ticks(void); void st_pause_ticks_init(void); void st_pause_ticks_start(void); void st_pause_ticks_stop(void); -void timer_init(timer_type* ptimer); +void timer_init(timer_type* ptimer, int st_ticks); void timer_start(timer_type* ptimer, unsigned int period); void timer_stop(timer_type* ptimer); /*====================================================================== diff --git a/src/title.c b/src/title.c index 5e2af7668..da2d1fde8 100644 --- a/src/title.c +++ b/src/title.c @@ -47,13 +47,13 @@ int title(void) int done, quit, frame, pict, i; char str[80]; char **level_subsets; - level_subsets = NULL; int subsets_num; + level_subsets = NULL; level_subsets = dsubdirs("/levels", "info", &subsets_num); st_subset subset; subset_init(&subset); - /* Rest menu variables */ + /* Reset menu variables */ menu_reset(); menu_set_current(&main_menu); @@ -65,8 +65,8 @@ int title(void) texture_load(&title,DATA_PREFIX "/images/title/title.png", IGNORE_ALPHA); texture_load(&anim1,DATA_PREFIX "/images/title/title-anim2.png", IGNORE_ALPHA); texture_load(&anim2,DATA_PREFIX "/images/title/title-anim1.png", IGNORE_ALPHA); - texture_load(&img_choose_subset,DATA_PREFIX "/images/status/choose-level-subset.png", IGNORE_ALPHA); - + texture_load(&img_choose_subset,DATA_PREFIX "/images/status/choose-level-subset.png", USE_ALPHA); + /* --- Main title loop: --- */ done = 0; @@ -78,7 +78,7 @@ int title(void) texture_draw_bg(&title, NO_UPDATE); load_hs(); - + while (!done && !quit) { frame++; @@ -154,7 +154,7 @@ int title(void) { switch (menu_check(&main_menu)) { - case 0: + case 2: done = 0; i = 0; if(level_subsets != NULL) @@ -218,14 +218,14 @@ int title(void) } } break; - case 1: + case 3: update_load_save_game_menu(&load_game_menu, YES); break; - case 3: + case 5: done = 1; quit = leveleditor(1); break; - case 4: + case 7: quit = 1; break; } diff --git a/src/world.c b/src/world.c index 3988a3f4e..7e7c4e6ea 100644 --- a/src/world.c +++ b/src/world.c @@ -59,6 +59,7 @@ void broken_brick_init(broken_brick_type* pbroken_brick, float x, float y, float pbroken_brick->base.y = y; pbroken_brick->base.xm = xm; pbroken_brick->base.ym = ym; + timer_init(&pbroken_brick->timer,YES); timer_start(&pbroken_brick->timer,200); } @@ -163,6 +164,7 @@ void floating_score_init(floating_score_type* pfloating_score, float x, float y, pfloating_score->base.alive = YES; pfloating_score->base.x = x; pfloating_score->base.y = y - 16; + timer_init(&pfloating_score->timer,YES); timer_start(&pfloating_score->timer,1000); pfloating_score->value = s; }