void BadGuy::bump() { // these can't be bumped if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH || kind == BAD_FLYINGSNOWBALL) return; physic.set_velocity_y(3); kill_me(25); }
void BadGuy::collision(void *p_c_object, int c_object, CollisionType type) { BadGuy* pbad_c = NULL; if(type == COLLISION_BUMP) { bump(); return; } if(type == COLLISION_SQUISH) { Player* player = static_cast<Player*>(p_c_object); squish(player); return; } /* COLLISION_NORMAL */ switch (c_object) { case CO_BULLET: kill_me(10); break; case CO_BADGUY: pbad_c = (BadGuy*) p_c_object; /* If we're a kicked mriceblock, kill any badguys we hit */ if(kind == BAD_MRICEBLOCK && mode == KICK) { pbad_c->kill_me(25); } // a held mriceblock gets kills the enemy too but falls to ground then else if(kind == BAD_MRICEBLOCK && mode == HELD) { pbad_c->kill_me(25); kill_me(0); } /* Kill badguys that run into exploding bomb */ else if (kind == BAD_BOMB && dying == DYING_NOT) { if (pbad_c->kind == BAD_MRBOMB) { // mrbomb transforms into a bomb now explode(pbad_c); return; } else if (pbad_c->kind != BAD_MRBOMB) { pbad_c->kill_me(50); } } /* Kill any badguys that get hit by stalactite */ else if (kind == BAD_STALACTITE && dying == DYING_NOT) { if (pbad_c->kind == BAD_MRBOMB) { // mrbomb transforms into a bomb now explode(pbad_c); return; } else pbad_c->kill_me(50); } /* When enemies run into eachother, make them change directions */ else { // Jumpy, fish, flame, stalactites are exceptions if (pbad_c->kind == BAD_JUMPY || pbad_c->kind == BAD_FLAME || pbad_c->kind == BAD_STALACTITE || pbad_c->kind == BAD_FISH) break; // Bounce off of other badguy if we land on top of him if (base.y + base.height < pbad_c->base.y + pbad_c->base.height) { if (pbad_c->dir == LEFT) { dir = RIGHT; physic.set_velocity(fabsf(physic.get_velocity_x()), 2); } else if (pbad_c->dir == RIGHT) { dir = LEFT; physic.set_velocity(-fabsf(physic.get_velocity_x()), 2); } break; } else if (base.y + base.height > pbad_c->base.y + pbad_c->base.height) break; if (pbad_c->kind != BAD_FLAME) { if (dir == LEFT) { dir = RIGHT; physic.set_velocity_x(fabsf(physic.get_velocity_x())); } else if (dir == RIGHT) { dir = LEFT; physic.set_velocity_x(-fabsf(physic.get_velocity_x())); } } } break; case CO_PLAYER: Player* player = static_cast<Player*>(p_c_object); /* Get kicked if were flat */ if (mode == FLAT && !dying) { play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER); // Hit from left side if (player->base.x < base.x) { physic.set_velocity_x(5); dir = RIGHT; } // Hit from right side else { physic.set_velocity_x(-5); dir = LEFT; } mode = KICK; player->kick_timer.start(KICKING_TIME); set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right); } break; } }
void BadGuy::squish(Player* player) { static const int MAX_ICEBLOCK_SQUICHES = 10; if(kind == BAD_MRBOMB) { // mrbomb transforms into a bomb now World::current()->add_bad_guy(base.x, base.y, BAD_BOMB); make_player_jump(player); World::current()->add_score(base.x - scroll_x, base.y, 50 * player_status.score_multiplier); play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER); player_status.score_multiplier++; remove_me(); return; } else if (kind == BAD_MRICEBLOCK) { if (mode == NORMAL || mode == KICK) { /* Flatten! */ play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER); mode = FLAT; set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right); physic.set_velocity_x(0); timer.start(4000); } else if (mode == FLAT) { /* Kick! */ play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER); if (player->base.x < base.x + (base.width/2)) { physic.set_velocity_x(5); dir = RIGHT; } else { physic.set_velocity_x(-5); dir = LEFT; } mode = KICK; player->kick_timer.start(KICKING_TIME); set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right); } make_player_jump(player); player_status.score_multiplier++; // check for maximum number of squiches squishcount++; if(squishcount >= MAX_ICEBLOCK_SQUICHES) { kill_me(50); return; } return; } else if(kind == BAD_FISH) { // fish can only be killed when falling down if(physic.get_velocity_y() >= 0) return; make_player_jump(player); World::current()->add_score(base.x - scroll_x, base.y, 25 * player_status.score_multiplier); player_status.score_multiplier++; // simply remove the fish... remove_me(); return; } else if(kind == BAD_BOUNCINGSNOWBALL) { squish_me(player); set_sprite(img_bouncingsnowball_squished,img_bouncingsnowball_squished); return; } else if(kind == BAD_FLYINGSNOWBALL) { squish_me(player); set_sprite(img_flyingsnowball_squished,img_flyingsnowball_squished); return; } else if(kind == BAD_SNOWBALL) { squish_me(player); set_sprite(img_snowball_squished_left, img_snowball_squished_right); return; } }
void invalid_format(void) { kill_me("Invalid format"); }