src/character/movement.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  *****************************************************************************/
00020 
00021 #include <map>
00022 #include <iostream>
00023 #include "movement.h"
00024 #include "../tool/xml_document.h"
00025 #include "../tool/string_tools.h"
00026 
00027 Movement::Movement(xmlpp::Element *xml)
00028 {
00029   always_moving = false;
00030   XmlReader::ReadStringAttr( xml, "name", type);
00031   assert(type!="");
00032 
00033   speed = 15;
00034   XmlReader::ReadIntAttr(xml, "speed", speed);
00035 
00036   // Load the test rectangle
00037   test_left = test_right = test_top = test_bottom = 0;
00038   xmlpp::Element *collision_rect = XmlReader::GetMarker(xml, "collision_rect");
00039   if (collision_rect == NULL) return;
00040   XmlReader::ReadUintAttr(collision_rect, "left", test_left);
00041   XmlReader::ReadUintAttr(collision_rect, "right", test_right);
00042   XmlReader::ReadUintAttr(collision_rect, "top", test_top);
00043   XmlReader::ReadUintAttr(collision_rect, "bottom", test_bottom);
00044 
00045   xmlpp::Node::NodeList nodes = xml -> get_children("frame");
00046   xmlpp::Node::NodeList::iterator
00047     it=nodes.begin(),
00048     end=nodes.end();
00049 
00050   for (; it != end; ++it)
00051   {
00052     xmlpp::Element *elem = dynamic_cast<xmlpp::Element*> (*it);
00053     assert (elem != NULL);
00054     int frame_number;
00055     XmlReader::ReadIntAttr(elem, "number", frame_number);
00056 
00057     xmlpp::Node::NodeList nodes2 = elem -> get_children("member");
00058     xmlpp::Node::NodeList::iterator
00059       it2=nodes2.begin(),
00060       end2=nodes2.end();
00061 
00062     for (; it2 != end2; ++it2)
00063     {
00064       xmlpp::Element *elem2 = dynamic_cast<xmlpp::Element*> (*it2);
00065       std::string member_type;
00066       XmlReader::ReadStringAttr(elem2, "type", member_type);
00067 
00068       member_mvt mvt;
00069       int dx, dy;
00070       int angle_deg = 0;
00071       dx = dy = 0;
00072       double scale_x, scale_y, tmp_alpha;
00073       scale_x = scale_y = tmp_alpha = 1.0;
00074       XmlReader::ReadIntAttr(elem2, "dx", dx);
00075       XmlReader::ReadIntAttr(elem2, "dy", dy);
00076       XmlReader::ReadDoubleAttr(elem2, "scale_x", scale_x);
00077       XmlReader::ReadDoubleAttr(elem2, "scale_y", scale_y);
00078       XmlReader::ReadDoubleAttr(elem2, "alpha", tmp_alpha);
00079       XmlReader::ReadIntAttr(elem2, "angle", angle_deg);
00080       XmlReader::ReadBoolAttr(elem2, "follow_crosshair", mvt.follow_crosshair);
00081       XmlReader::ReadBoolAttr(elem2, "follow_half_crosshair", mvt.follow_half_crosshair);
00082       XmlReader::ReadBoolAttr(elem2, "follow_speed", mvt.follow_speed);
00083       XmlReader::ReadBoolAttr(elem2, "follow_direction", mvt.follow_direction);
00084       if(tmp_alpha < 0.0 || tmp_alpha > 1.0) tmp_alpha = 1.0;
00085       mvt.SetAngle(angle_deg * M_PI / 180);
00086       mvt.pos.x = dx;
00087       mvt.pos.y = dy;
00088       mvt.alpha = tmp_alpha;
00089       mvt.scale = Point2f(scale_x, scale_y);
00090 
00091       always_moving |= mvt.follow_crosshair;
00092       always_moving |= mvt.follow_half_crosshair;
00093       always_moving |= mvt.follow_speed;
00094       always_moving |= mvt.follow_direction;
00095 
00096       if((int)frames.size() <= frame_number)
00097         frames.resize(frame_number+1);
00098 
00099       frames[frame_number][member_type] = mvt;
00100     }
00101   }
00102 }
00103 
00104 Movement::~Movement()
00105 {
00106 }

Generated on Mon Jan 1 13:10:56 2007 for Wormux by  doxygen 1.4.7