00001 #ifndef H_DRAGON 00002 #define H_DRAGON 00003 00004 class Dragon : public AnimatedSprite 00005 { 00006 public: 00007 Dragon() : AnimatedSprite("rsc/dragon.xml") 00008 { 00009 add_animation_object(this); 00010 int r=irand(2); 00011 int y=irand(15)*32; 00012 if (r==0) 00013 { 00014 set_position(iVec2(-50,y)); 00015 set_velocity(dVec2(100,0)); 00016 set_active_sequence(1); 00017 } 00018 else 00019 { 00020 set_position(iVec2(650,y)); 00021 set_velocity(dVec2(-100,0)); 00022 set_active_sequence(0); 00023 } 00024 } 00025 00026 virtual void handle_collision(RigidBody2D* o) 00027 { 00028 if (o->get("Boy")=="YES") 00029 { 00030 JungleBoy* jb=static_cast<JungleBoy*>(o); 00031 if (jb->is_vulnerable()) 00032 { 00033 jb->die(); 00034 } 00035 } 00036 } 00037 00038 virtual bool advance(int dt) 00039 { 00040 AnimatedSprite::advance(dt); 00041 double x=get_position().x; 00042 double sx=get_velocity().x; 00043 if (x<-100 && sx<0) return false; 00044 if (x>700 && sx>0) return false; 00045 return true; 00046 } 00047 }; 00048 00049 #endif // H_DRAGON