#include "globals.h"
#include "defines.h"
#include "badguy.h"
-#include "scene.h"
-#include "screen.h"
-#include "world.h"
#include "tile.h"
#include "resources.h"
#include "sprite_manager.h"
-#include "gameloop.h"
-#include "display_manager.h"
-#include "lispwriter.h"
+#include "world.h"
#include "camera.h"
+#include "lispwriter.h"
+#include "level.h"
Sprite* img_mriceblock_flat_left;
Sprite* img_mriceblock_flat_right;
}
}
-BadGuy::BadGuy(DisplayManager& display_manager, BadGuyKind kind_,
- LispReader& lispreader)
+BadGuy::BadGuy(BadGuyKind kind_, LispReader& lispreader)
: removable(false), squishcount(0)
{
- display_manager.add_drawable(this, LAYER_OBJECTS);
-
lispreader.read_float("x", &start_position.x);
lispreader.read_float("y", &start_position.y);
init();
}
-BadGuy::BadGuy(DisplayManager& display_manager, BadGuyKind kind_,
- float x, float y)
+BadGuy::BadGuy(BadGuyKind kind_, float x, float y)
+ : removable(false), squishcount(0)
{
- display_manager.add_drawable(this, LAYER_OBJECTS);
-
start_position.x = x;
start_position.y = y;
stay_on_platform = false;
static const int WAITTIME = 1000;
// go in wait mode when back in water
- if(dying == DYING_NOT && gettile(base.x, base.y+ base.height)->water
- && physic.get_velocity_y() <= 0 && mode == NORMAL)
+ if(dying == DYING_NOT
+ && gettile(base.x, base.y+ base.height)->attributes & Tile::WATER
+ && physic.get_velocity_y() <= 0 && mode == NORMAL)
{
mode = FISH_WAIT;
set_sprite(0, 0);
void
BadGuy::action_walkingtree(double elapsed_time)
{
+ Player& tux = *World::current()->get_tux();
+ Direction v_dir = physic.get_velocity_x() < 0 ? LEFT : RIGHT;
+
if (dying == DYING_NOT)
check_horizontal_bump();
fall();
+ if (mode == BGM_BIG)
+ {
+ if ((tux.base.x + tux.base.width/2 > base.x + base.width/2) && v_dir == LEFT)
+ {
+ dir = RIGHT;
+ physic.set_velocity_x(-physic.get_velocity_x());
+ }
+ else if ((tux.base.x + tux.base.width/2 < base.x + base.width/2) && v_dir == RIGHT)
+ {
+ dir = LEFT;
+ physic.set_velocity_x(-physic.get_velocity_x());
+ }
+ }
+
+
physic.apply(elapsed_time, base.x, base.y);
if (dying != DYING_FALLING)
collision_swept_object_map(&old_base,&base);
remove_me();
}
-
void
BadGuy::action(float elapsed_time)
{
}
void
-BadGuy::draw(Camera& viewport, int)
+BadGuy::draw(DrawingContext& context)
{
- float scroll_x = viewport.get_translation().x;
- float scroll_y = viewport.get_translation().y;
-
- // Don't try to draw stuff that is outside of the screen
- if(base.x <= scroll_x - base.width || base.x >= scroll_x + screen->w)
+ Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right;
+ if(sprite == 0)
return;
-
- if(sprite_left == 0 || sprite_right == 0)
- {
- return;
- }
+ sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
+#if 0
Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right;
- sprite->draw(viewport.world2screen(Vector(base.x, base.y)));
+ if(dying == DYING_FALLING && physic.get_velocity_y() < 0)
+ sprite->draw(viewport.world2screen(Vector(base.x, base.y)), SD_VERTICAL_FLIP);
+ else
+ sprite->draw(viewport.world2screen(Vector(base.x, base.y)));
+#endif
- if (debug_mode)
+ float scroll_x = context.get_translation().x;
+ float scroll_y = context.get_translation().y;
+ if(debug_mode)
fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75,0,75, 150);
}
if(kind == BAD_MRBOMB) {
// mrbomb transforms into a bomb now
- explode();
+ explode(false);
make_player_jump(player);
World::current()->add_score(Vector(base.x, base.y),
if (mode == BGM_BIG)
{
set_sprite(img_walkingtree_left_small, img_walkingtree_left_small);
- physic.set_velocity_x(physic.get_velocity_x() * 1.1);
+ physic.set_velocity_x(physic.get_velocity_x() * 2.0f);
// XXX magic number: 66 is BGM_BIG height
- base.y += 66 - base.height;
- player->base.y = base.y - player->base.height - 2;
make_player_jump(player);
+ base.y += 66 - base.height;
World::current()->add_score(Vector(base.x, base.y),
25 * player_status.score_multiplier);
else
squish_me(player);
}
-
-
}
void
}
void
-BadGuy::explode()
+BadGuy::explode(bool right_way)
{
- World::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
+ BadGuy *badguy = World::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
+ if(right_way)
+ {
+ badguy->timer.start(0);
+ badguy->mode = BOMB_TICKING;
+ }
+
remove_me();
}
if (pbad_c->kind == BAD_MRBOMB)
{
// mrbomb transforms into a bomb now
- pbad_c->explode();
+ pbad_c->explode(true);
return;
}
else if (pbad_c->kind != BAD_MRBOMB)
if (pbad_c->kind == BAD_MRBOMB)
{
// mrbomb transforms into a bomb now
- pbad_c->explode();
+ pbad_c->explode(false);
return;
}
else