#include <member.h>
Inheritance diagram for Member:
Public Member Functions | |
virtual | ~Member () |
Member (xmlpp::Element *xml, Profile *res) | |
Member (Member *m) | |
virtual void | Draw (const Point2i &_pos, int flip_x, int direction) |
void | RotateSprite () |
void | ResetMovement () |
void | ApplySqueleton (Member *parent_member) |
void | ApplyMovement (member_mvt &mvt, std::vector< class c_junction > &squel_lst) |
const Point2i | GetPos () |
void | SetAngle (const double &angle) |
Public Attributes | |
Sprite * | spr |
std::string | name |
std::map< std::string, v_attached > | attached_members |
Point2f | pos |
Point2f | scale |
float | alpha |
std::string | type |
bool | go_through_ground |
Protected Attributes | |
Point2f | anchor |
Private Attributes | |
Member * | parent |
double | angle_rad |
Definition at line 36 of file member.h.
Member::~Member | ( | ) | [virtual] |
Definition at line 133 of file member.cpp.
00134 { 00135 delete spr; 00136 attached_members.clear(); 00137 }
Member::Member | ( | xmlpp::Element * | xml, | |
Profile * | res | |||
) |
Definition at line 30 of file member.cpp.
00031 { 00032 parent = NULL; 00033 if(xml == NULL) return; 00034 name=""; 00035 XmlReader::ReadStringAttr( xml, "name", name); 00036 assert(name!=""); 00037 00038 // Load the sprite 00039 spr = resource_manager.LoadSprite( res, name); 00040 // spr->EnableRotationCache(64); 00041 // spr->EnableFlippingCache(); 00042 // spr->cache.EnableLastFrameCache(); 00043 00044 // Get the various option 00045 type=""; 00046 XmlReader::ReadStringAttr( xml, "type", type); 00047 assert(type!=""); 00048 00049 xmlpp::Element *el = XmlReader::GetMarker(xml, "anchor"); 00050 if(el != 0) 00051 { 00052 int dx,dy; 00053 dx = dy = 0; 00054 XmlReader::ReadIntAttr(el, "dx", dx); 00055 XmlReader::ReadIntAttr(el, "dy", dy); 00056 anchor = Point2f((float)dx,(float)dy); 00057 spr->SetRotation_HotSpot(Point2i(dx,dy)); 00058 } 00059 00060 go_through_ground = false; 00061 XmlReader::ReadBoolAttr(xml, "go_through_ground", go_through_ground); 00062 00063 xmlpp::Node::NodeList nodes = xml -> get_children("attached"); 00064 xmlpp::Node::NodeList::iterator 00065 it=nodes.begin(), 00066 end=nodes.end(); 00067 00068 for (; it != end; ++it) 00069 { 00070 xmlpp::Element *elem = dynamic_cast<xmlpp::Element*> (*it); 00071 assert (elem != NULL); 00072 std::string att_type; 00073 if (!XmlReader::ReadStringAttr(elem, "member_type", att_type)) 00074 { 00075 std::cerr << "Malformed attached member definition" << std::endl; 00076 continue; 00077 } 00078 00079 int dx,dy; 00080 dx = dy = 0; 00081 XmlReader::ReadIntAttr(elem, "dx", dx); 00082 XmlReader::ReadIntAttr(elem, "dy", dy); 00083 Point2f d((float)dx, (float)dy); 00084 00085 std::string frame_str; 00086 XmlReader::ReadStringAttr(elem, "frame", frame_str); 00087 if (frame_str == "*") 00088 { 00089 v_attached rot_spot; 00090 rot_spot.assign (spr->GetFrameCount(), d); 00091 attached_members[att_type] = rot_spot; 00092 } 00093 else 00094 { 00095 int frame; 00096 if (!str2int (frame_str, frame) || frame < 0 || frame >= (int)spr->GetFrameCount()) 00097 { 00098 std::cerr << "Malformed attached member definition (wrong frame number)" << std::endl; 00099 continue; 00100 } 00101 if(attached_members.find(att_type) == attached_members.end()) 00102 { 00103 v_attached rot_spot; 00104 rot_spot.resize(spr->GetFrameCount(), Point2f(0.0,0.0)); 00105 attached_members[att_type] = rot_spot; 00106 } 00107 (attached_members.find(att_type)->second)[frame] = d; 00108 } 00109 } 00110 ResetMovement(); 00111 }
Here is the call graph for this function:
Member::Member | ( | Member * | m | ) |
Definition at line 113 of file member.cpp.
00114 { 00115 parent = NULL; 00116 name = m->name; 00117 spr = new Sprite(*m->spr); 00118 type = m->type; 00119 anchor = m->anchor; 00120 Point2i rot = Point2i((int)anchor.x, (int)anchor.y); 00121 spr->SetRotation_HotSpot(rot); 00122 go_through_ground = m->go_through_ground; 00123 00124 for(std::map<std::string, v_attached>::iterator it = m->attached_members.begin(); 00125 it != m->attached_members.end(); 00126 ++it) 00127 { 00128 attached_members[it->first] = it->second; 00129 } 00130 ResetMovement(); 00131 }
Here is the call graph for this function:
void Member::ApplyMovement | ( | member_mvt & | mvt, | |
std::vector< class c_junction > & | squel_lst | |||
) |
void Member::ApplySqueleton | ( | Member * | parent_member | ) |
Definition at line 186 of file member.cpp.
00187 { 00188 // Place the member to shape the squeleton 00189 if(parent_member == NULL) 00190 { 00191 std::cerr << "Member " << name << " have no parent member!" << std::endl; 00192 return; 00193 } 00194 parent = parent_member; 00195 00196 assert(parent->name != "weapon" && parent->type != "weapon"); 00197 00198 // Set the position 00199 pos = parent->pos; 00200 pos = pos - anchor; 00201 00202 if(parent->attached_members.find(type) != parent->attached_members.end()) 00203 pos = pos + parent->attached_members.find(type)->second[parent->spr->GetCurrentFrame()]; 00204 }
Here is the call graph for this function:
void Member::Draw | ( | const Point2i & | _pos, | |
int | flip_x, | |||
int | direction | |||
) | [virtual] |
Reimplemented in WeaponMember.
Definition at line 146 of file member.cpp.
00147 { 00148 assert(name != "weapon" && type!="weapon"); 00149 00150 Point2i posi((int)pos.x, (int)pos.y); 00151 posi += _pos; 00152 00153 if(direction == 1) 00154 { 00155 spr->SetRotation_rad(angle_rad); 00156 spr->Scale(scale.x,scale.y); 00157 } 00158 else 00159 { 00160 spr->Scale(-scale.x,scale.y); 00161 spr->SetRotation_rad(-angle_rad); 00162 posi.x = 2 * flip_center - posi.x - spr->GetWidth(); 00163 } 00164 00165 if(parent == NULL && type != "body") 00166 { 00167 std::cerr << "Error : Member " << name << " have no parent member!" << std::endl; 00168 return; 00169 } 00170 00171 spr->SetAlpha(alpha); 00172 spr->Update(); 00173 spr->Draw(posi); 00174 }
Here is the call graph for this function:
const Point2i Member::GetPos | ( | ) |
void Member::ResetMovement | ( | ) |
void Member::RotateSprite | ( | ) |
Definition at line 139 of file member.cpp.
00140 { 00141 spr->SetRotation_rad(angle_rad); 00142 spr->Scale(scale.x, scale.y); 00143 spr->RefreshSurface(); 00144 }
Here is the call graph for this function:
void Member::SetAngle | ( | const double & | angle | ) | [inline] |
float Member::alpha |
Point2f Member::anchor [protected] |
double Member::angle_rad [private] |
std::map<std::string, v_attached> Member::attached_members |
std::string Member::name |
Member* Member::parent [private] |
std::string Member::type |