aboutsummaryrefslogtreecommitdiff
path: root/engines/teenagent
diff options
context:
space:
mode:
authorVladimir Menshakov2009-11-07 09:19:49 +0000
committerVladimir Menshakov2009-11-07 09:19:49 +0000
commit71eae24902d18d1cd45eab7dce4a4f4612bfd780 (patch)
tree96b5133158f6a37897a202cfb6a66b5291eab4dd /engines/teenagent
parenta826c483b9f99c50d610b169c41b5d869a5502b3 (diff)
downloadscummvm-rg350-71eae24902d18d1cd45eab7dce4a4f4612bfd780.tar.gz
scummvm-rg350-71eae24902d18d1cd45eab7dce4a4f4612bfd780.tar.bz2
scummvm-rg350-71eae24902d18d1cd45eab7dce4a4f4612bfd780.zip
improved walking code
svn-id: r45718
Diffstat (limited to 'engines/teenagent')
-rw-r--r--engines/teenagent/scene.cpp68
-rw-r--r--engines/teenagent/scene.h3
-rw-r--r--engines/teenagent/teenagent.cpp10
3 files changed, 51 insertions, 30 deletions
diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp
index d24294b191..5d8ba85ea1 100644
--- a/engines/teenagent/scene.cpp
+++ b/engines/teenagent/scene.cpp
@@ -41,9 +41,7 @@ Scene::Scene() : intro(false), _engine(NULL),
void Scene::warp(const Common::Point &_point, byte o) {
Common::Point point(_point);
- destination = position = position0 = point;
- progress = 0;
- progress_total = 1;
+ destination = position = point;
if (o)
orientation = o;
}
@@ -57,6 +55,7 @@ void Scene::moveTo(const Common::Point &_point, byte orient, bool validate) {
const Walkbox &w = scene_walkboxes[i];
if (w.rect.in(point)) {
debug(0, "bumped into walkbox %u", i);
+ w.dump();
byte o = w.orientation;
switch (o) {
case 1:
@@ -85,9 +84,6 @@ void Scene::moveTo(const Common::Point &_point, byte orient, bool validate) {
}
destination = point;
orientation = orient;
- position0 = position;
- progress_total = 1 + (int)(0.5f + sqrt((float)position.sqrDist(destination)) / 10);
- progress = 0;
}
@@ -308,21 +304,29 @@ bool Scene::processEvent(const Common::Event &event) {
}
return false;
- case Common::EVENT_KEYUP:
- if (intro && event.kbd.keycode == Common::KEYCODE_ESCAPE) {
- intro = false;
- message.clear();
- events.clear();
- sounds.clear();
- current_event.clear();
- message_color = 0xd1;
- Resources::instance()->font7.color = 0xd1;
- for (int i = 0; i < 4; ++i)
- custom_animation[i].free();
- _engine->playMusic(4);
- init(10, Common::Point(136, 153));
+ case Common::EVENT_KEYDOWN:
+ if (event.kbd.keycode == Common::KEYCODE_ESCAPE || event.kbd.keycode == Common::KEYCODE_SPACE) {
+ if (intro) {
+ intro = false;
+ message.clear();
+ events.clear();
+ sounds.clear();
+ current_event.clear();
+ message_color = 0xd1;
+ Resources::instance()->font7.color = 0xd1;
+ for (int i = 0; i < 4; ++i)
+ custom_animation[i].free();
+ _engine->playMusic(4);
+ init(10, Common::Point(136, 153));
+ return true;
+ }
+
+ if (!message.empty()) {
+ message.clear();
+ nextEvent();
+ return true;
+ }
}
- return true;
default:
return false;
@@ -414,19 +418,31 @@ bool Scene::render(OSystem *system) {
} else if (!hide_actor) {
actor_animation.free();
- if (progress < progress_total) {
- Common::Point dp(destination.x - position0.x, destination.y - position0.y);
+ if (position != destination) {
+ const int speed_x = 10, speed_y = 5;
+ Common::Point dp(destination.x - position.x, destination.y - position.y);
+ switch(orientation) {
+ case 2: //left or right
+ case 4:
+ if (dp.y != 0)
+ dp.x = 0; //first, walking up-down
+ break;
+ default:
+ if (dp.x != 0)
+ dp.y = 0; //first, walking left-right
+ }
+
int o;
if (ABS(dp.x) > ABS(dp.y))
o = dp.x > 0 ? Object::kActorRight : Object::kActorLeft;
else
o = dp.y > 0 ? Object::kActorDown : Object::kActorUp;
- position.x = position0.x + dp.x * progress / progress_total;
- position.y = position0.y + dp.y * progress / progress_total;
+ position.x += (ABS(dp.x) < speed_x? dp.x: SIGN(dp.x) * speed_x);
+ position.y += (ABS(dp.y) < speed_y? dp.y: SIGN(dp.y) * speed_y);
+
actor_animation_position = teenagent.render(surface, position, o, 1);
- ++progress;
- if (progress >= progress_total) {
+ if (position == destination) {
position = destination;
if (orientation == 0)
orientation = o; //save last orientation
diff --git a/engines/teenagent/scene.h b/engines/teenagent/scene.h
index 683e5c8042..6e115e63f7 100644
--- a/engines/teenagent/scene.h
+++ b/engines/teenagent/scene.h
@@ -161,8 +161,7 @@ private:
Common::Rect actor_animation_position, animation_position[4];
Actor teenagent, teenagent_idle;
- Common::Point position0, position, destination;
- int progress, progress_total;
+ Common::Point position, destination;
uint8 orientation;
Common::Array<Common::Array<Object> > objects;
diff --git a/engines/teenagent/teenagent.cpp b/engines/teenagent/teenagent.cpp
index 36dabcda0c..7029672bb0 100644
--- a/engines/teenagent/teenagent.cpp
+++ b/engines/teenagent/teenagent.cpp
@@ -66,8 +66,10 @@ void TeenAgentEngine::processObject() {
for (uint i = 0; i < hotspots.size(); ++i) {
const UseHotspot &spot = hotspots[i];
if (spot.inventory_id == inv->id && dst_object->id == spot.object_id) {
- debug(0, "combine! pos?: %u,%u", spot.x, spot.y);
- //moveTo(Common::Point(obj->x, obj->y), NULL, Examine);
+ debug(0, "use object on hotspot!");
+ spot.dump();
+ if (spot.actor_x != 0xffff && spot.actor_y != 0xffff)
+ moveTo(spot.actor_x, spot.actor_y, spot.orientation);
inventory->resetSelectedObject();
if (!processCallback(TO_LE_16(spot.callback)))
debug(0, "fixme! display proper description");
@@ -419,6 +421,10 @@ void TeenAgentEngine::moveTo(uint16 x, uint16 y, byte o, bool warp) {
SceneEvent event(SceneEvent::kWalk);
event.dst.x = x;
event.dst.y = y;
+ if (o > 4) {
+ warning("invalid orientation %d", o);
+ o = 0;
+ }
event.orientation = o;
event.color = warp ? 1 : 0;
scene->push(event);