⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 molebouncer.cpp

📁 C++&datastructure书籍源码,以前外教提供现在与大家共享
💻 CPP
字号:
class MoleBouncer : public Bouncer
{
  public:
    MoleBouncer(Shape& s, double angle, double v)
     : Bouncer(s,angle,v)
   {  }
    virtual void update(AnimatedCanvas& ac)
    {
        RandGen rgen;
        Iterator<Shape> it(ac.makeIterator());
        bool collided = false;               // collision or still bouncing?
        Point p = getLocation();
        double angle = getAngle();
        for(it.Init(); it.HasMore(); it.Next())
        {   // check for collision, but not with myself
            if (it.Current().id() != this->id() && it.Current().overlaps(*this))
            {   ac.removeShape(this);
                ac.addShape(
                  new MoleBouncer(
                      CircleShape(Point(rgen.RandReal(0,ac.width()/10),
                                        rgen.RandReal(0,ac.height()/10)),
                      RADIUS, CanvasColor::BLUE), 2*PI - angle, 4));
                collided = true;
                break;
            }
        }
        if (!collided)           // no collision, update
        {   Bouncer::update(ac); 
        }
    }
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -