//--------------------------------------------------------------
void ofApp::setup(){
    
    //Systemwide Settings
    ofEnableAlphaBlending();
    ofSetVerticalSync(TRUE);
    ofSetBackgroundAuto(FALSE);
    ofSetFrameRate(60);
//    ofSetFullscreen(true);
    ofSetBackgroundColor(0, 0, 0);
    ofSetCircleResolution(128);
    
    isMousePressed = false;
    
    //number of birds initiation
    numBirds = 300;
    framesBetweenRecordedPosition = 3;
    frameCounter = 0;
    
    //create all my birds
    for(int i = 0; i < numBirds; i++){
        Bird tempBird; //create a temp bird
        tempBird.setup(); //give it life
        myBirds.push_back(tempBird); //copy it and stick it in the vectory
    } //tempBird is no more
    
    
    //cursorAmp is the magnitude multiplier to the cursor attraction force it will approach an assymptote of
    cursorAmp = 1.0;
    ampAsymptote = 7.0;
}
//--------------------------------------------------------------
void ofApp::setup(){
    numBirds = 100;
    //create all my birds
    for(int i=0; i<numBirds; i++){
        Bird tempBird; //create a temporary bird
        tempBird.setup(); //give it life
        myBirds.push_back(tempBird); //stick it in the vector
    } //tempBird is no more
}
Esempio n. 3
0
int BirdModel::countFastest() {
	int num = 0;
	Bird* bird;
	for (int i = 0; i < dimX * dimY; i++) {
		bird = agents.getAgent(repast::AgentId(i, rank, 0));
		if (bird->getFastest())
			num += 1;
	}
	return num;
}
Esempio n. 4
0
  Action Player::shoot(const GameState &pState, const Deadline &pDue) {
    if (lastRound != pState.getRound()) {
      hmm.clear();

      for (unsigned int i = 0; i < pState.getNumBirds(); ++i) {
        HMM hmm1(this -> STATES, this -> DIRECTIONS);
        hmm.push_back(hmm1);
      }
    }

    for (unsigned int i = 0; i < pState.getNumBirds(); ++i) {
      Bird b = pState.getBird(i);
      if (b.isDead())
        continue;

      int n = b.getSeqLength();

      // if (n < THRESHOLD || pState.getRound() == 0)
      //   continue;

      std::vector<int> seq(n, 0);
      for (int j = 0; j < n; ++j) {
        seq[j] = b.getObservation(j);
      }

      hmm[i].estimateMatrices(seq);

      std::vector<long double> em = hmm[i].getNextEmissionDist();
      long double max = -1;
      int nextMove = -1;
      for (int j = 0; j < DIRECTIONS; ++j) {
        if (em[j] > max) {
          max = em[j];
          nextMove = j;
        }
      }

      if (max > MIN_PROBABILITY) {
        std::cerr << "Shooting with prob: " << max << std::endl;
        hmm[i].printTransitionMatrix();
        hmm[i].printEmissionMatrix();
        std::cerr << std::endl << std::endl;
        ++shots;
        return Action(i, (EMovement)nextMove);
      }
    }

    // cerr << "Shots: " << shots << endl;
    // cerr << "Hits:  " << hits << endl;
    // if (shots != 0) 
    //   cerr << "Rate:  " << (double) hits / (double) shots << endl << endl;

    // This line choose not to shoot
    return cDontShoot;
  }
