+// $Id$
+//
+// SuperTux
+// Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
+// Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
+// Copyright (C) 2004 Matthias Braun <matze@braunis.de>
//
-// C Implementation: badguy
-//
-// Description:
-//
-//
-// Author: Tobias Glaesser <tobi.web@gmx.de> & Bill Kendrick, (C) 2004
-//
-// Copyright: See COPYING file that comes with this distribution
-//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
#include <iostream>
#include <math.h>
}
void
-BadGuy::init(float x, float y, BadGuyKind kind_)
+BadGuy::init(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
{
base.x = x;
base.y = y;
base.xm = 0;
base.ym = 0;
+ stay_on_platform = stay_on_platform_;
mode = NORMAL;
dying = DYING_NOT;
kind = kind_;
physic.set_velocity(-1.3, 0);
set_sprite(img_mrbomb_left, img_mrbomb_right, 4);
} else if (kind == BAD_LAPTOP) {
- physic.set_velocity(-1.3, 0);
+ physic.set_velocity(-.8, 0);
set_sprite(img_laptop_left, img_laptop_right, 4, 5);
} else if(kind == BAD_MONEY) {
set_sprite(img_jumpy_left_up, img_jumpy_left_up, 1);
// jump when we're about to fall
if (physic.get_velocity_y() == 0 &&
- !issolid(base.x+base.width/2, base.y + base.height)) {
- physic.enable_gravity(true);
- physic.set_velocity(physic.get_velocity_x(), BSODJUMP);
- }
+ !issolid(base.x+base.width/2, base.y + base.height))
+ {
+ physic.enable_gravity(true);
+ physic.set_velocity(physic.get_velocity_x(), BSODJUMP);
+ }
// Handle dying timer:
if (dying == DYING_SQUISHED && !timer.check())
mode=KICK;
set_sprite(img_laptop_flat_left, img_laptop_flat_right, 1);
- physic.set_velocity((dir == LEFT) ? -8 : 8, -8);
+ physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
}
}
{
mode = NORMAL;
set_sprite(img_laptop_left, img_laptop_right, 4, 5);
- physic.set_velocity( (dir == LEFT) ? -1.3 : 1.3, 0);
+ physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
}
}
}
if (physic.get_velocity_y() < 0)
{
base.y = int((base.y + base.height)/32) * 32 - base.height;
- physic.set_velocity(physic.get_velocity_x(), 0);
+ physic.set_velocity_y(0);
}
// no gravity anymore please
physic.enable_gravity(false);
+
+ if (stay_on_platform && mode == NORMAL)
+ {
+ if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
+ base.y + base.height))
+ {
+ physic.set_velocity_x(-physic.get_velocity_x());
+ if (dir == LEFT)
+ dir = RIGHT;
+ else
+ dir = LEFT;
+ }
+ }
}
}
else
// jump when on ground
if(dying == DYING_NOT && issolid(base.x, base.y+32))
{
- physic.set_velocity(physic.get_velocity_x(), JUMPV);
+ physic.set_velocity_y(JUMPV);
physic.enable_gravity(true);
mode = MONEY_JUMP;
// jump when on ground
if(dying == DYING_NOT && issolid(base.x, base.y+32))
{
- physic.set_velocity(physic.get_velocity_x(), JUMPV);
+ physic.set_velocity_y(JUMPV);
physic.enable_gravity(true);
}
else
// go into flyup mode if none specified yet
if(dying == DYING_NOT && mode == NORMAL) {
mode = FLY_UP;
- physic.set_velocity(physic.get_velocity_x(), FLYINGSPEED);
+ physic.set_velocity_y(FLYINGSPEED);
timer.start(DIRCHANGETIME/2);
}
if(dying == DYING_NOT && !timer.check()) {
if(mode == FLY_UP) {
mode = FLY_DOWN;
- physic.set_velocity(physic.get_velocity_x(), -FLYINGSPEED);
+ physic.set_velocity_y(-FLYINGSPEED);
} else if(mode == FLY_DOWN) {
mode = FLY_UP;
- physic.set_velocity(physic.get_velocity_x(), FLYINGSPEED);
+ physic.set_velocity_y(FLYINGSPEED);
}
timer.start(DIRCHANGETIME);
}
if (physic.get_velocity_y() == 0 &&
!issolid(base.x+base.width/2, base.y + base.height)) {
physic.enable_gravity(true);
- physic.set_velocity(physic.get_velocity_x(), 2);
+ physic.set_velocity_y(2);
}
#endif
void
BadGuy::make_player_jump(Player* player)
{
- player->physic.set_velocity(player->physic.get_velocity_x(), 2);
+ player->physic.set_velocity_y(2);
player->base.y = base.y - player->base.height - 2;
}
} else if(kind == BAD_BSOD) {
squish_me(player);
set_sprite(img_bsod_squished_left, img_bsod_squished_right, 1);
- physic.set_velocity(0, physic.get_velocity_y());
+ physic.set_velocity_x(0);
return;
} else if (kind == BAD_LAPTOP) {
play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
mode = FLAT;
set_sprite(img_laptop_flat_left, img_laptop_flat_right, 1);
- physic.set_velocity(0, physic.get_velocity_y());
+ physic.set_velocity_x(0);
timer.start(4000);
} else if (mode == FLAT) {
play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
if (player->base.x < base.x + (base.width/2)) {
- physic.set_velocity(5, physic.get_velocity_y());
+ physic.set_velocity_x(5);
dir = RIGHT;
} else {
- physic.set_velocity(-5, physic.get_velocity_y());
+ physic.set_velocity_x(-5);
dir = LEFT;
}
set_sprite(img_bsod_falling_left, img_bsod_falling_right, 1);
physic.enable_gravity(true);
- physic.set_velocity(physic.get_velocity_x(), 0);
+ physic.set_velocity_y(0);
/* Gain some points: */
if (kind == BAD_BSOD)
return;
}
+ /* COLLISION_NORMAL */
switch (c_object)
{
case CO_BULLET:
case CO_BADGUY:
pbad_c = (BadGuy*) p_c_object;
+
+ /* If we're a kicked mriceblock, kill any badguys we hit */
if(kind == BAD_LAPTOP && mode == KICK &&
pbad_c->kind != BAD_FLAME && pbad_c->kind != BAD_BOMB)
{
- /* We're in kick mode, kill the other guy
- and yourself(wuahaha) : */
pbad_c->kill_me();
- kill_me();
}
+
+ /* Kill badguys that run into exploding bomb */
+ else if (kind == BAD_BOMB && dying == DYING_NOT)
+ {
+ if (pbad_c->kind == BAD_MRBOMB)
+ {
+ // FIXME: this is where other MrBombs *should* explode istead of dying
+ pbad_c->kill_me();
+ }
+ else if (pbad_c->kind != BAD_BOMB)
+ {
+ pbad_c->kill_me();
+ }
+ }
+
+ /* Kill any badguys that get hit by stalactite */
+ else if (kind == BAD_STALACTITE && dying == DYING_NOT)
+ {
+ pbad_c->kill_me();
+ }
+
+ /* When enemies run into eachother, make them change directions */
+ else
+ {
+ // Jumpy is an exception
+ if (pbad_c->kind == BAD_MONEY)
+ break;
+ if (dir == LEFT)
+ dir = RIGHT;
+ else if (dir == RIGHT)
+ dir = LEFT;
+
+ physic.inverse_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;
+ set_sprite(img_laptop_flat_left, img_laptop_flat_right, 1);
+ }
break;
+
}
}