Beispiel #1
0
Asteroid::Asteroid(int ast_size){
    int i, gen, dots, interval, angle, radius, min_radius, delta_radius;
    Asteroid* ast;
    Dot d;

    item = NULL;

    dots = 3*pow(2,ast_size);
    interval = 360/dots;
    min_radius = 10*pow(2,ast_size);
    delta_radius = 1.25*min_radius;

    //Generating vertex
    for(i=0; i<dots; i++){
        angle = rand()%interval + i*interval;
        radius = rand()%delta_radius + min_radius;

        d.setX(radius*cos(angle*PI/180));
        d.setY(radius*sin(angle*PI/180));
        loop_vertex.push_back(d);
    }


    if(ast_size != SMALL){

        //Generating subparts
        gen = rand()%2+2;
        while(gen>0){
            ast = new Asteroid(ast_size-1);
            d.setX(rand()%4-2);
            d.setY(rand()%4-2);
            ast->setSpeed(d);
            parts.push_back(ast);
            gen--;
        }
    }

    if(ast_size == BIG){
        //Generating item
        gen = rand()%(NUM_ITEMS*3);
        if(gen%3 == 0){
            item = new Item(gen/3);
            item->setSpeed(rand()%360, 0.25);
        }
    }

    //Adjusting centroid
    centralize();

    //setColor(0, 1, (float)(BIG - ast_size)/BIG);
    setColor(0, (GLfloat)(ast_size*0.125 + 0.75), (GLfloat)(0.25-ast_size*0.125));
    setHandling(1);

    if(rand()%2 == 0){
        commands[TURN_LEFT] = true;
    }
    else{
        commands[TURN_RIGHT] = true;
    }
}
Beispiel #2
0
void myGame::resetGame() 
{
	ghosts.clear();
	dots.clear();

	//create patterns
	Pattern* ghostPattern1 = new Pattern(1);

	ghostPattern1->addStep(0, "CAMP", 40, [&] (Entity* e) {

		Ghost* myself = static_cast<Ghost*>(e) ;

		int waypoint = myself->targetWaypoint ;
		VECTOR2 center = *myself->getCenter() ;

		float left_edge = myself->getX();
		float right_edge = myself->getX() + myself->getWidth()*myself->getScale();
		float top_edge = myself->getY();
		float bottom_edge = myself->getY() + myself->getHeight()*myself->getScale();

		VECTOR2 currentWaypoint = waypointSet1[waypoint] ;
		if(	currentWaypoint.x > left_edge && 
			currentWaypoint.x < right_edge &&
			currentWaypoint.y > top_edge &&
			currentWaypoint.y < bottom_edge) 
			myself->targetWaypoint++ ;

		if( myself->targetWaypoint > 3) myself->targetWaypoint = 0 ;

		myself->waypointTrack(waypointSet1[waypoint]);
		myself->vectorTrack(&player, 180);
	}) ;

	Pattern* ghostPattern2 = new Pattern(1);

	ghostPattern2->addStep(0, "CAMP", 40, [&] (Entity* e) {
		Ghost* myself = static_cast<Ghost*>(e) ;

		int waypoint = myself->targetWaypoint ;
		VECTOR2 center = *myself->getCenter() ;

		float left_edge = myself->getX();
		float right_edge = myself->getX() + myself->getWidth()*myself->getScale();
		float top_edge = myself->getY();
		float bottom_edge = myself->getY() + myself->getHeight()*myself->getScale();

		VECTOR2 currentWaypoint = waypointSet2[waypoint] ;
		if(	currentWaypoint.x > left_edge && 
			currentWaypoint.x < right_edge &&
			currentWaypoint.y > top_edge &&
			currentWaypoint.y < bottom_edge) 
			myself->targetWaypoint++ ;

		if( myself->targetWaypoint > 3) myself->targetWaypoint = 0 ;

		myself->waypointTrack(waypointSet2[waypoint]);
		myself->vectorTrack(&player, 180);
	}) ;


	//create entities
	// ghost 1
	Ghost* ghost1 = new Ghost() ;
	if (!ghost1->initialize(this, ghostNS::WIDTH, ghostNS::HEIGHT, 4, &allTM))
		throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ghost entity"));

	ghost1->setX(0);
	ghost1->setY(0);
	ghosts.add(ghost1, new Pattern(ghostPattern1));

	// ghost 2
	Ghost* ghost2 = new Ghost() ;
	if (!ghost2->initialize(this, ghostNS::WIDTH, ghostNS::HEIGHT, 4, &allTM))
		throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ghost entity"));
	
	ghost2->setX(GAME_WIDTH - ghostNS::WIDTH*ghostNS::SCALE);
	ghost2->setY(GAME_HEIGHT - ghostNS::HEIGHT*ghostNS::SCALE);
	ghost2->setCurrentFrame(1);
	ghosts.add(ghost2, new Pattern(ghostPattern2));

	// dots
	rows = 4 ;
	cols = 5 ;
	for(int i = 0; i < rows; ++i)
	{
		for(int j = 0; j < cols; ++j)
		{
			Dot* newDot = new Dot() ;
			if (!newDot->initialize(this, dotNS::WIDTH, dotNS::HEIGHT, 4, &allTM))
				throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing dot entity"));

			newDot->setX( ((GAME_WIDTH/cols)*j) + 50);
			newDot->setY( ((GAME_HEIGHT/rows)*i) + 50);
			newDot->setScale(dotNS::SCALE);

			dots.add(newDot);
		}
	}
	dotsRemaining = rows * cols ;
}
Beispiel #3
0
Dot Dot::transf(float rotatee, Dot translade){
    Dot p;
    p.setX(x*cos(rotatee*PI/180)-y*sin(rotatee*PI/180));
    p.setY(x*sin(rotatee*PI/180)+y*cos(rotatee*PI/180));
    return (p + translade);
}