Esempio n. 5
0
Bird* Bird::create(const std::string& filename, const std::string& c_plist, const char* c_FileNameFormat, Vec2 P0, Vec2 P1, Vec2 P2, Vec2 P3, float DelayTime, float FlyTime)
{
	Bird *sprite = new (std::nothrow) Bird(filename, c_plist, c_FileNameFormat, P0, P1, P2, P3, DelayTime, FlyTime);
	if (sprite && sprite->init())
	{
		sprite->autorelease();		
		return sprite;
	}
	CC_SAFE_DELETE(sprite);
	return nullptr;
}
Esempio n. 6
0
void Scene::populate(int n, int size)
{
    for (int i = 0; i < n; ++i) {
        Bird * b = new Bird(size);

        // set a random position
        b->setPos(Rand::randPointF(sceneRect()));

        addItem(b);
    }
}
//--------------------------------------------------------------
void ofApp::setup(){
    
    // Number of Birds
    numBirds = 100;
    
    // Create all Birds.
    for (int i = 0; i < numBirds; i++) {
        Bird tempBird;                  // Create a Bird,
        tempBird.setup();               // Give this Bird all initial content,
        myBirds.push_back(tempBird);    // Put this Bird into myBirds Array.
    }
}
Esempio n. 8
0
Bird* Bird::createWithWorld( b2World* world )
{
	Bird* result = new Bird();
	if (result && result->initWithWorld(world))
	{
		result->autorelease();
		return result;
	} else {
		delete result;
		result = NULL;
		return NULL;
	}
}
Esempio n. 9
0
int main(){
  Bird *b = new Bird();
  FlyingBird *f = new FlyingBird();
  Penguin *p = new Penguin();
  assert(b->f() == 21);
  assert(f->g() == 42);
  assert(p->f() == 42);
  assert(p->g() == 21);
  delete b;
  delete f;
  delete p;
  return 0;
}
Esempio n. 10
0
void BlueBird::special()
{


    Bird *duplicate;
    b2Vec2 v = g_body->GetLinearVelocity();
    duplicate = new BlueBird(ratio,g_pixmap.pos()+QPointF(0,g_pixmap.pixmap().height()),g_pixmap.pixmap());
    duplicate->launch(b2Vec2(v.x,v.y-5));
    list->push_back(duplicate);
    duplicate = new BlueBird(ratio,g_pixmap.pos()-QPointF(0,g_pixmap.pixmap().height()),g_pixmap.pixmap());
    duplicate->launch(b2Vec2(v.x,v.y+5));
    list->push_back(duplicate);
}
Esempio n. 11
0
int main() {
  Bird b; 
  Cat c;
  Pet* p[] = { &b, &c, };
  for(int i = 0; i < sizeof p / sizeof *p; i++)
    cout << p[i]->type() << " je "
         << p[i]->eats()->foodType() << endl;
  // Funkcja moze zwrocic dokladny typ:
  Cat::CatFood* cf = c.eats();
  Bird::BirdFood* bf;
  // Funkcja nie moze zwrocic dokladnego typu:
//!  bf = b.eats();
  // Trzeba rzutowac w dol:
  bf = dynamic_cast<Bird::BirdFood*>(b.eats());
} ///:~
Esempio n. 12
0
int main() {
  Bird b; 
  Cat c;
  Pet* p[] = { &b, &c, };
  for(int i = 0; i < sizeof p / sizeof *p; i++)
    cout << p[i]->type() << " eats "
         << p[i]->eats()->foodType() << endl;
  // Can return the exact type:
  Cat::CatFood* cf = c.eats();
  Bird::BirdFood* bf;
  // Cannot return the exact type:
//!  bf = b.eats();
  // Must downcast:
  bf = dynamic_cast<Bird::BirdFood*>(b.eats());
} ///:~
Esempio n. 13
0
void BlueBird::special()
{
    Bird *duplicate;
    b2Vec2 v = g_body->GetLinearVelocity();
    float angle=atan2f(v.y,v.x), spin=PI/18, dist=g_pixmap.pixmap().height();
    duplicate = new BlueBird(ratio,g_pixmap.pos()+QPointF(dist*cosf(angle+PI/2),dist*-sinf(angle+PI/2)),g_pixmap.pixmap());
    duplicate->launch(b2Vec2(v.x*cosf(spin)+v.y*-sinf(spin),v.x*+sinf(spin)+v.y*cosf(spin)));
    list->push_back(duplicate);

    duplicate = new BlueBird(ratio,g_pixmap.pos()+QPointF(dist*cosf(angle-PI/2),dist*-sinf(angle-PI/2)),g_pixmap.pixmap());
    duplicate->launch(b2Vec2(v.x*cosf(-spin)+v.y*-sinf(-spin),v.x*sinf(-spin)+v.y*cosf(-spin)));
    list->push_back(duplicate);


}
Esempio n. 14
0
// bad code for demonstration purpose only!
int main(){
  cout << "(a)----------------------------\n";
        Hummingbird hummingbird;
        Bird        bird = hummingbird; // slicing
        Animal &    animal = hummingbird;
  cout << "(b)-----------------------------\n";
	    hummingbird.makeSound();
	    bird.makeSound();
	    animal.makeSound(); // non-virtual!
  cout << "(c)-----------------------------\n";
        hummingbird.move();
        bird.move();
        animal.move();
  cout << "(d)-----------------------------\n";
}
Esempio n. 15
0
void doSomething(Flyable *obj)
{
    cout << typeid(*obj).name() <<endl;
    obj->takeoff();
    if(typeid(*obj) == typeid(Bird))
    {
        Bird *bird = dynamic_cast<Bird * >(obj);
        bird->foraging();
    }
    if(typeid(*obj) == typeid(Plane))
    {
        Plane *plane = dynamic_cast<Plane * >(obj);
        plane->carry();
    }
    obj->land();
}
Esempio n. 16
0
int main(){
  cout << "(a)----------------------------" << endl;
	    Bird        bibo();
        Hummingbird hummingbird;
        Bird        bird = hummingbird;
        Animal &    animal= hummingbird;
  cout << "(b)-----------------------------" << endl;
	    hummingbird.makeSound();
	    bird.makeSound();
	    animal.makeSound();
  cout << "(c)-----------------------------" << endl;
        hummingbird.move();
        bird.move();
        animal.move();
  cout << "(d)-----------------------------" << endl;
}
Esempio n. 17
0
void doSomething(Flyable *obj)                 // 做些事情
{
    obj->takeoff();

    cout << typeid(*obj).name() << endl;        // 输出传入对象类型("class Bird" or "class Plane")

    if(typeid(*obj) == typeid(Bird))            // 判断对象类型
    {
        Bird *bird = dynamic_cast<Bird *>(obj); // 对象转化
        bird->foraging();
    }

    obj->land();

    return;
};
Esempio n. 18
0
//Deletes all of the created objects here.
void CloseFunc(){
	window.window_handle = -1;
	cylinder.TakeDown();torus.TakeDown();square.TakeDown();square2.TakeDown();
	disc.TakeDown();sphere.TakeDown();sphere2.TakeDown();tiger.TakeDown();goldeen.TakeDown();
	stadium.TakeDown();coin.TakeDown();ss.TakeDown();healthBar.TakeDown();
	shark.TakeDown();bird.TakeDown();sb.TakeDown();arena.TakeDown();skyboxUW.TakeDown();fbo.TakeDown();rain2.TakeDown();
	tri2.TakeDown();skybox.TakeDown();skybox2.TakeDown();skybox3.TakeDown();egg.TakeDown();snow2.TakeDown();
	star.TakeDown();magneton.TakeDown();haunter.TakeDown();frog.TakeDown();
	sph1.TakeDown(); enm.TakeDown(); usr.TakeDown();sq4.TakeDown();soldier.TakeDown();userTeam.TakeDown();cpuTeam.TakeDown();
}
Esempio n. 19
0
void Level1::spawn()
{
    if(itemCount > 39)
        return;
    Bird * bird = new Bird();
    birds.push_back(bird);
    addItem(bird);
    int x = points.begin()->x();
    int y = points.begin()->y();
    QVector<QPointF>::Iterator it = points.begin();

    bird->moveAnim->setStartValue(bird->pos());
    bird->moveAnim->setEndValue(QPointF(x,y));
    bird->moveAnim->setDuration(2000);
    bird->moveAnim->start();

    points.erase(it);
    itemCount++;
}
Esempio n. 20
0
Bird * Bird::create( short type )
{
    Bird *bird = new Bird();
    CCString *name = CCString::createWithFormat("*****@*****.**",type);
    if(bird&&bird->initWithSpriteFrameName(name->getCString()))
    {
        bird->birdType = type;
        bird->autorelease();
        CCArray *frames = CCArray::create();
        CCString *blinkFrame = CCString::createWithFormat("*****@*****.**",type);
        frames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()));
        frames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(blinkFrame->getCString()));
        frames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()));
        CCAnimation *animation = CCAnimation::createWithSpriteFrames(frames,0.2f);
        bird->blinkAct = CCAnimate::create(animation);
        bird->blink();
        return bird;
    }
    return NULL;
}
Esempio n. 21
0
void Widget::keyPressEvent(QKeyEvent *e){
b2Vec2 tmpv;
Bird* tmpb;
    switch(e->key()){

        case Qt::Key_S:
            shootBird(startX,startY,8.0,8.0,1);
        break;
        case Qt::Key_Space:
            switch(current_type)
            {
                case 2:
                tmpv = FlyingBird->speed;
                tmpv.Set(tmpv.x*1.5,tmpv.y*1.5);
                FlyingBird->setLinearVelocity(tmpv);
                break;
                case 3:
                tmpb =new Bird(FlyingBird->g_body->GetPosition().x,FlyingBird->g_body->GetPosition().y,0.15,&timer,QPixmap("./egg.png").scaled(height()/15.0,height()/15.0),world,scene,5,false);
                itemList.push_back(tmpb);
                break;
                case 4:
                tmpb =new Bird(FlyingBird->g_body->GetPosition().x,FlyingBird->g_body->GetPosition().y,0.27,&timer,QPixmap("./Blue_Bird_1.png").scaled(height()/10.0,height()/10.0),world,scene,4,false);
                tmpv = FlyingBird->speed;
                                tmpv.Set(tmpv.x,tmpv.y*0.75);
                tmpb->setLinearVelocity(tmpv);
                itemList.push_back(tmpb);
                tmpb =new Bird(FlyingBird->g_body->GetPosition().x,FlyingBird->g_body->GetPosition().y,0.27,&timer,QPixmap("./Blue_Bird_1.png").scaled(height()/10.0,height()/10.0),world,scene,4,false);
                tmpv = FlyingBird->speed;
                tmpv.Set(tmpv.x,tmpv.y*1.2);
                tmpb->setLinearVelocity(tmpv);
                itemList.push_back(tmpb);
                break;
            default:
                break;

            }

        default:
            break;
    }
}
//--------------------------------------------------------------
void ofApp::setup(){
    
    //Systemwide Settings
    ofEnableAlphaBlending();
    ofSetVerticalSync(TRUE);
    ofSetBackgroundAuto(FALSE);
    ofSetFrameRate(60);
    
    //number of birds initiation
    numBirds = 100;
    
    //create all my birds
    for(int i = 0; i < numBirds; i++){
        Bird tempBird; //create a temp bird
        tempBird.setup(); //give it life
        myBirds.push_back(tempBird); //copy it and stick it in the vectory
    } //tempBird is no more
    
    

}
Esempio n. 23
0
int main()
{
    cout << "Creating dog." << endl;
    Dog dog;
    dog.speak();
    cout << "Creating cat." << endl;
    Cat cat;
    cat.speak();
    cout << "Creating bird." << endl;
    Bird bird;
    bird.speak();
    cout << "All animals created." << endl << endl;

    cout << "Creating pet pointer array." << endl;
    cout << "Adding created pets to array." << endl;
    Pet* petPtr[3] = {&dog, &cat, &bird};
    cout << "Iterating over array." << endl;
    for(int i = 0; i < (int) (sizeof(petPtr) / sizeof(*petPtr)); i++) {
        petPtr[i]->speak();
    }

    cout << endl << "Creating array of dynamically allocated animals." << endl;
    Pet* dynAllocPets[3] = {new Dog, new Cat, new Bird};
    cout << "Iterating over array." << endl;
    for(int i = 0; i < (int) (sizeof(dynAllocPets) / sizeof(*dynAllocPets)); i++) {
        dynAllocPets[i]->speak();
    }
    cout << "Calling destructors." << endl;
    for(int i = 0; i < (int) (sizeof(dynAllocPets) / sizeof(*dynAllocPets)); i++) {
        dynAllocPets[i]->~Pet();
    }

    /*
    cout << endl << "Trying to declare oject of type Pet (will not compile)." << endl;
    Pet pet;*/
    return 0;
}
Esempio n. 24
0
static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr, gpointer user_data)
{
	sun.draw(cr);
	
	cloud1.draw(cr);
	cloud2.draw(cr);
    cloud3.draw(cr);
    cloud4.draw(cr);
    cloud7.draw(cr);
    cloud8.draw(cr);
    arrow.draw(cr);
    
	balloon.draw(cr);
	balloon.check_hit(arrow);
	balloon2.draw(cr);
	balloon2.check_hit(arrow);
	balloon3.draw(cr);
	balloon3.check_hit(arrow);
	balloon4.draw(cr);
	balloon4.check_hit(arrow);
	
    
    
    bird.draw(cr);
    bird.check_hit(arrow);
    
    
    bush1.draw(cr);
	bush2.draw(cr);
	bush3.draw(cr);
	bush4.draw(cr);
	bush5.draw(cr);
	
	scoreboard.display(cr);
    return FALSE;
}
Esempio n. 25
0
void doFly(Bird& b) {
    cout << b.getType() << endl;
    b.fly();
    cout << endl;
}
Esempio n. 26
0
// on "init" you need to initialize your instance
bool GameStart::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !Layer::init() )
	{
		return false;
	}
	log("GameStart init");
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	// add a "close" icon to exit the progress. it's an autorelease object
	auto closeItem = MenuItemImage::create(
		"CloseNormal.png",
		"CloseSelected.png",
		CC_CALLBACK_1(GameStart::menuCloseCallback, this));

	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
		origin.y + closeItem->getContentSize().height/2));

	// create menu, it's an autorelease object
	auto menu = Menu::create(closeItem, NULL);
	menu->setPosition(Vec2::ZERO);
	this->addChild(menu, 1);

	// create and initialize a label
	auto label = Label::createWithTTF("Flappy Bird", "fonts/Marker Felt.ttf", 32);
	label->setPosition(Vec2(origin.x + visibleSize.width/2,origin.y + visibleSize.height - 80));
	this->addChild(label, 3);


	//initialize the SpriteFrameCache
	SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
	frameCache->addSpriteFramesWithFile("birdSprites.plist");

	auto ready = Sprite::createWithSpriteFrameName("text_ready.png");
	ready->setPosition(visibleSize.width/2,visibleSize.height/2+100);
	addChild(ready,1);

	auto tutorial = Sprite::createWithSpriteFrameName("tutorial.png");
	tutorial->setPosition(visibleSize.width/2,visibleSize.height/2-10);
	addChild(tutorial,1);

	auto ok = Sprite::createWithSpriteFrameName("button_ok.png");
	auto ok_item = MenuItemSprite::create(ok,ok,nullptr,CC_CALLBACK_1(GameStart::Game_Begin,this));
	auto mu = Menu::create(ok_item,0);
	mu->setPosition(visibleSize.width/2,visibleSize.height/2-80);
	addChild(mu,2);

	auto bg = Sprite::createWithSpriteFrameName("bg_day.png");
	bg->setPosition(visibleSize.width/2,visibleSize.height/2);
	addChild(bg);

	Bird *bird = new Bird(static_cast<BIRD_KINDS>(random(0,2)));
	bird->getBird()->setPosition(visibleSize.width/2-45,visibleSize.height/2);
	addChild(bird->getBird(),2);
	bird->bird_Fly_Spot();


	//draw the background





	return true;
}
Esempio n. 27
0
 void visit( Bird & bird ) override
 {
     bird.fly();
 }
