From: Tobias Gläßer Date: Sat, 13 Mar 2004 23:45:12 +0000 (+0000) Subject: fixed player/badguy collisions and score multiplication X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=482a326a798f376647a1c5de03be513fdc714609;p=supertux.git fixed player/badguy collisions and score multiplication SVN-Revision: 207 --- diff --git a/src/badguy.c b/src/badguy.c index 5cc1f163b..fddd97f60 100644 --- a/src/badguy.c +++ b/src/badguy.c @@ -77,7 +77,7 @@ void badguy_action(bad_guy_type* pbad) pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio; if (pbad->dying != FALLING) - collision_swept_object_map(&pbad->old_base,&pbad->base); + collision_swept_object_map(&pbad->old_base,&pbad->base); if (pbad->base.y > screen->h) pbad->base.alive = NO; @@ -154,7 +154,7 @@ void badguy_action(bad_guy_type* pbad) else if (pbad->mode == HELD) { /* FIXME: The pbad object shouldn't know about pplayer objects. */ /* If we're holding the laptop */ - pbad->dir=tux.dir; + pbad->dir=tux.dir; if(pbad->dir==RIGHT) { pbad->base.x = tux.base.x + 16; @@ -165,19 +165,19 @@ void badguy_action(bad_guy_type* pbad) pbad->base.x = tux.base.x - 16; pbad->base.y = tux.base.y + tux.base.height/1.5 - pbad->base.height; } - if(collision_object_map(&pbad->base)) - { - pbad->base.x = tux.base.x; - pbad->base.y = tux.base.y + tux.base.height/1.5 - pbad->base.height; - } + if(collision_object_map(&pbad->base)) + { + pbad->base.x = tux.base.x; + pbad->base.y = tux.base.y + tux.base.height/1.5 - pbad->base.height; + } if(tux.input.fire != DOWN) /* SHOOT! */ { - if(pbad->dir = LEFT) - pbad->base.x -= 24; - else - pbad->base.x += 24; - + if(pbad->dir = LEFT) + pbad->base.x -= 24; + else + pbad->base.x += 24; + pbad->mode=KICK; pbad->base.ym-=8; play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER); @@ -189,9 +189,9 @@ void badguy_action(bad_guy_type* pbad) if(pbad->mode != HELD) pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio; - + if (pbad->dying != FALLING) - collision_swept_object_map(&pbad->old_base,&pbad->base); + collision_swept_object_map(&pbad->old_base,&pbad->base); if (pbad->base.y > screen->h) pbad->base.alive = NO; /* Bump into things horizontally: */ @@ -273,9 +273,9 @@ void badguy_action(bad_guy_type* pbad) /* Move vertically: */ pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio; - + if (pbad->dying != FALLING) - collision_swept_object_map(&pbad->old_base,&pbad->base); + collision_swept_object_map(&pbad->old_base,&pbad->base); if (pbad->base.y > screen->h) pbad->base.alive = NO; @@ -299,7 +299,7 @@ void badguy_action(bad_guy_type* pbad) physic_set_state(&pbad->physic,PH_VT); physic_set_start_vy(&pbad->physic,0.); pbad->base.ym = physic_get_velocity(&pbad->physic); - ++pbad->base.y; + ++pbad->base.y; } else { @@ -585,59 +585,63 @@ void badguy_collision(bad_guy_type* pbad, void *p_c_object, int c_object) break; case CO_PLAYER: pplayer_c = (player_type*) p_c_object; - if (pbad->kind == BAD_BSOD) + if(pbad->kind != BAD_MONEY) { - pbad->dying = SQUISHED; - timer_start(&pbad->timer,4000); - physic_set_state(&pplayer_c->vphysic,PH_VT); - physic_set_start_vy(&pplayer_c->vphysic,2.); - - add_score(pbad->base.x - scroll_x, pbad->base.y, - 50 * score_multiplier); - - play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER); - } - else if (pbad->kind == BAD_LAPTOP) - { - - if (pbad->mode != KICK) + if (pbad->kind == BAD_BSOD) { - /* Flatten! */ - - play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER); - pbad->mode = FLAT; - pbad->base.xm = 4; - - timer_start(&pbad->timer,10000); - + pbad->dying = SQUISHED; + timer_start(&pbad->timer,4000); physic_set_state(&pplayer_c->vphysic,PH_VT); physic_set_start_vy(&pplayer_c->vphysic,2.); + + add_score(pbad->base.x - scroll_x, pbad->base.y, + 50 * score_multiplier); + + play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER); } - else + else if (pbad->kind == BAD_LAPTOP) { - /* Kick! */ - play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER); + if (pbad->mode != KICK) + { + /* Flatten! */ + + play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER); + pbad->mode = FLAT; + pbad->base.xm = 4; - if (pplayer_c->base.x <= pbad->base.x) - pbad->dir = RIGHT; + timer_start(&pbad->timer,10000); + + physic_set_state(&pplayer_c->vphysic,PH_VT); + physic_set_start_vy(&pplayer_c->vphysic,2.); + } else - pbad->dir = LEFT; + { + /* Kick! */ - pbad->base.xm = 8; + play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER); - timer_start(&pbad->timer,5000); - } + if (pplayer_c->base.x <= pbad->base.x) + pbad->dir = RIGHT; + else + pbad->dir = LEFT; - physic_set_state(&pplayer_c->vphysic,PH_VT); - physic_set_start_vy(&pplayer_c->vphysic,2.); + pbad->base.xm = 8; - add_score(pbad->base.x - scroll_x, - pbad->base.y, - 25 * score_multiplier); + timer_start(&pbad->timer,5000); + } - /* play_sound(sounds[SND_SQUISH]); */ - } + physic_set_state(&pplayer_c->vphysic,PH_VT); + physic_set_start_vy(&pplayer_c->vphysic,2.); + + add_score(pbad->base.x - scroll_x, + pbad->base.y, + 25 * score_multiplier); + + /* play_sound(sounds[SND_SQUISH]); */ + } + score_multiplier++; + } break; } diff --git a/src/collision.c b/src/collision.c index 78cbc3eff..e3c044999 100644 --- a/src/collision.c +++ b/src/collision.c @@ -242,11 +242,11 @@ void collision_handler() /* CO_BADGUY & CO_BADGUY check */ for(i = 0; i < num_bad_guys; ++i) { - if(bad_guys[i].base.alive) + if(bad_guys[i].base.alive && bad_guys[i].dying == NO) { for(j = i+1; j < num_bad_guys; ++j) { - if(j != i && bad_guys[j].base.alive) + if(j != i && bad_guys[j].base.alive && bad_guys[j].dying == NO) { if(rectcollision(&bad_guys[i].base,&bad_guys[j].base) == YES) { diff --git a/src/gameloop.c b/src/gameloop.c index b580f00a3..d24da2926 100644 --- a/src/gameloop.c +++ b/src/gameloop.c @@ -1748,12 +1748,10 @@ void savegame(int slot) fwrite(&scroll_x,sizeof(float),1,fi); fwrite(&tux,sizeof(player_type),1,fi); timer_fwrite(&tux.invincible_timer,fi); - printf("Time inv LEFT: %d\n",timer_get_left(&tux.invincible_timer)); timer_fwrite(&tux.skidding_timer,fi); timer_fwrite(&tux.safe_timer,fi); timer_fwrite(&tux.frame_timer,fi); timer_fwrite(&time_left,fi); - printf("Time LEFT: %d\n",timer_get_left(&time_left)); ui = st_get_ticks(); fwrite(&ui,sizeof(int),1,fi); } @@ -1805,12 +1803,10 @@ void loadgame(int slot) fread(&scroll_x,sizeof(float),1,fi); fread(&tux,sizeof(player_type),1,fi); timer_fread(&tux.invincible_timer,fi); - printf("Time inv LEFT: %d - %d\n",timer_get_left(&tux.invincible_timer),tux.invincible_timer.time); timer_fread(&tux.skidding_timer,fi); timer_fread(&tux.safe_timer,fi); timer_fread(&tux.frame_timer,fi); timer_fread(&time_left,fi); - printf("Time LEFT: %d\n",timer_get_left(&time_left)); fread(&ui,sizeof(int),1,fi); tux.hphysic.start_time += st_get_ticks() - ui; tux.vphysic.start_time += st_get_ticks() - ui; diff --git a/src/player.c b/src/player.c index 507837d80..add399eff 100644 --- a/src/player.c +++ b/src/player.c @@ -186,9 +186,12 @@ void player_action(player_type* pplayer) } physic_init(&pplayer->vphysic); - } + /* Reset score multiplier (for multi-hits): */ + score_multiplier = 1; + } + if(jumped_in_solid == YES) { @@ -276,11 +279,6 @@ void player_action(player_type* pplayer) } } - /* Reset score multiplier (for multi-hits): */ - - if (pplayer->base.ym > 2) - score_multiplier = 1; - } timer_check(&pplayer->safe_timer); @@ -900,9 +898,10 @@ void player_collision(player_type* pplayer, void* p_c_object, int c_object) else { pbad_c->dying = FALLING; - physic_set_state(&pplayer->vphysic,PH_VT); - physic_set_start_vy(&pplayer->vphysic,-2.); play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); + add_score(pbad_c->base.x - scroll_x, + pbad_c->base.y, + 25 * score_multiplier); } } } @@ -916,9 +915,10 @@ void player_collision(player_type* pplayer, void* p_c_object, int c_object) else { pbad_c->dying = FALLING; - physic_set_state(&pplayer->vphysic,PH_VT); - physic_set_start_vy(&pplayer->vphysic,-2.); play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); + add_score(pbad_c->base.x - scroll_x, + pbad_c->base.y, + 25 * score_multiplier); } } score_multiplier++;