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

📄 bouncer.cpp

📁 C++&datastructure书籍源码,以前外教提供现在与大家共享
💻 CPP
字号:
#include <iostream>
#include "canvas.h"
#include "auxil.h"
#include <string>

using namespace std;

class BounceAround : public Bouncer
{
  public:
    BounceAround(Shape& cs, double angle, double v)
      : Bouncer(cs,angle,v)
    { }
    
    BounceAround(const BounceAround& ba)
      : Bouncer(ba)
    { }
    
    virtual void updatebottom(AnimatedCanvas& c, Point& p)
    {
        // p.y = 20; // -= bbox().getUL().y;
        Bouncer::updatebottom(c,p);
    }
    virtual void updateright(AnimatedCanvas& c, Point& p)
    {  
        p.x = p.x - bbox().getUL().x;
    }
    
    virtual void draw(AnimatedCanvas& c)
    {
        Bouncer::draw(c);
    }
    
    virtual Shape* clone()
    {
        return new BounceAround(*this);
    }
    
};


int main()
{
    int width=400;
    int height=400;
    AnimatedCanvas display(width,height,20,20);
    //Canvas display(400,400,20,20);

    string base = "c:\\data\\pics\\";
    
    display.SetTitle("bouncer demo");
    
    CircleShape c1(Point(50,10),8,RED);
    CircleShape c2(Point(20,50),8,BLUE);
    
    RectangleShape r1(Point(40,50),16,16,YELLOW);
    RectangleShape r2(Point(30,50),16,16,CYAN);
    
    RectangleShape b(Point(50,50),16,8,GREEN);
    CircleShape    lear(Point(48,48),4,GREEN);
    CircleShape    rear(Point(68,48),4,GREEN);
    TextShape ts(Point(50,58),"mickey",BLACK);
    CompositeShape thing;
    thing.add(b);
    thing.add(ts);
    thing.add(rear);
    thing.add(lear);
    
    CircleShape ba(Point(16,30),16,RED);
    RectangleShape ba2(Point(4,56),24,12,RED);
    RectangleShape t1(Point(15,44),2,20,RED);
    RectangleShape t2(Point(8,44),2,20,RED);
    RectangleShape t3(Point(22,44),2,20,RED);
    CompositeShape balloon;
    balloon.add(ba);
    balloon.add(ba2);
    balloon.add(t1); balloon.add(t2); balloon.add(t3);
    
    EllipseShape body(Point(10,10),Point(50,30),YELLOW);
    EllipseShape bodyb(Point(9,9),Point(51,31),BLACK);
    CircleShape  eye(Point(40,15),5,RED);
    TriangleShape fin(Point(30,5),Point(30,11),Point(35,11),BLUE);
    TriangleShape tail(Point(0,10),Point(0,30),Point(15,20),GREEN);
    CompositeShape fish;
    fish.add(fin);
    fish.add(tail);
    fish.add(bodyb);
    fish.add(body);
    fish.add(eye);
    
    Shape * fish2 = fish.clone();
    fish2->setLocation(Point(10,40));
    Shape * fish3 = fish.clone();
    fish3->setLocation(Point(50,100));
    
    Shape * ball2 = balloon.clone();
    ball2->setLocation(Point(16,60));
    
    string name = base + "olaout.jpg";
    ImageShape i1(Point(50,50),name);
    name = base + "markout.jpg";    
    ImageShape i2(Point(100,100),name);
    
    tvector<Point> p;
    p.push_back(Point(10,20));
    p.push_back(Point(10,10));
    p.push_back(Point(15,5));
    p.push_back(Point(20,10));
    p.push_back(Point(20,20));
    p.push_back(Point(15,25));
    PolygonShape ps(p,p.size(),BLACK);
    
    const double PI=3.14159265;
    Bouncer b1(c1,PI/4,1);
    Bouncer b2(c2,PI/4,1);
    
    Bouncer h1(i1,3*PI/4,2);
    Bouncer h2(i2,PI/4,4);
    Bouncer h3(r1,3*PI/5,3);
    Bouncer h4(r2,4*PI/7,4);
    BounceAround h5(thing,3*PI/5,8);
    Bouncer h6(balloon,PI/2,4);
    Bouncer h7(*ball2,0,4);
    Bouncer h8(ps, 5*PI/4,2);
    Bouncer h9(fish,0,3);
    Bouncer h10(*fish2,0,4);
    BounceAround h11(*fish3,PI/4,3);
    
    // display.setBackground(mjs);
    display.addShape(b1.clone());
    display.addShape(b2.clone());
    display.addShape(h1.clone());
    display.addShape(h2.clone());
    display.addShape(h3.clone());
    display.addShape(h4.clone());
    display.addShape(h5.clone());
    display.addShape(h6.clone());
    display.addShape(h7.clone());
    display.addShape(h8.clone());
    display.addShape(h9.clone());
    display.addShape(h10.clone());
    display.addShape(h11.clone());
    
    CircleShape g(Point(50,20),20,GREEN);
    display.addShape(new BounceAround(g,PI/5,5));
    
    display.addShape(new Bouncer(tail,PI,2));
    display.addShape(new Bouncer(ps,0,3));
    display.addShape(new Bouncer(ps,PI/2,3));
    
    // display.run(5000,20);
    
    display.addShape(new PrintWatcher('u'));
    display.runUntilEscape(20);
    
    //display.repaint();
    char ch;
    cin.get(ch);
    
    return 0;
    
    
}

⌨️ 快捷键说明

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