[Super-tux-commit] supertux/src badguy.cpp,1.17,1.18 badguy.h,1.18,1.19 gameloop.cpp,1.38,1.39 globa
Brought to you by:
wkendrick
From: Tobias Gl??er <to...@us...> - 2004-03-29 13:36:12
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21235/src Modified Files: badguy.cpp badguy.h gameloop.cpp globals.cpp globals.h intro.cpp leveleditor.cpp menu.cpp scene.cpp scene.h special.cpp Log Message: - introduced new function wait_for_event - removed arrays_init() - applied fixes from Matze Braun for badguy bugs Index: scene.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/scene.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- scene.cpp 24 Mar 2004 22:15:44 -0000 1.9 +++ scene.cpp 29 Mar 2004 13:24:42 -0000 1.10 @@ -45,10 +45,6 @@ timer_type time_left; double frame_ratio; -void arrays_init(void) -{ -} - void arrays_free(void) { bad_guys.clear(); Index: intro.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/intro.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- intro.cpp 22 Mar 2004 15:52:35 -0000 1.8 +++ intro.cpp 29 Mar 2004 13:24:41 -0000 1.9 @@ -2,7 +2,7 @@ intro.c Super Tux - Intro Screen - + by Bill Kendrick bi...@ne... http://www.newbreedsoftware.com/supertux/ @@ -29,11 +29,11 @@ #include "timer.h" char * intro_text[] = { - "Tux and Gown were having a nice picnic..", - "when suddenly...", - "Gown is beamed away!!!", - "This looks like a job for ---" -}; + "Tux and Gown were having a nice picnic..", + "when suddenly...", + "Gown is beamed away!!!", + "This looks like a job for ---" + }; /* --- INTRO --- */ @@ -42,16 +42,16 @@ { SDL_Event event; texture_type bkgd, copter_squish, copter_stretch, beam, - gown_sit, gown_lookup, gown_upset, - tux_sit, tux_upset, tux_mad; + gown_sit, gown_lookup, gown_upset, + tux_sit, tux_upset, tux_mad; texture_type copter[2]; SDL_Rect src, dest; int done, i, quit, j, scene; int * height, * height_speed; timer_type timer; - + /* Load sprite images: */ - texture_load(&bkgd, datadir + "/images/intro/intro.png", IGNORE_ALPHA); + texture_load(&bkgd, datadir + "/images/intro/intro.png", IGNORE_ALPHA); texture_load(&gown_sit, datadir + "/images/intro/gown-sit.png", USE_ALPHA); texture_load(&gown_lookup, datadir + "/images/intro/gown-lookup.png", USE_ALPHA); texture_load(&gown_upset, datadir + "/images/intro/gown-upset.png", USE_ALPHA); @@ -59,244 +59,228 @@ texture_load(&tux_upset, datadir + "/images/intro/tux-upset.png", USE_ALPHA); texture_load(&tux_mad, datadir + "/images/intro/tux-mad.png", USE_ALPHA); texture_load(&copter[0], datadir + "/images/intro/copter1.png", USE_ALPHA); - texture_load(&copter[1], datadir + "/images/intro/copter2.png", USE_ALPHA); - texture_load(&copter_squish, datadir + "/images/intro/copter-squish.png", USE_ALPHA); - texture_load(&copter_stretch, datadir + "/images/intro/copter-stretch.png", USE_ALPHA); - texture_load(&beam, datadir + "/images/intro/beam.png", USE_ALPHA); - + texture_load(&copter[1], datadir + "/images/intro/copter2.png", USE_ALPHA); + texture_load(&copter_squish, datadir + "/images/intro/copter-squish.png", USE_ALPHA); + texture_load(&copter_stretch, datadir + "/images/intro/copter-stretch.png", USE_ALPHA); + texture_load(&beam, datadir + "/images/intro/beam.png", USE_ALPHA); + /* Allocate buffer for height array: */ - + height = (int*) malloc(sizeof(int) * (gown_upset.w)); height_speed = (int*) malloc(sizeof(int) * (gown_upset.w)); - - + + /* Initialize height arrays: */ - + for (j = 0; j < (gown_upset.w); j++) { height[j] = 400; height_speed[j] = (rand() % 10) + 1; } - - /* Display background: */ - + + /* Display background: */ + texture_draw_bg(&bkgd, UPDATE); - + /* Animation: */ - + done = 0; quit = 0; scene = 0; i = 0; - + timer_init(&timer, false); timer_start(&timer,10000); - + while (timer_check(&timer) && !done && !quit) { - - /* Handle events: */ - - while (SDL_PollEvent(&event)) + + + done = wait_for_event(event,0); + if(done == 2) { - if (event.type == SDL_QUIT) - { - /* Quit event - quit: */ - - quit = 1; - } - else if (event.type == SDL_KEYDOWN) - { - /* Keypress - skip intro: */ - - done = 1; - } - else if (event.type == SDL_JOYBUTTONDOWN) - { - /* Fire button - skip intro: */ - - done = 1; - } - } - - - /* Display background: */ - + quit = 1; + done = 0; + } + + + /* Display background: */ + /* Draw things: */ - + if (timer_get_gone(&timer) < 2000 && scene == 0) - { - ++scene; - /* Gown and tux sitting: */ - - texture_draw(&tux_sit, 270, 400, UPDATE); - texture_draw(&gown_sit, 320, 400, UPDATE); - - text_drawf(&white_text, intro_text[0], 0, -8, A_HMIDDLE, A_BOTTOM, 0); - } - - + { + ++scene; + /* Gown and tux sitting: */ + + texture_draw(&tux_sit, 270, 400, UPDATE); + texture_draw(&gown_sit, 320, 400, UPDATE); + + text_drawf(&white_text, intro_text[0], 0, -8, A_HMIDDLE, A_BOTTOM, 0); + } + + if (timer_get_gone(&timer) >= 2000 && scene == 1) - { - ++scene; - /* Helicopter begins to fly in: */ - - erasecenteredtext(&white_text, intro_text[0], 454, &bkgd, NO_UPDATE, 1); - text_drawf(&white_text, intro_text[1], 0,-8, A_HMIDDLE, A_BOTTOM, 0); - } + { + ++scene; + /* Helicopter begins to fly in: */ + + erasecenteredtext(&white_text, intro_text[0], 454, &bkgd, NO_UPDATE, 1); + text_drawf(&white_text, intro_text[1], 0,-8, A_HMIDDLE, A_BOTTOM, 0); + } + - if (timer_get_gone(&timer) >= 2000 && timer_get_gone(&timer) < 4000) - { - /* Helicopter flying in: */ - texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h)); - - texture_draw(&copter[i % 2], - (float)(timer_get_gone(&timer) - 2000) / 5 - (copter[0].w), 32, - NO_UPDATE); + { + /* Helicopter flying in: */ + texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h)); + + texture_draw(&copter[i % 2], + (float)(timer_get_gone(&timer) - 2000) / 5 - (copter[0].w), 32, + NO_UPDATE); + + update_rect(screen, 0, 32, screen->w, (copter[0].h)); + } - update_rect(screen, 0, 32, screen->w, (copter[0].h)); - } - if (timer_get_gone(&timer) >= 2500 && scene == 2) - { - ++scene; - /* Gown notices something... */ - - texture_draw(&gown_lookup, 320, 400, UPDATE); - } + { + ++scene; + /* Gown notices something... */ + + texture_draw(&gown_lookup, 320, 400, UPDATE); + } + - if (timer_get_gone(&timer) >= 3500 && scene == 3) - { - ++scene; - /* Gown realizes it's bad! */ - - texture_draw(&gown_upset, 320, 400, UPDATE); - } + { + ++scene; + /* Gown realizes it's bad! */ + + texture_draw(&gown_upset, 320, 400, UPDATE); + } + - if (timer_get_gone(&timer) >= 4000 && timer_get_gone(&timer) < 8000) - { - /* Helicopter sits: */ - texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h)); - - texture_draw(&copter[i % 2], 400 - (copter[0].w), 32); - update_rect(screen, 0, 32, screen->w, (copter[0].h)); - } + { + /* Helicopter sits: */ + texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h)); + + texture_draw(&copter[i % 2], 400 - (copter[0].w), 32); + update_rect(screen, 0, 32, screen->w, (copter[0].h)); + } + - if (timer_get_gone(&timer) >= 5000 && scene == 4) - { - ++scene; - /* Tux realizes something's happening: */ - - texture_draw(&tux_upset, 270, 400, UPDATE); - - - erasecenteredtext(&white_text, intro_text[1], 454, &bkgd, UPDATE, 1); - text_drawf(&white_text, intro_text[2], 0,-8, A_HMIDDLE, A_BOTTOM, 0); - } - - + { + ++scene; + /* Tux realizes something's happening: */ + + texture_draw(&tux_upset, 270, 400, UPDATE); + + + erasecenteredtext(&white_text, intro_text[1], 454, &bkgd, UPDATE, 1); + text_drawf(&white_text, intro_text[2], 0,-8, A_HMIDDLE, A_BOTTOM, 0); + } + + if (timer_get_gone(&timer) >= 5000 && timer_get_gone(&timer) <= 8000) - { - /* Beam gown up! */ - - texture_draw_part(&bkgd, - 310, 32 + (copter[0].h), 310, - 32 + (copter[0].h), - (gown_upset.w) + 20, - 376 + (gown_upset.h) - (copter[0].h)); - - - for (j = 0; j < (gown_upset.sdl_surface -> w); j++) - { - texture_draw(&beam, 320 + j - ((beam.w) / 2), height[j], - NO_UPDATE); - - src.x = j; - src.y = 0; - src.w = 1; - src.h = (gown_upset.h); - - dest.x = 320 + j; - dest.y = height[j]; - dest.w = src.w; - dest.h = src.h; - - texture_draw_part(&gown_upset,src.x,src.y,dest.x,dest.y,dest.w,dest.h); - - height[j] = 400 + rand() % 10 - (int)(300. * ((float)(timer_get_gone(&timer) - 5000)/(float)3000.)); - if(height[j] < 105) - height[j] = 105; - } + { + /* Beam gown up! */ + + texture_draw_part(&bkgd, + 310, 32 + (copter[0].h), 310, + 32 + (copter[0].h), + (gown_upset.w) + 20, + 376 + (gown_upset.h) - (copter[0].h)); + + + for (j = 0; j < (gown_upset.sdl_surface -> w); j++) + { + texture_draw(&beam, 320 + j - ((beam.w) / 2), height[j], + NO_UPDATE); + + src.x = j; + src.y = 0; + src.w = 1; + src.h = (gown_upset.h); + + dest.x = 320 + j; + dest.y = height[j]; + dest.w = src.w; + dest.h = src.h; + + texture_draw_part(&gown_upset,src.x,src.y,dest.x,dest.y,dest.w,dest.h); + + height[j] = 400 + rand() % 10 - (int)(300. * ((float)(timer_get_gone(&timer) - 5000)/(float)3000.)); + if(height[j] < 105) + height[j] = 105; + } + + update_rect(screen, + 310, + 32 + (copter[0].h), + (gown_upset.w) + 20, + 400 + (gown_upset.h) - (copter[0].h)); + } + - update_rect(screen, - 310, - 32 + (copter[0].h), - (gown_upset.w) + 20, - 400 + (gown_upset.h) - (copter[0].h)); - } - - if (timer_get_gone(&timer) >= 8000 && scene == 5) - { - texture_draw_part(&bkgd, - 310, 32 + (copter[0].h), 310, - 32 + (copter[0].h), - (gown_upset.w) + 20, - 368 + (gown_upset.h) - (copter[0].h)); - - ++scene; - /* Tux gets mad! */ - - texture_draw(&tux_mad, 270, 400, UPDATE); - - erasecenteredtext(&white_text, intro_text[2], 454, &bkgd, UPDATE, 1); - text_drawf(&white_text, intro_text[3], 0,-8, A_HMIDDLE, A_BOTTOM, 0); - } - - + { + texture_draw_part(&bkgd, + 310, 32 + (copter[0].h), 310, + 32 + (copter[0].h), + (gown_upset.w) + 20, + 368 + (gown_upset.h) - (copter[0].h)); + + ++scene; + /* Tux gets mad! */ + + texture_draw(&tux_mad, 270, 400, UPDATE); + + erasecenteredtext(&white_text, intro_text[2], 454, &bkgd, UPDATE, 1); + text_drawf(&white_text, intro_text[3], 0,-8, A_HMIDDLE, A_BOTTOM, 0); + } + + if (timer_get_gone(&timer) >= 8000 && timer_get_gone(&timer) <= 8250) - { - /* Helicopter starting to speed off: */ - - texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_squish.h)); - - texture_draw(&copter_squish, - 400 - (copter[0].w), 32, - NO_UPDATE); + { + /* Helicopter starting to speed off: */ - update_rect(screen, 0, 32, screen->w, (copter_squish.h)); - } + texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_squish.h)); + + texture_draw(&copter_squish, + 400 - (copter[0].w), 32, + NO_UPDATE); + + update_rect(screen, 0, 32, screen->w, (copter_squish.h)); + } if (timer_get_gone(&timer) >= 8250) - { - /* Helicopter speeding off: */ - - texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_stretch.h)); - - texture_draw(&copter_stretch, - (timer_get_gone(&timer) - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w), - 32, - NO_UPDATE); - - update_rect(screen, 0, 32, screen->w, (copter_stretch.h)); - } - - flipscreen(); + { + /* Helicopter speeding off: */ + + texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_stretch.h)); + + texture_draw(&copter_stretch, + (timer_get_gone(&timer) - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w), + 32, + NO_UPDATE); + + update_rect(screen, 0, 32, screen->w, (copter_stretch.h)); + } + + flipscreen(); ++i; /* Pause: */ SDL_Delay(20); } - + /* Free surfaces: */ - + texture_free(&bkgd); texture_free(&gown_sit); texture_free(&gown_lookup); @@ -309,15 +293,15 @@ texture_free(&copter_squish); texture_free(&copter_stretch); texture_free(&beam); - - + + /* Free array buffers: */ - + free(height); free(height_speed); - - + + /* Return to main! */ - + return(quit); } Index: special.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/special.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- special.cpp 24 Mar 2004 17:41:04 -0000 1.4 +++ special.cpp 29 Mar 2004 13:24:42 -0000 1.5 @@ -89,10 +89,15 @@ void bullet_collision(bullet_type* pbullet, int c_object) { - - if(c_object == CO_BADGUY) - bullets.erase(static_cast<std::vector<bullet_type>::iterator>(pbullet)); - + if(c_object == CO_BADGUY) { + std::vector<bullet_type>::iterator i; + for(i = bullets.begin(); i != bullets.end(); ++i) { + if(& (*i) == pbullet) { + bullets.erase(i); + return; + } + } + } } void upgrade_init(upgrade_type *pupgrade, float x, float y, int dir, int kind) Index: globals.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/globals.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- globals.h 28 Mar 2004 01:00:16 -0000 1.20 +++ globals.h 29 Mar 2004 13:24:41 -0000 1.21 @@ -44,6 +44,8 @@ extern SDL_Joystick * js; +int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false); + #define JOYSTICK_DEAD_ZONE 4096 #endif /* SUPERTUX_GLOBALS_H */ Index: scene.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/scene.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- scene.h 24 Mar 2004 22:23:48 -0000 1.14 +++ scene.h 29 Mar 2004 13:24:42 -0000 1.15 @@ -53,7 +53,6 @@ void add_score(float x, float y, int s); void set_defaults(void); -void arrays_init(void); void arrays_free(void); void add_bouncy_distro(float x, float y); Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- gameloop.cpp 28 Mar 2004 14:11:53 -0000 1.38 +++ gameloop.cpp 29 Mar 2004 13:24:41 -0000 1.39 @@ -87,7 +87,8 @@ flipscreen(); - SDL_Delay(1000); + SDL_Event event; + wait_for_event(event,1000,3000,true); } /* Reset Timers */ @@ -370,7 +371,6 @@ } arrays_free(); - arrays_init(); activate_bad_guys(); activate_particle_systems(); level_free_gfx(); @@ -594,7 +594,7 @@ level = levelnb; /* Init the game: */ - arrays_init(); + arrays_free(); set_defaults(); strcpy(level_subset,subset); @@ -761,8 +761,10 @@ /* Pause till next frame, if the machine running the game is too fast: */ /* FIXME: Works great for in OpenGl mode, where the CPU doesn't have to do that much. But the results in SDL mode aren't perfect (thought the 100 FPS are reached), even on an AMD2500+. */ - if(last_update_time >= update_time - 12 && !jump) + if(last_update_time >= update_time - 12 && !jump) { SDL_Delay(10); + update_time = st_get_ticks(); + } /*if((update_time - last_update_time) < 10) SDL_Delay((11 - (update_time - last_update_time))/2);*/ @@ -1548,7 +1550,9 @@ text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1); flipscreen(); - SDL_Delay(2000); + + SDL_Event event; + wait_for_event(event,2000,5000,true); } void drawresultscreen(void) @@ -1566,7 +1570,9 @@ text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1); flipscreen(); - SDL_Delay(2000); + + SDL_Event event; + wait_for_event(event,2000,5000,true); } void savegame(int slot) @@ -1632,7 +1638,6 @@ if(level_load(¤t_level,level_subset,level) != 0) exit(1); arrays_free(); - arrays_init(); activate_bad_guys(); activate_particle_systems(); level_free_gfx(); Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- menu.cpp 28 Mar 2004 21:42:04 -0000 1.21 +++ menu.cpp 29 Mar 2004 13:24:42 -0000 1.22 @@ -129,6 +129,7 @@ { pos_x = screen->w/2; pos_y = screen->h/2; + last_menu = 0; arrange_left = 0; num_items = 0; active_item = 0; Index: globals.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/globals.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- globals.cpp 28 Mar 2004 01:00:16 -0000 1.7 +++ globals.cpp 29 Mar 2004 13:24:41 -0000 1.8 @@ -21,12 +21,12 @@ MouseCursor * mouse_cursor; bool use_gl; -bool use_joystick; +bool use_joystick; bool use_fullscreen; bool debug_mode; bool show_fps; -int joystick_num = 0; +int joystick_num = 0; char* level_startup_file = 0; bool launch_worldmap_mode = false; @@ -35,4 +35,59 @@ SDL_Joystick * js; +/* Returns 1 for every button event, 2 for a quit event and 0 for no event. */ +int wait_for_event(SDL_Event& event,unsigned int min_delay, unsigned int max_delay, bool empty_events) +{ + int i; + timer_type maxdelay; + timer_type mindelay; + timer_init(&maxdelay,false); + timer_init(&mindelay,false); + + if(max_delay < min_delay) + max_delay = min_delay; + + timer_start(&maxdelay,max_delay); + timer_start(&mindelay,min_delay); + + if(empty_events) + while (SDL_PollEvent(&event)) + {} + /* Handle events: */ + + for(i = 0; timer_check(&maxdelay) || !i; ++i) + { + while (SDL_PollEvent(&event)) + { + if(!timer_check(&mindelay)) + { + if (event.type == SDL_QUIT) + { + /* Quit event - quit: */ + return 2; + } + else if (event.type == SDL_KEYDOWN) + { + /* Keypress - skip intro: */ + + return 1; + } + else if (event.type == SDL_JOYBUTTONDOWN) + { + /* Fire button - skip intro: */ + + return 1; + } + else if (event.type == SDL_MOUSEBUTTONDOWN) + { + /* Mouse button - skip intro: */ + return 1; + } + } + } + SDL_Delay(10); + } + + return 0; +} Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- leveleditor.cpp 28 Mar 2004 21:42:04 -0000 1.25 +++ leveleditor.cpp 29 Mar 2004 13:24:41 -0000 1.26 @@ -240,7 +240,7 @@ le_level_subset.load(level_subsets.item[i-2]); leveleditor_menu->item[3].kind = MN_GOTO; le_level = 1; - arrays_init(); + arrays_free(); loadshared(); le_current_level = new st_level; if(level_load(le_current_level, le_level_subset.name.c_str(), le_level) != 0) @@ -271,7 +271,7 @@ le_level_subset.load(subset_new_menu->item[2].input); leveleditor_menu->item[3].kind = MN_GOTO; le_level = 1; - arrays_init(); + arrays_free(); loadshared(); le_current_level = new st_level; if(level_load(le_current_level, le_level_subset.name.c_str(), le_level) != 0) @@ -578,7 +578,6 @@ void le_goto_level(int levelnb) { arrays_free(); - arrays_init(); level_free(le_current_level); if(level_load(le_current_level, le_level_subset.name.c_str(), levelnb) != 0) @@ -1237,7 +1236,7 @@ level_save(le_current_level,"test",le_level); gameloop("test",le_level, ST_GL_TEST); Menu::set_current(leveleditor_menu); - arrays_init(); + arrays_free(); level_load_gfx(le_current_level); loadshared(); } Index: badguy.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- badguy.h 28 Mar 2004 01:44:15 -0000 1.18 +++ badguy.h 29 Mar 2004 13:24:41 -0000 1.19 @@ -21,6 +21,11 @@ #include "physic.h" #include "collision.h" +extern texture_type img_bsod_left[4]; +extern texture_type img_bsod_right[4]; +extern texture_type img_laptop_left[3]; +extern texture_type img_money_left[2]; + /* Enemy modes: */ enum { NORMAL=0, @@ -28,6 +33,8 @@ KICK, HELD, + MONEY_JUMP, + BOMB_TICKING, BOMB_EXPLODE, @@ -35,26 +42,6 @@ STALACTITE_FALL }; -extern texture_type img_bsod_squished_left; -extern texture_type img_bsod_squished_right; -extern texture_type img_bsod_falling_left; -extern texture_type img_bsod_falling_right; -extern texture_type img_laptop_flat_left; -extern texture_type img_laptop_flat_right; -extern texture_type img_laptop_falling_left; -extern texture_type img_laptop_falling_right; -extern texture_type img_bsod_left[4]; -extern texture_type img_bsod_right[4]; -extern texture_type img_laptop_left[3]; -extern texture_type img_laptop_right[3]; -extern texture_type img_money_left[2]; -extern texture_type img_money_right[2]; -extern texture_type img_mrbomb_left[4]; -extern texture_type img_mrbomb_right[4]; -extern texture_type img_stalactite; -extern texture_type img_stalactite_broken; -extern texture_type img_flame[2]; - /* Bad guy kinds: */ enum BadGuyKind { BAD_BSOD, Index: badguy.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- badguy.cpp 28 Mar 2004 21:42:04 -0000 1.17 +++ badguy.cpp 29 Mar 2004 13:24:41 -0000 1.18 @@ -33,6 +33,9 @@ texture_type img_money_right[2]; texture_type img_mrbomb_left[4]; texture_type img_mrbomb_right[4]; +texture_type img_mrbomb_ticking_left; +texture_type img_mrbomb_ticking_right; +texture_type img_mrbomb_explosion; texture_type img_stalactite; texture_type img_stalactite_broken; texture_type img_flame[2]; @@ -88,15 +91,15 @@ void BadGuy::init(float x, float y, BadGuyKind kind_) { + base.x = x; + base.y = y; base.width = 32; base.height = 32; mode = NORMAL; dying = DYING_NOT; kind = kind_; - base.x = x; - base.y = y; base.xm = -1.3; - base.ym = 4.8; + base.ym = 0; old_base = base; dir = LEFT; seen = false; @@ -110,6 +113,8 @@ dying = DYING_SQUISHED; } else if(kind == BAD_FLAME) { base.ym = 0; // we misuse base.ym as angle for the flame + } else if(kind == BAD_MONEY) { + base.ym = 4.8; } } @@ -118,14 +123,13 @@ /* --- BLUE SCREEN OF DEATH MONSTER: --- */ /* Move left/right: */ - if (dying == DYING_NOT || - dying == DYING_FALLING) + if (dying == DYING_NOT || dying == DYING_FALLING) { base.x += base.xm * frame_ratio; } /* Move vertically: */ - base.y = base.y + base.ym * frame_ratio; + base.y += base.ym * frame_ratio; if (dying != DYING_FALLING) collision_swept_object_map(&old_base,&base); @@ -136,13 +140,11 @@ fall(true); // Handle dying timer: - if (dying == DYING_SQUISHED) + if (dying == DYING_SQUISHED && !timer_check(&timer)) { /* Remove it if time's up: */ - if(!timer_check(&timer)) { - remove_me(); - return; - } + remove_me(); + return; } } @@ -219,18 +221,14 @@ fall(); /* Handle mode timer: */ - if (mode == FLAT && mode != HELD) + if (mode == FLAT) { if(!timer_check(&timer)) { mode = NORMAL; - base.xm = 4; + base.xm = (dir == LEFT) ? -1.3 : 1.3; } } - else if (mode == KICK) - { - timer_check(&timer); - } } void BadGuy::check_horizontal_bump(bool checkcliff) @@ -251,6 +249,8 @@ // don't check for cliffs when we're falling if(!checkcliff) return; + if(!issolid(base.x + base.width/2, base.y + base.height + 16)) + return; if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + 16)) { @@ -274,7 +274,7 @@ /* Fall if we get off the ground: */ if (dying != DYING_FALLING) { - if (!issolid(base.x+16, base.y + 32)) + if (!issolid(base.x+base.width/2, base.y + base.height)) { if(!physic_is_set(&physic)) { @@ -282,18 +282,14 @@ physic_set_start_vy(&physic, dojump ? 2. : 0.); } - if(mode != HELD) - { - base.ym = physic_get_velocity(&physic); - } + base.ym = physic_get_velocity(&physic); } else { /* Land: */ - if (base.ym > 0) { - base.y = (int)(base.y / 32) * 32; + base.y = int((base.y + base.height)/32) * 32 - base.height; base.ym = 0; } physic_init(&physic); @@ -354,18 +350,12 @@ physic_set_state(&physic,PH_VT); physic_set_start_vy(&physic,6.); base.ym = physic_get_velocity(&physic); + mode = MONEY_JUMP; } - /* // matze: is this code needed? - else if(issolid(base.x, base.y)) - { // This works, but isn't the best solution imagineable - physic_set_state(&physic,PH_VT); - physic_set_start_vy(&physic,0.); - base.ym = physic_get_velocity(&physic); - ++base.y; - }*/ else { base.ym = physic_get_velocity(&physic); + mode = NORMAL; } } else @@ -407,6 +397,12 @@ mode = BOMB_EXPLODE; dying = DYING_NOT; // now the bomb hurts timer_start(&timer, 1000); + // explosion image has different size + base.x -= (img_mrbomb_explosion.w - base.width) / 2; + base.y -= img_mrbomb_explosion.h - base.height; + base.width = img_mrbomb_explosion.w; + base.height = img_mrbomb_explosion.h; + old_base = base; } else if(mode == BOMB_EXPLODE) { remove_me(); return; @@ -417,7 +413,11 @@ void BadGuy::action_stalactite() { if(mode == NORMAL) { - if(tux.base.x + 32 > base.x - 40 && tux.base.x < base.x + 32 + 40) { + static const int range = 40; + // start shaking when tux is below the stalactite and at least 40 pixels + // near + if(tux.base.x + 32 > base.x - range && tux.base.x < base.x + 32 + range + && tux.base.y + tux.base.height > base.y) { timer_start(&timer, 800); mode = STALACTITE_SHAKING; } @@ -427,7 +427,8 @@ mode = STALACTITE_FALL; } } else if(mode == STALACTITE_FALL) { - base.y += base.ym * frame_ratio; + base.y += base.ym * frame_ratio; + fall(); /* Destroy if collides land */ if(issolid(base.x+16, base.y+32)) { @@ -435,6 +436,10 @@ dying = DYING_SQUISHED; mode = FLAT; } + } else if(mode == FLAT) { + if(!timer_check(&timer)) { + remove_me(); + } } } @@ -451,52 +456,50 @@ void BadGuy::action() -{ - if (seen) - { - switch (kind) - { - case BAD_BSOD: - action_bsod(); - break; - - case BAD_LAPTOP: - action_laptop(); - break; - - case BAD_MONEY: - action_money(); - break; - - case BAD_MRBOMB: - action_mrbomb(); - break; - - case BAD_BOMB: - action_bomb(); - break; - - case BAD_STALACTITE: - action_stalactite(); - break; - - case BAD_FLAME: - action_flame(); - break; - } - } - +{ // Remove if it's far off the screen: if (base.x < scroll_x - OFFSCREEN_DISTANCE) { - remove_me(); + remove_me(); return; } - else /* !seen */ + + // Once it's on screen, it's activated! + if (base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE) + seen = true; + + if(!seen) + return; + + switch (kind) { - // Once it's on screen, it's activated! - if (base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE) - seen = true; + case BAD_BSOD: + action_bsod(); + break; + + case BAD_LAPTOP: + action_laptop(); + break; + + case BAD_MONEY: + action_money(); + break; + + case BAD_MRBOMB: + action_mrbomb(); + break; + + case BAD_BOMB: + action_bomb(); + break; + + case BAD_STALACTITE: + action_stalactite(); + break; + + case BAD_FLAME: + action_flame(); + break; } } @@ -504,7 +507,7 @@ BadGuy::draw_bsod() { texture_type* texture = 0; - float y = base.y; + if(dying == DYING_NOT) { size_t frame = (global_frame_counter / 5) % 4; texture = (dir == LEFT) ? &img_bsod_left[frame] : &img_bsod_right[frame]; @@ -513,10 +516,9 @@ } else if(dying == DYING_SQUISHED) { texture = (dir == LEFT) ? &img_bsod_squished_left : &img_bsod_squished_right; - y += 24; } - texture_draw(texture, base.x - scroll_x, y); + texture_draw(texture, base.x - scroll_x, base.y); } void @@ -546,7 +548,7 @@ BadGuy::draw_money() { texture_type* texture; - size_t frame = (base.ym != 300) ? 0 : 1; + size_t frame = (mode == NORMAL) ? 0 : 1; if(tux.base.x + tux.base.width < base.x) { texture = &img_money_left[frame]; @@ -575,12 +577,13 @@ BadGuy::draw_bomb() { texture_type* texture; - + // TODO add real bomb graphics if(mode == BOMB_TICKING) { - texture = &img_bsod_squished_right; + texture = (dir == LEFT) + ? &img_mrbomb_ticking_left : &img_mrbomb_ticking_right; } else { - texture = &img_bsod_squished_left; + texture = &img_mrbomb_explosion; } texture_draw(texture, base.x - scroll_x, base.y); @@ -611,40 +614,39 @@ BadGuy::draw() { // Don't try to draw stuff that is outside of the screen - if (base.x > scroll_x - 32 && - base.x < scroll_x + screen->w) + if (base.x <= scroll_x - base.width || base.x >= scroll_x + screen->w) + return; + + switch (kind) { - switch (kind) - { - case BAD_BSOD: - draw_bsod(); - break; - - case BAD_LAPTOP: - draw_laptop(); - break; - - case BAD_MONEY: - draw_money(); - break; + case BAD_BSOD: + draw_bsod(); + break; - case BAD_MRBOMB: - draw_mrbomb(); - break; + case BAD_LAPTOP: + draw_laptop(); + break; - case BAD_BOMB: - draw_bomb(); - break; + case BAD_MONEY: + draw_money(); + break; - case BAD_STALACTITE: - draw_stalactite(); - break; + case BAD_MRBOMB: + draw_mrbomb(); + break; - case BAD_FLAME: - draw_flame(); - break; + case BAD_BOMB: + draw_bomb(); + break; + + case BAD_STALACTITE: + draw_stalactite(); + break; + + case BAD_FLAME: + draw_flame(); + break; - } } } @@ -662,8 +664,8 @@ BadGuy::make_player_jump(Player* player) { physic_set_state(&player->vphysic,PH_VT); - physic_set_start_vy(&player->vphysic,2.); - player->base.y = base.y - player->base.height - 1; + physic_set_start_vy(&player->vphysic, 2.); + player->base.y = base.y - player->base.height - 2; } void @@ -682,14 +684,18 @@ return; } else if(kind == BAD_BSOD) { - dying = DYING_SQUISHED; - timer_start(&timer,4000); - make_player_jump(player); add_score(base.x - scroll_x, base.y, 50 * score_multiplier); play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER); score_multiplier++; + + dying = DYING_SQUISHED; + timer_start(&timer, 2000); + base.y += base.height - img_bsod_squished_left.h; + base.height = img_bsod_squished_left.h; + base.xm = base.ym = 0; + old_base = base; return; } else if (kind == BAD_LAPTOP) { @@ -698,29 +704,27 @@ /* Flatten! */ play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER); mode = FLAT; - base.xm = 4; + base.xm = 0; timer_start(&timer, 4000); } else if (mode == FLAT) { /* Kick! */ play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER); - if (player->base.x < base.x + (base.width/2)) + if (player->base.x < base.x + (base.width/2)) { + base.xm = 5; dir = RIGHT; - else + } else { + base.xm = -5; dir = LEFT; + } - base.xm = 5; mode = KICK; - - timer_start(&timer,5000); } make_player_jump(player); - add_score(base.x - scroll_x, - base.y, - 25 * score_multiplier); + add_score(base.x - scroll_x, base.y, 25 * score_multiplier); score_multiplier++; return; } @@ -767,11 +771,7 @@ case CO_BADGUY: pbad_c = (BadGuy*) p_c_object; - if (mode == NORMAL) - { - /* do nothing */ - } - else if(mode == KICK) + if(kind == BAD_LAPTOP && mode == KICK) { /* We're in kick mode, kill the other guy and yourself(wuahaha) : */ @@ -782,7 +782,6 @@ add_score(base.x - scroll_x, base.y, 100); - pbad_c->dying = DYING_FALLING; dying = DYING_FALLING; base.ym = -8; @@ -918,6 +917,12 @@ texture_load(&img_mrbomb_right[i], datadir + "/images/shared/mrbomb-right-" + num + ".png", USE_ALPHA); } + texture_load(&img_mrbomb_ticking_left, + datadir + "/images/shared/mrbombx-left-0.png", USE_ALPHA); + texture_load(&img_mrbomb_ticking_right, + datadir + "/images/shared/mrbombx-right-0.png", USE_ALPHA); + texture_load(&img_mrbomb_explosion, + datadir + "/images/shared/mrbomb-explosion.png", USE_ALPHA); /* stalactite */ texture_load(&img_stalactite, @@ -969,6 +974,10 @@ texture_free(&img_mrbomb_right[i]); } + texture_free(&img_mrbomb_ticking_left); + texture_free(&img_mrbomb_ticking_right); + texture_free(&img_mrbomb_explosion); + texture_free(&img_stalactite); texture_free(&img_stalactite_broken); |