[Scummvm-cvs-logs] SF.net SVN: scummvm:[46968] scummvm/trunk/engines/teenagent

megath at users.sourceforge.net megath at users.sourceforge.net
Mon Jan 4 12:12:19 CET 2010


Revision: 46968
          http://scummvm.svn.sourceforge.net/scummvm/?rev=46968&view=rev
Author:   megath
Date:     2010-01-04 11:12:19 +0000 (Mon, 04 Jan 2010)

Log Message:
-----------
added idle animation

Modified Paths:
--------------
    scummvm/trunk/engines/teenagent/actor.cpp
    scummvm/trunk/engines/teenagent/actor.h
    scummvm/trunk/engines/teenagent/animation.h
    scummvm/trunk/engines/teenagent/scene.cpp
    scummvm/trunk/engines/teenagent/scene.h

Modified: scummvm/trunk/engines/teenagent/actor.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/actor.cpp	2010-01-04 08:34:07 UTC (rev 46967)
+++ scummvm/trunk/engines/teenagent/actor.cpp	2010-01-04 11:12:19 UTC (rev 46968)
@@ -24,13 +24,49 @@
 
 #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};
 	const uint8 frames_up[] = {18, 19, 20, 21, 22, 23, 24, 25, };

Modified: scummvm/trunk/engines/teenagent/actor.h
===================================================================
--- scummvm/trunk/engines/teenagent/actor.h	2010-01-04 08:34:07 UTC (rev 46967)
+++ scummvm/trunk/engines/teenagent/actor.h	2010-01-04 11:12:19 UTC (rev 46968)
@@ -29,9 +29,11 @@
 
 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

Modified: scummvm/trunk/engines/teenagent/animation.h
===================================================================
--- scummvm/trunk/engines/teenagent/animation.h	2010-01-04 08:34:07 UTC (rev 46967)
+++ scummvm/trunk/engines/teenagent/animation.h	2010-01-04 11:12:19 UTC (rev 46968)
@@ -44,6 +44,7 @@
 	Surface *firstFrame();
 	Surface *currentFrame(int dt = 1);
 	uint16 currentIndex() const { return index; }
+	void resetIndex() { index = 0; }
 
 	~Animation();
 

Modified: scummvm/trunk/engines/teenagent/scene.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/scene.cpp	2010-01-04 08:34:07 UTC (rev 46967)
+++ scummvm/trunk/engines/teenagent/scene.cpp	2010-01-04 11:12:19 UTC (rev 46968)
@@ -39,7 +39,8 @@
 		_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 @@
 						(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 @@
 					} 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);
 				}
 			}
 		}

Modified: scummvm/trunk/engines/teenagent/scene.h
===================================================================
--- scummvm/trunk/engines/teenagent/scene.h	2010-01-04 08:34:07 UTC (rev 46967)
+++ scummvm/trunk/engines/teenagent/scene.h	2010-01-04 11:12:19 UTC (rev 46968)
@@ -220,6 +220,7 @@
 	
 	int _fade_timer;
 	int _fade_type;
+	uint _idle_timer;
 
 	struct Sound {
 		byte id, delay;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list