improved walking code

svn-id: r45718
This commit is contained in:
Vladimir Menshakov 2009-11-07 09:19:49 +00:00
parent a826c483b9
commit 71eae24902
3 changed files with 51 additions and 30 deletions

View File

@ -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,8 +304,9 @@ bool Scene::processEvent(const Common::Event &event) {
}
return false;
case Common::EVENT_KEYUP:
if (intro && event.kbd.keycode == Common::KEYCODE_ESCAPE) {
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();
@ -321,8 +318,15 @@ bool Scene::processEvent(const Common::Event &event) {
custom_animation[i].free();
_engine->playMusic(4);
init(10, Common::Point(136, 153));
}
return true;
}
if (!message.empty()) {
message.clear();
nextEvent();
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

View File

@ -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;

View File

@ -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);