00001 #ifndef H_OGRE
00002 #define H_OGRE
00003
00004 class Ogre : public AnimatedSprite
00005 {
00006 bool m_Right;
00007 bool m_OnGround;
00008 public:
00009 Ogre()
00010 : AnimatedSprite("rsc/ogre.xml"),
00011 m_Right(true),
00012 m_OnGround(true)
00013 {
00014 add_animation_object(this);
00015 set_active_sequence(0);
00016 set_acceleration(dVec2(0,200));
00017 }
00018
00019 virtual void handle_collision(RigidBody2D* o)
00020 {
00021 if (o->get("Boy")=="YES")
00022 {
00023 JungleBoy* jb=static_cast<JungleBoy*>(o);
00024 if (jb->is_vulnerable())
00025 {
00026 jb->die();
00027 set_active_sequence(m_Right?3:2);
00028 }
00029 }
00030 if (o->get("Floor")=="YES")
00031 {
00032 iRect2 r1=get_rect();
00033 iRect2 r2=o->get_rect();
00034 iRect2 res=r1.overlap(r2);
00035 if (res.get_height()<10 && get_velocity().y>0 && res.br.y==r1.br.y)
00036 {
00037 offset_position(dVec2(0,-res.get_height()));
00038 set_velocity(dVec2(get_velocity().x,0));
00039 m_OnGround=true;
00040 }
00041 xstring edge_type=o->get("Edge");
00042 if (!edge_type.empty())
00043 {
00044 if (edge_type=="Right" && m_Right) m_Right=false;
00045 else
00046 if (edge_type=="Left" && !m_Right) m_Right=true;
00047 }
00048 }
00049 }
00050
00051 virtual bool advance(int dt)
00052 {
00053 AnimatedSprite::advance(dt);
00054 if (get_active_sequence()>1)
00055 {
00056 if (get_current_frame()<2) return true;
00057 }
00058 if (m_Right)
00059 {
00060 set_active_sequence(1);
00061 set_velocity(dVec2(30,get_velocity().y));
00062 }
00063 else
00064 {
00065 set_active_sequence(0);
00066 set_velocity(dVec2(-30,get_velocity().y));
00067 }
00068 return true;
00069 }
00070 };
00071
00072 #endif H_OGRE
00073
00074