From 50245ba5710df184af5b5e8f0037e87b33491cfe Mon Sep 17 00:00:00 2001 From: Vladimir Menshakov Date: Mon, 4 Jan 2010 11:12:19 +0000 Subject: added idle animation svn-id: r46968 --- engines/teenagent/actor.cpp | 38 +++++++++++++++++++++++++++++++++++++- engines/teenagent/actor.h | 2 ++ engines/teenagent/animation.h | 1 + engines/teenagent/scene.cpp | 11 +++++++++-- engines/teenagent/scene.h | 1 + 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/engines/teenagent/actor.cpp b/engines/teenagent/actor.cpp index e9a29ff35d..71c5caebb0 100644 --- a/engines/teenagent/actor.cpp +++ b/engines/teenagent/actor.cpp @@ -24,12 +24,48 @@ #include "teenagent/actor.h" #include "teenagent/objects.h" +#include "teenagent/resources.h" namespace TeenAgent { -Actor::Actor() : head_index(0) {} +Actor::Actor() : head_index(0), idle_type(0) {} //idle animation lists at dseg: 0x6540 +Common::Rect Actor::renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, uint zoom) { + static Common::RandomSource random; + if (index == 0) { + idle_type = random.getRandomNumber(2); + debug(0, "switched to idle animation %u", idle_type); + } + + Resources * res = Resources::instance(); + byte *frames_idle; + do { + frames_idle = res->dseg.ptr(res->dseg.get_word(0x6540 + idle_type * 2)) + index++; + if (*frames_idle == 0) { + idle_type = random.getRandomNumber(2); + debug(0, "switched to idle animation %u[loop]", idle_type); + index = 3; //put 4th frame (base 1) if idle animation loops + } + } while(*frames_idle == 0); + + bool mirror = orientation == kActorLeft; + Surface *s = frames + *frames_idle - 1; + + ///\todo remove copy-paste here and below + int xp = position.x - s->w * zoom / 512 - s->x, yp = position.y - s->h * zoom / 256 - s->y; + if (xp < 0) + xp = 0; + if (xp + s->w > 320) + xp = 320 - s->w; + + if (yp < 0) + yp = 0; + if (yp + s->h > 200) + yp = 200 - s->h; + + return s->render(surface, xp, yp, mirror, Common::Rect(), zoom); +} Common::Rect Actor::render(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, bool render_head, uint zoom) { const uint8 frames_left_right[] = {0, 1, 2, 3, 4, 5, /* step */ 6, 7, 8, 9}; diff --git a/engines/teenagent/actor.h b/engines/teenagent/actor.h index 73a7a605a8..3edace362e 100644 --- a/engines/teenagent/actor.h +++ b/engines/teenagent/actor.h @@ -29,9 +29,11 @@ namespace TeenAgent { class Actor : public Animation { uint head_index; + uint idle_type; public: Actor(); Common::Rect render(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, int delta_frame, bool head, uint zoom); + Common::Rect renderIdle(Graphics::Surface *surface, const Common::Point &position, uint8 orientation, uint zoom); }; } // End of namespace TeenAgent diff --git a/engines/teenagent/animation.h b/engines/teenagent/animation.h index 3e65a73b94..f77fbcf679 100644 --- a/engines/teenagent/animation.h +++ b/engines/teenagent/animation.h @@ -44,6 +44,7 @@ public: Surface *firstFrame(); Surface *currentFrame(int dt = 1); uint16 currentIndex() const { return index; } + void resetIndex() { index = 0; } ~Animation(); diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp index 7cc009bf78..976a1770b8 100644 --- a/engines/teenagent/scene.cpp +++ b/engines/teenagent/scene.cpp @@ -39,7 +39,8 @@ Scene::Scene() : intro(false), _engine(NULL), _id(0), ons(0), orientation(kActorRight), actor_talking(false), message_timer(0), message_first_frame(0), message_last_frame(0), message_animation(NULL), - current_event(SceneEvent::kNone), hide_actor(false), callback(0), callback_timer(0) {} + current_event(SceneEvent::kNone), hide_actor(false), callback(0), callback_timer(0), + _fade_timer(0), _fade_type(0), _idle_timer(0) {} void Scene::warp(const Common::Point &_point, byte o) { Common::Point point(_point); @@ -707,6 +708,8 @@ bool Scene::render() { (ABS(dp.x) < speed_y? dp.x: SIGN(dp.x) * speed_y): (ABS(dp.x) < speed_x? dp.x: SIGN(dp.x) * speed_x); + _idle_timer = 0; + teenagent_idle.resetIndex(); actor_animation_position = teenagent.render(surface, position, o, 1, false, zoom); if (position == destination) { @@ -722,7 +725,11 @@ bool Scene::render() { } else busy = true; } else { - actor_animation_position = teenagent.render(surface, position, orientation, 0, actor_talking, zoom); + ++_idle_timer; + if (_idle_timer < 50) + actor_animation_position = teenagent.render(surface, position, orientation, 0, actor_talking, zoom); + else + actor_animation_position = teenagent_idle.renderIdle(surface, position, orientation, zoom); } } } diff --git a/engines/teenagent/scene.h b/engines/teenagent/scene.h index aa23595ccf..3319c3e1f8 100644 --- a/engines/teenagent/scene.h +++ b/engines/teenagent/scene.h @@ -220,6 +220,7 @@ private: int _fade_timer; int _fade_type; + uint _idle_timer; struct Sound { byte id, delay; -- cgit v1.2.3