Esempio n. 28
0
void initialize(int numspecies) {
	int birdId = 0;
	int predatorId = 0;

	for(int i=0; i<numspecies; i++) {
		int numbirds = settings[i].number;

		for(int j = 0; j<numbirds; j++) {
			Bird bird = Bird(world, settings[i].maxV, settings[i].minsize, settings[i].maxsize);
			bird.setSpecies(i);

			bird.setPredator(settings[i].predator);
			bird.setMaxA(settings[i].maxA);

			bird.setSightDistance(settings[i].sight_distance);
			bird.setMinSeparation(settings[i].min_separation);
			bird.setAligmentRadius(settings[i].alignment_radius);
			bird.setAvoidanceRadius(settings[i].avoidance_radius);

			bird.setWanderRadius(settings[i].wander_radius);
			bird.setWanderDistance(settings[i].wander_distance);

			bird.setSightAngle(settings[i].sight_angle);
			bird.setMaxTurn(settings[i].max_turn);

			Color color;
			color.clRed = settings[i].color.clRed;
			color.clGreen = settings[i].color.clGreen;
			color.clBlue = settings[i].color.clBlue;
			bird.setColor(color);

			if(settings[i].predator) {
				bird.setId(predatorId);
				predators1.push_back(bird);
				predators2.push_back(bird);
				predatorId++;
			}
			else {
				bird.setId(birdId);
				birds1.push_back(bird);
				birds2.push_back(bird);
				birdId++;
			}
		}
	}
}
Esempio n. 29
0
void MainWindow::showEvent(QShowEvent *)
{

    // Setting the QGraphicsScene
    scene = new QGraphicsScene(0,0,width(),ui->graphicsView->height());

    scene->addPixmap(QPixmap(":/image/Angry Bird Game - Background.png"));
    QLabel *label = new QLabel(QString("分數 : "));
    label->setGeometry(30,30,45,30);
    scene->addWidget(label);
    lcd = new QLCDNumber();
    lcd->display(0);
    lcd->setGeometry(60,30,50,30);
    scene->addWidget(lcd);
    button = new QPushButton(QString("Restart!!"));
    button->setGeometry(0,0,50,30);
    connect(button,SIGNAL(pressed()),this,SLOT(restart()));
    scene->addWidget(button);
    exit = new QPushButton(QString("Exit"));
    exit->setGeometry(930,0,30,30);
    connect(exit,SIGNAL(pressed()),this,SLOT(QUITSLOT()));
    scene->addWidget(exit);

    ui->graphicsView->setScene(scene);

    // Create world
    world = new b2World(b2Vec2(0.0f, -9.8f));
    // Setting Size
    GameItem::setGlobalSize(QSizeF(32,18),size());
    // Create ground (You can edit here)
    items.push_back(new Land(16,1.5,32,3,QPixmap(":/ground.png").scaled(960,90),world,scene));

    // Create bird (You can edit here)

    Bird *birdie = new Bird(2.0f,10.0f,1,&timer,QPixmap(":/bird.png").scaled(60,60),world,scene);
    // Setting the Velocity
    birdie->setLinearVelocity(b2Vec2(0,0));
    birdie->setDensity();
    itemList.push_back(birdie);


    Bird *birdie1 = new Yellowbird(5.0f,17.0f,1,&timer,QPixmap(":/image/angry-bird-yellow-icon.png").scaled(60,60),world,scene);
    // Setting the Velocity
    birdie1->setLinearVelocity(b2Vec2(0,0));
    //birdie1->getBody().SetActive(false);
    itemList.push_back(birdie1);

    tempb = new Blackbird(3.0f,17.0f,1,&timer,QPixmap(":/image/angry-bird-black-icon (1).png").scaled(60,60),world,scene);
    // Setting the Velocity
    tempb->setLinearVelocity(b2Vec2(0,0));
    //birdie2->getBody().SetActive(false);
    itemList.push_back(tempb);

    temp = new Whitebird(1.0f,17.0f,1,&timer,QPixmap(":/image/angry-bird-white-icon.png").scaled(60,60),world,scene);
    // Setting the Velocity
    temp->setLinearVelocity(b2Vec2(0,0));
    //birdie3->getBody().SetActive(false);
    itemList.push_back(temp);




    items.push_back(new Land(3,6,0.7/2,3.5/2,QPixmap(":/image/bun.png").scaled(width()/(320/7),height()/(36/7)),world,scene));
    items.at(1)->getBody().SetUserData(BUN);
    items.push_back(new Land(2.6,6,0.7/2,2.1/2,QPixmap(":/image/bun2.png").scaled(width()/(320/7),height()/(60/7)),world,scene));
    items.at(2)->getBody().SetUserData(BUN);
    //itemList.push_back(new Rope(20.0f, 10.0f, 0.5f, 0.5f, 10.0f, &timer, QPixmap(":/image/angry-bird-yellow-icon.png").scaled(height()/9.0,height()/9.0),world,scene));

    items.push_back(new Land(5,14,2,0.5,QPixmap(":/image/plate.png").scaled(60,15),world,scene));
    items.push_back(new Land(3,14,2,0.5,QPixmap(":/image/plate.png").scaled(60,15),world,scene));
    items.push_back(new Land(1,14,2,0.5,QPixmap(":/image/plate.png").scaled(60,15),world,scene));

    for(int j = 0; j < 5; j++){
        ball.push_back(new Ball(15,12 + j*2,1,&timer,QPixmap(":/image/ball.png").scaled(60,60),world,scene));
        ball.push_back(new Ball(28,12 + j*2,1,&timer,QPixmap(":/image/ball.png").scaled(60,60),world,scene));
    }


    float h = 0.03f, w = 0.03f;
    for(int i = 0; i < ropelength; ++i)
        rope.push_back(new Rope(1.0f, 4.0f, w/2, h/2, &timer, QPixmap(":/image/rope1.png").scaled(width()/(320/3), height()/(60)),world,scene));

    b2RevoluteJointDef jointdef;
    jointdef.localAnchorA.x = -w/2;
    jointdef.localAnchorB.x = w/2;


    for(int i = 0; i < rope.length() - 1; i++){
            jointdef.bodyA = &rope.at(i)->getBody();
            jointdef.bodyB = &rope.at(i+1)->getBody();
            revolutejoint.push_back((b2RevoluteJoint*) world->CreateJoint(&jointdef));
    }

    b2RopeJointDef ropejointdef;
    ropejointdef.localAnchorA.Set(-w/2,0);
    ropejointdef.localAnchorB.Set(w/2,0);
    ropejointdef.maxLength = 0;

    for(int i = 0; i < rope.length() - 1; i++){
        ropejointdef.bodyA = &rope.at(i)->getBody();
        ropejointdef.bodyB = &rope.at(i+1)->getBody();
        ropejoint.push_back((b2RopeJoint*)world->CreateJoint(&ropejointdef));
    }

    jointdef.localAnchorA.x=0;
    jointdef.localAnchorB.x=0;
    jointdef.bodyA = &items.at(2)->getBody();
    jointdef.bodyB = &rope.at(0)->getBody();
    world->CreateJoint(&jointdef);

    jointdef.localAnchorA.x=0.3;
    jointdef.localAnchorA.y=0;
    jointdef.localAnchorB.x=0;
    jointdef.bodyA = &items.at(1)->getBody();
    jointdef.bodyB = &rope.at(ropelength-1)->getBody();
    world->CreateJoint(&jointdef);

    //create enemy

    //itemList.push_back(new Enemy(19.0f,5.0f,0.27f,&timer,QPixmap(":/image/enemy1.png").scaled(height()/(9),height()/(9)),world,scene));
    //itemList.push_back(new Enemy(21.5f,7.0f,0.27f,&timer,QPixmap(":/image/pig.png").scaled(height()/(9),height()/(9)),world,scene));
    enemy.push_back(new Enemy(19.0f,5.0f,1,&timer,QPixmap(":/image/enemy1.png").scaled(60,60),world,scene));
    enemy.push_back(new Enemy(21.5f,7.0f,1,&timer,QPixmap(":/image/pig.png").scaled(60,60),world,scene));
    enemy.at(1)->gethealth() += 50;

    //create block
    block.push_back(new Block(18.0f,4.0f,2,2,&timer,QPixmap(":/image/block1.png").scaled(60,60),world,scene));
    block.push_back(new Block(18.0f,6.0f,2,2,&timer,QPixmap(":/image/block1.png").scaled(60,60),world,scene));
    block.push_back(new Block(18.0f,8.0f,2,2,&timer,QPixmap(":/image/block1.png").scaled(60,60),world,scene));
    block.push_back(new Block(20.0f,8.0f,2,2,&timer,QPixmap(":/image/block1.png").scaled(60,60),world,scene));
    block.push_back(new Block(22.0f,8.0f,2,2,&timer,QPixmap(":/image/block1.png").scaled(60,60),world,scene));
    block.push_back(new Block(24.0f,8.0f,2,2,&timer,QPixmap(":/image/block1.png").scaled(60,60),world,scene));
    block.push_back(new Block(24.0f,6.0f,2,2,&timer,QPixmap(":/image/block1.png").scaled(60,60),world,scene));
    block.push_back(new Block(24.0f,4.0f,2,2,&timer,QPixmap(":/image/block1.png").scaled(60,60),world,scene));

    //block.at(3)->setpixmap(QPixmap(":/image/dispear.png").scaled(height()/9, height()/9),1,1);

    // Timer
    connect(&timer,SIGNAL(timeout()),this,SLOT(tick()));
    connect(this,SIGNAL(quitGame()),this,SLOT(QUITSLOT()));
    timer.start(100/6);

    world->SetContactListener(new myContactListener());
}
Esempio n. 30
0
void MyScene::Initialise()
{
	glClearColor(0.f, 0.f, 0.f, 1.f);

	// DEMO 1
	//Triangle *t = new Triangle();
    //AddObjectToScene(t);

	// DEMO 2 (Demos / Triforce)
    //Triforce *t = new Triforce();
    // AddObjectToScene(t);
    
	// DEMO 3 (Demos/Solar System)
    // create and add a new triangle to the scene
    //Planet *sun = new Planet(30.0f, 0.0f, 12.0f, 0.0f);
    //sun->SetColour(255, 255, 0); //yellow
    //
    //Planet *mars = new Planet(6.0f, 60.0f, 150.0f, 50.0f);
    //mars->SetColour(255, 0, 0); //red
    //
    //Planet2 *earth = new Planet2(15.0f, 135.0f, 100.0f, 20.0f, 6.0f, 30.0, 100.0f, 8.0f );
    //earth->SetColour(0, 0, 255); //earth blue, moon grey
    //
    //AddObjectToScene(sun);
    //AddObjectToScene(mars);
    //AddObjectToScene(earth);

	// DEMO 4 (Demos/Animated Lamp)
	// Create and add a new lamp to the scene
	//Lamp *l = new Lamp();
	//l->size(6.f);
	//AddObjectToScene(l);

	// DEMO 5
	// Show floor and triangle
	//Floor *f = new Floor();
	//Triangle *t = new Triangle();
	//f->size(100.f);
    //t->size(0.5f);
	//AddObjectToScene(f);
	//AddObjectToScene(t);
	
	// DEMO 6 (LIGHTING)
	// Show teapot and lighting
	//Floor *f = new Floor();
	//f->size(100.f);

	//Teapot *t = new Teapot();
	//t->size(100.f);

	//Light *l = new Light();
	//
	//AddObjectToScene(l);
	//AddObjectToScene(t);
	//AddObjectToScene(f);

	// DEMO 7 (Multilights)
	//Floor *f = new Floor();
	//f->size(100.f);

	//Teapot *t = new Teapot();
	//t->size(100.f);

	//MultiLight *l = new MultiLight();

	//AddObjectToScene(l);
	//AddObjectToScene(t);
	//AddObjectToScene(f);

	// DEMO 8 (Spotlight)
	//Room *r = new Room();
	//r->size(150.f);
	//AddObjectToScene(r);

	//SpotLight *s0 = new SpotLight(GL_LIGHT0, 1);
	//s0->position(0.f, 1.f, 0.f);
	//s0->SetAmbient(0.5f, 0.0f, 0.0f, 1.0f);
	//s0->SetDiffuse(0.9f, 0.0f, 0.0f, 1.0f);
	//s0->SetSpecular(1.0f, 0.5f, 0.5f, 1.0f);
	//s0->SetAttenuation(1.0f, 0.0f, 0.0f);
	//s0->SetSpotDirection(0.0f, 0.0f, -1.0f);
	//s0->SetSpotExponent(6.0f);
	//s0->SetSpotCutOff(80.0f);
	//AddObjectToScene(s0);

	//// add a green spotlight that rotates
	//SpotLight *s1 = new SpotLight(GL_LIGHT1, 2);
	//s1->position(0.0f, -10.0f, 0.f);
	//s1->SetAmbient(0.0f, 0.5f, 0.0f, 1.0f);
	//s1->SetDiffuse(0.0f, 0.9f, 0.0f, 1.0f);
	//s1->SetSpecular(0.5f, 1.0f, 0.5f, 1.0f);
	//s1->SetAttenuation(1.0f, 0.0f, 0.000004f);
	//s1->SetSpotDirection(-1.0f, 0.0f, 0.0f);
	//s1->SetSpotExponent(10.0f);
	//s1->SetSpotCutOff(60.0f);
	//AddObjectToScene(s1);

	//// add a blue spotlight that rotates
	//SpotLight *s2 = new SpotLight(GL_LIGHT2, 3);
	//s2->position(0.0f, -30.0f, 0.f);
	//s2->SetAmbient(0.0f, 0.0f, 0.5f, 1.0f);
	//s2->SetDiffuse(0.0f, 0.0f, 0.9f, 1.0f);
	//s2->SetSpecular(0.5f, 0.5f, 1.0f, 1.0f);
	//s2->SetAttenuation(0.5f, 0.0f, 0.0f);
	//s2->SetSpotDirection(1.0f, 0.0f, 0.0f);
	//s2->SetSpotExponent(80.0f);
	//s2->SetSpotCutOff(20.0f);
	//AddObjectToScene(s2);

	//// add a white spotlight that is stationary
	//SpotLight *s3 = new SpotLight(GL_LIGHT3, 0);
	//s3->position(0.0f, 0.0f, 0.f);
	//s3->SetAmbient(0.5f, 0.5f, 0.5f, 1.0f);
	//s3->SetDiffuse(0.9f, 0.9f, 0.9f, 1.0f);
	//s3->SetSpecular(1.0f, 1.0f, 1.0f, 1.0f);
	//s3->SetAttenuation(1.0f, 0.0f, 0.0f);
	//s3->SetSpotDirection(1.0f, 1.0f, -1.0f);
	//s3->SetSpotExponent(30.0f);
	//s3->SetSpotCutOff(75.0f);
	//AddObjectToScene(s3);

	//// add a light that starts yellow and slowly gets more and less green
	//SpotLight *s4 = new SpotLight(GL_LIGHT4, 4);
	//s4->position(0.0f, -20.0f, 0.f);
	//s4->SetAmbient(0.5f, 0.5f, 0.0f, 1.0f);
	//s4->SetDiffuse(0.4f, 0.4f, 0.0f, 1.0f);
	//s4->SetSpecular(1.0f, 1.0f, 1.0f, 1.0f);
	//s4->SetAttenuation(1.0f, 0.0f, 0.0f);
	//s4->SetSpotDirection(-1.0f, -1.0f, -1.0f);
	//s4->SetSpotExponent(30.0f);
	//s4->SetSpotCutOff(60.0f);
	//AddObjectToScene(s4);

	//// add a light that gets more and less blue and rotates on all axis
	//SpotLight *s5 = new SpotLight(GL_LIGHT5, 5);
	//s5->position(0.0f, -40.0f, 0.f);
	//s5->SetAmbient(0.1f, 0.5f, 0.1f, 1.0f);
	//s5->SetDiffuse(0.2f, 0.9f, 0.2f, 1.0f);
	//s5->SetSpecular(1.0f, 1.0f, 1.0f, 1.0f);
	//s5->SetAttenuation(1.0f, 0.0f, 0.0f);
	//s5->SetSpotDirection(1.0f, -1.0f, -1.0f);
	//s5->SetSpotExponent(20.0f);
	//s5->SetSpotCutOff(80.0f);
	//AddObjectToScene(s5);

	//// DEMO 9 (TEXTURED CUBE)
	//TexturedCube *txc = new TexturedCube("./Code/Demos/Texturing/batmanlogo.bmp");
	//txc->size(200.f);
	//AddObjectToScene(txc);

	//// DEMO 10 (Animated Texturing)

	//Link *link = new Link(10.f, 25.f, "./Code/Demos/Texturing/linkSpriteSheet.bmp");
	//link->position(0.f, -99.9f, -100.f);
	//link->size(10.f);


	//Water *water = new Water(20, 20, "./Code/Demos/Texturing/water.bmp");
 //   
	//water->position(0.f, -99.9f, 100.f);
	//water->size(400.f);

	//Floor *floor = new Floor();
	//floor->size(100);

	//SunLight *sl = new SunLight();
	//sl->direction(-1.f, 1.f, 1.f);

	//AddObjectToScene(floor);
	//AddObjectToScene(water);
	//AddObjectToScene(link);
	//AddObjectToScene(sl);

//skybox
	cameraRadius();
	myStage *stage = new myStage();
	GLuint* skybox = new GLuint[6];
	skybox[0] = Scene::GetTexture("./Code/src/skybox_left.bmp");
	skybox[1] = Scene::GetTexture("./Code/src/skybox_right.bmp");
	skybox[2] = Scene::GetTexture("./Code/src/skybox_front.bmp");
	skybox[3] = Scene::GetTexture("./Code/src/skybox_back.bmp");
	skybox[4] = Scene::GetTexture("./Code/src/skybox_down.bmp");
	skybox[5] = Scene::GetTexture("./Code/src/skybox_up.bmp");
	stage->setTextures(skybox);
	stage->size(2*camrad);
	stage->position(0.f, -100.f, 0.f);
	AddObjectToScene(stage);


//buildings
	YfjBuilding *yfjBuilding = new YfjBuilding();
	GLuint* yfjbd = new GLuint[6];
	yfjbd[0] = Scene::GetTexture("./Code/src/YFJ0.bmp");
	yfjbd[1] = Scene::GetTexture("./Code/src/YFJ1.bmp");
	yfjbd[2] = Scene::GetTexture("./Code/src/YFJ2.bmp");
	yfjbd[3] = Scene::GetTexture("./Code/src/AMEN3.bmp");
	yfjbd[4] = Scene::GetTexture("./Code/src/YFJ4.bmp");
	yfjbd[5] = Scene::GetTexture("./Code/src/YFJ5.bmp");
	yfjBuilding->setTextures(yfjbd);
	yfjBuilding->size(10);
	yfjBuilding->position(-200.f,-100.f,-200.f);
	AddObjectToScene(yfjBuilding);

	AmenBuilding *amenBuilding = new AmenBuilding();
	GLuint* amenbd = new GLuint[5];
	amenbd[0] = Scene::GetTexture("./Code/src/AMEN0.bmp");
	amenbd[1] = Scene::GetTexture("./Code/src/AMEN1.bmp");	
	amenbd[2] = Scene::GetTexture("./Code/src/AMEN2.bmp");
	amenbd[3] = Scene::GetTexture("./Code/Src/AMEN3.bmp");
	amenbd[4] = Scene::GetTexture("./Code/Src/AMEN4.bmp");
	amenBuilding->setTextures(amenbd);
	amenBuilding->size(10);
	amenBuilding->position(-200.f, -100.f, 0.0f);
	AddObjectToScene(amenBuilding);


//road
	Road *road1 = new Road("./Code/src/Road1.bmp");
	road1->size(10);
	road1->setLength(9);
	road1->position(50.0f, -99.f, -480.0f);
	AddObjectToScene(road1);

	Road *road2	= new Road("./Code/src/Road1.bmp");
	road2->size(10);
	road2->setLength(8);
	road2->position(-300.0f, -99.f, -480.0f);
	AddObjectToScene(road2);

	Road *road3 = new Road("./Code/src/Road2.bmp");
	road3->size(10);
	road3->setLength(5);
	road3->position(-280.0f, -99.f, 120.0f);
	road3->orientation(0.f, 77.f, 0.f);
	AddObjectToScene(road3);

//water
	Water *water = new Water(20, 20, "./Code/Demos/Texturing/water.bmp");
	water->size(400);
	water->position(-600.f, -98.f, -150.0f);
	AddObjectToScene(water);


//tree
	Tree *tree1 = new Tree("./Code/src/bark.bmp");
	Tree *tree2 = new Tree("./Code/src/bark.bmp");
	Tree *tree3 = new Tree("./Code/src/bark.bmp");
	Tree *tree4 = new Tree("./Code/src/bark.bmp");
	Tree *tree5 = new Tree("./Code/src/bark.bmp");
	Tree *tree6 = new Tree("./Code/src/bark.bmp");

	tree1->setReplaceString('f', "ff-[-& f + ff + < + f] + [+>f--f&-f]");
	tree2->setReplaceString('f', "ff-[-& f + ff + < + f] + [+>f--f&-f]");
	tree3->setReplaceString('f', "ff-[-& f + ff + < + f] + [+>f--f&-f]");
	tree4->setReplaceString('f', "ff-[-& f + ff + < + f] + [+>f--f&-f]");
	tree5->setReplaceString('f', "ff-[-& f + ff + < + f] + [+>f--f&-f]");
	tree6->setReplaceString('f', "ff-[-& f + ff + < + f] + [+>f--f&-f]");

	tree1->size(5);
	tree2->size(5);
	tree3->size(5);
	tree4->size(5);
	tree5->size(5);
	tree6->size(5);

	tree1->position(-200.f, -98.f, 80.0f);
	tree2->position(-160.f, -98.f, 88.0f);
	tree3->position(-120.f, -98.f, 97.0f);
	tree4->position(-80.f, -98.f, 105.0f);
	tree5->position(-40.f, -98.f, 114.0f);
	tree6->position(0.f, -98.f, 123.0f);

	AddObjectToScene(tree1);
	AddObjectToScene(tree2);
	AddObjectToScene(tree3);
	AddObjectToScene(tree4);
	AddObjectToScene(tree5);
	AddObjectToScene(tree6);
//bird
	Bird *bird = new Bird(24.f, 31.4f, "./Code/src/bird.bmp");
	bird->position(0.f, -0.f, -300.f);
	bird->size(5.f);
	AddObjectToScene(bird);

//light

	mySunlight *sl = new mySunlight();
	sl->direction(-1.f, 1, 1.f);
	AddObjectToScene(sl);

	SpotLight *s0 = new SpotLight(GL_LIGHT1, 0);
	s0->size(0.1);
	s0->position(-198.f, -74.f, 132.f);
	s0->SetAmbient(0.8f, 0.8f, 0.8f, 1.0f);
	s0->SetDiffuse(0.9f, 0.9f, 0.9f, 1.0f);
	s0->SetSpecular(1.0f, 0.5f, 0.5f, 1.0f);
	s0->SetAttenuation(1.0f, 0.0f, 0.0f);
	s0->SetSpotDirection(0.0f, -1.0f, 0.0f);
	s0->SetSpotExponent(6.0f);
	s0->SetSpotCutOff(80.0f);
	AddObjectToScene(s0);

	StreetLight *stl = new StreetLight();
	stl->orientation(0.f, -13.f, 0.f);
	stl->position(-200.f, -98.f, 140.f);
	stl->size(5);
	AddObjectToScene(stl);

	SpotLight *s1 = new SpotLight(GL_LIGHT2, 0);
	s1->size(0.1);
	s1->position(-98.f, -74.f, 155.f);
	s1->SetAmbient(0.9f, 0.9f, 0.9f, 1.0f);
	s1->SetDiffuse(0.9f, 0.9f, 0.9f, 1.0f);
	s1->SetSpecular(1.0f, 0.5f, 0.5f, 1.0f);
	s1->SetAttenuation(1.0f, 0.0f, 0.0f);
	s1->SetSpotDirection(0.0f, -1.0f, 0.0f);
	s1->SetSpotExponent(6.0f);
	s1->SetSpotCutOff(80.0f);
	AddObjectToScene(s1);

	StreetLight *stl2 = new StreetLight();
	stl2->orientation(0.f, -13.f, 0.f);
	stl2->position(-100.f, -98.f, 163.f);
	stl2->size(5);
	AddObjectToScene(stl2);

	SpotLight *s2 = new SpotLight(GL_LIGHT3, 0);
	s2->size(0.1);
	s2->position(-8.f, -74.f, 175.f);
	s2->SetAmbient(0.8f, 0.8f, 0.8f, 1.0f);
	s2->SetDiffuse(0.9f, 0.9f, 0.9f, 1.0f);
	s2->SetSpecular(1.0f, 0.5f, 0.5f, 1.0f);
	s2->SetAttenuation(1.0f, 0.0f, 0.0f);
	s2->SetSpotDirection(0.0f, -1.0f, 0.0f);
	s2->SetSpotExponent(6.0f);
	s2->SetSpotCutOff(80.0f);
	AddObjectToScene(s2);
	StreetLight *stl3 = new StreetLight();
	stl3->orientation(0.f, -13.f, 0.f);
	stl3->position(-10.f, -98.f, 184.f);
	stl3->size(5);
	AddObjectToScene(stl3);
}