From 09473c383d4fe5c5e2634e64cc857cf39f0130bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Mon, 29 Mar 2004 13:24:42 +0000 Subject: [PATCH] - introduced new function wait_for_event - removed arrays_init() - applied fixes from Matze Braun for badguy bugs SVN-Revision: 413 --- src/badguy.cpp | 267 +++++++++++++++++----------------- src/badguy.h | 27 +--- src/gameloop.cpp | 19 ++- src/globals.cpp | 59 +++++++- src/globals.h | 2 + src/intro.cpp | 408 +++++++++++++++++++++++++--------------------------- src/leveleditor.cpp | 7 +- src/menu.cpp | 1 + src/scene.cpp | 4 - src/scene.h | 1 - src/special.cpp | 13 +- 11 files changed, 425 insertions(+), 383 deletions(-) diff --git a/src/badguy.cpp b/src/badguy.cpp index 852313bee..ce393bf56 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -33,6 +33,9 @@ texture_type img_money_left[2]; 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 @@ std::string badguykind_to_string(BadGuyKind kind) 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 @@ BadGuy::init(float x, float y, BadGuyKind kind_) 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 @@ void BadGuy::action_bsod() /* --- 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 @@ void BadGuy::action_bsod() 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 @@ void BadGuy::action_laptop() 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 @@ void BadGuy::check_horizontal_bump(bool checkcliff) // 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 @@ void BadGuy::fall(bool dojump) /* 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 @@ void BadGuy::fall(bool dojump) 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 @@ void BadGuy::action_money() 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 @@ void BadGuy::action_bomb() 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_bomb() 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 @@ void BadGuy::action_stalactite() 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 @@ void BadGuy::action_stalactite() dying = DYING_SQUISHED; mode = FLAT; } + } else if(mode == FLAT) { + if(!timer_check(&timer)) { + remove_me(); + } } } @@ -451,52 +456,50 @@ BadGuy::action_flame() 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 @@ void 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 @@ BadGuy::draw_bsod() } 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 @@ void 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 @@ void 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 @@ void 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_LAPTOP: + draw_laptop(); + break; - case BAD_MRBOMB: - draw_mrbomb(); - break; + case BAD_MONEY: + draw_money(); + break; - case BAD_BOMB: - draw_bomb(); - break; + case BAD_MRBOMB: + draw_mrbomb(); + break; - case BAD_STALACTITE: - draw_stalactite(); - break; + case BAD_BOMB: + draw_bomb(); + break; - case BAD_FLAME: - draw_flame(); - break; + case BAD_STALACTITE: + draw_stalactite(); + break; + + case BAD_FLAME: + draw_flame(); + break; - } } } @@ -662,8 +664,8 @@ void 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 @@ BadGuy::squich(Player* player) 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 @@ BadGuy::squich(Player* player) /* 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 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type) 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 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type) add_score(base.x - scroll_x, base.y, 100); - pbad_c->dying = DYING_FALLING; dying = DYING_FALLING; base.ym = -8; @@ -918,6 +917,12 @@ void load_badguy_gfx() 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 @@ void free_badguy_gfx() 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); diff --git a/src/badguy.h b/src/badguy.h index 6d2fb5c51..71cf4d19f 100644 --- a/src/badguy.h +++ b/src/badguy.h @@ -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 @@ enum { KICK, HELD, + MONEY_JUMP, + BOMB_TICKING, BOMB_EXPLODE, @@ -35,26 +42,6 @@ enum { 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, diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 3c298faa7..751261021 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -87,7 +87,8 @@ void levelintro(void) flipscreen(); - SDL_Delay(1000); + SDL_Event event; + wait_for_event(event,1000,3000,true); } /* Reset Timers */ @@ -370,7 +371,6 @@ int game_action(void) } arrays_free(); - arrays_init(); activate_bad_guys(); activate_particle_systems(); level_free_gfx(); @@ -594,7 +594,7 @@ int gameloop(const char * subset, int levelnb, int mode) level = levelnb; /* Init the game: */ - arrays_init(); + arrays_free(); set_defaults(); strcpy(level_subset,subset); @@ -761,8 +761,10 @@ int gameloop(const char * subset, int levelnb, int mode) /* 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 @@ void drawendscreen(void) 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 @@ void drawresultscreen(void) 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 @@ void loadgame(int slot) if(level_load(¤t_level,level_subset,level) != 0) exit(1); arrays_free(); - arrays_init(); activate_bad_guys(); activate_particle_systems(); level_free_gfx(); diff --git a/src/globals.cpp b/src/globals.cpp index 383028577..fc4bc6198 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -21,12 +21,12 @@ text_type black_text, gold_text, blue_text, red_text, yellow_nums, white_text, w 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 @@ char *st_dir, *st_save_dir; 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; +} diff --git a/src/globals.h b/src/globals.h index 3c52a2c3b..f31c6b2a4 100644 --- a/src/globals.h +++ b/src/globals.h @@ -44,6 +44,8 @@ extern char* st_save_dir; 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 */ diff --git a/src/intro.cpp b/src/intro.cpp index 151723333..ae532fba5 100644 --- a/src/intro.cpp +++ b/src/intro.cpp @@ -2,7 +2,7 @@ intro.c Super Tux - Intro Screen - + by Bill Kendrick bill@newbreedsoftware.com 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 @@ int intro(void) { 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 @@ int intro(void) 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); - - update_rect(screen, 0, 32, screen->w, (copter[0].h)); - } - - + { + /* 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)); + } + + 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; - } - - update_rect(screen, - 310, - 32 + (copter[0].h), - (gown_upset.w) + 20, - 400 + (gown_upset.h) - (copter[0].h)); - } - - + { + /* 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)); + } + + 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: */ + + texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_squish.h)); - update_rect(screen, 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 @@ int intro(void) texture_free(&copter_squish); texture_free(&copter_stretch); texture_free(&beam); - - + + /* Free array buffers: */ - + free(height); free(height_speed); - - + + /* Return to main! */ - + return(quit); } diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index d7ddc42d4..12a1ff416 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -240,7 +240,7 @@ int leveleditor(int levelnb) 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 @@ int leveleditor(int levelnb) 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 save_subset_settings_menu() 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 @@ void le_testlevel() 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(); } diff --git a/src/menu.cpp b/src/menu.cpp index f4aff4a07..c338f49e7 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -129,6 +129,7 @@ Menu::Menu() { pos_x = screen->w/2; pos_y = screen->h/2; + last_menu = 0; arrange_left = 0; num_items = 0; active_item = 0; diff --git a/src/scene.cpp b/src/scene.cpp index 390c98344..3fab8693b 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -45,10 +45,6 @@ texture_type img_red_glow; timer_type time_left; double frame_ratio; -void arrays_init(void) -{ -} - void arrays_free(void) { bad_guys.clear(); diff --git a/src/scene.h b/src/scene.h index 4be33a160..06a8bdfe4 100644 --- a/src/scene.h +++ b/src/scene.h @@ -53,7 +53,6 @@ extern double frame_ratio; 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); diff --git a/src/special.cpp b/src/special.cpp index 69fc09324..92abb31be 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -89,10 +89,15 @@ void bullet_draw(bullet_type* pbullet) void bullet_collision(bullet_type* pbullet, int c_object) { - - if(c_object == CO_BADGUY) - bullets.erase(static_cast::iterator>(pbullet)); - + if(c_object == CO_BADGUY) { + std::vector::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) -- 2.11.0