00001 #ifndef H_FOOD
00002 #define H_FOOD
00003
00004 class Food : public AnimatedSprite
00005 {
00006 static const char* random_food()
00007 {
00008 static const char* names[] = {
00009 "rsc/food/apple.xml",
00010 "rsc/food/bagel.xml",
00011 "rsc/food/banana.xml",
00012 "rsc/food/berry.xml",
00013 "rsc/food/carrot.xml",
00014 "rsc/food/grapes.xml",
00015 "rsc/food/orange.xml",
00016 "rsc/food/pear.xml",
00017 "rsc/food/tberry.xml",
00018 "rsc/food/watermelon.xml"
00019 };
00020 static int n = sizeof(names)/sizeof(const char*);
00021 return names[irand(n)];
00022 }
00023
00024 bool m_Eaten;
00025 public:
00026 Food()
00027 : AnimatedSprite(random_food()),
00028 m_Eaten(false)
00029 {
00030 add_animation_object(this);
00031 }
00032
00033 virtual void handle_collision(RigidBody2D* o)
00034 {
00035 if (o->get("Boy")=="YES")
00036 {
00037 JungleBoy* jb=static_cast<JungleBoy*>(o);
00038 jb->eat_food();
00039 m_Eaten=true;
00040 }
00041 }
00042
00043 virtual bool advance(int dt)
00044 {
00045 if (!AnimatedSprite::advance(dt)) return false;
00046 return (!m_Eaten);
00047 }
00048 };
00049
00050 #endif // H_FOOD
00051